Package org.datavec.api.io
Class WritableComparator
- java.lang.Object
-
- org.datavec.api.io.WritableComparator
-
- All Implemented Interfaces:
Comparator,RawComparator
- Direct Known Subclasses:
BooleanWritable.Comparator,ByteWritable.Comparator,DoubleWritable.Comparator,FloatWritable.Comparator,IntWritable.Comparator,LongWritable.Comparator,Text.Comparator
public class WritableComparator extends Object implements RawComparator
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedWritableComparator(Class<? extends WritableComparable> keyClass)Construct for aWritableComparableimplementation.protectedWritableComparator(Class<? extends WritableComparable> keyClass, boolean createInstances)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)Optimization hook.intcompare(Object a, Object b)intcompare(WritableComparable a, WritableComparable b)Compare two WritableComparables.static intcompareBytes(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)Lexicographic order of binary data.static voiddefine(Class c, WritableComparator comparator)Register an optimized comparator for aWritableComparableimplementation.static WritableComparatorget(Class<? extends WritableComparable> c)Get a comparator for aWritableComparableimplementation.Class<? extends WritableComparable>getKeyClass()Returns the WritableComparable implementation class.static inthashBytes(byte[] bytes, int length)Compute hash for binary data.static inthashBytes(byte[] bytes, int offset, int length)Compute hash for binary data.WritableComparablenewKey()Construct a newWritableComparableinstance.static doublereadDouble(byte[] bytes, int start)Parse a double from a byte array.static floatreadFloat(byte[] bytes, int start)Parse a float from a byte array.static intreadInt(byte[] bytes, int start)Parse an integer from a byte array.static longreadLong(byte[] bytes, int start)Parse a long from a byte array.static intreadUnsignedShort(byte[] bytes, int start)Parse an unsigned short from a byte array.static intreadVInt(byte[] bytes, int start)Reads a zero-compressed encoded integer from a byte array and returns it.static longreadVLong(byte[] bytes, int start)Reads a zero-compressed encoded long from a byte array and returns it.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Constructor Detail
-
WritableComparator
protected WritableComparator(Class<? extends WritableComparable> keyClass)
Construct for aWritableComparableimplementation.
-
WritableComparator
protected WritableComparator(Class<? extends WritableComparable> keyClass, boolean createInstances)
-
-
Method Detail
-
get
public static WritableComparator get(Class<? extends WritableComparable> c)
Get a comparator for aWritableComparableimplementation.
-
define
public static void define(Class c, WritableComparator comparator)
Register an optimized comparator for aWritableComparableimplementation.
-
getKeyClass
public Class<? extends WritableComparable> getKeyClass()
Returns the WritableComparable implementation class.
-
newKey
public WritableComparable newKey()
Construct a newWritableComparableinstance.
-
compare
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)Optimization hook. Override this to make SequenceFile.Sorter's scream.The default implementation reads the data into two
WritableComparables (usingWritable.readFields(DataInput), then callscompare(WritableComparable,WritableComparable).- Specified by:
comparein interfaceRawComparator
-
compare
public int compare(WritableComparable a, WritableComparable b)
Compare two WritableComparables.The default implementation uses the natural ordering, calling
Comparable.compareTo(Object).
-
compare
public int compare(Object a, Object b)
- Specified by:
comparein interfaceComparator
-
compareBytes
public static int compareBytes(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)Lexicographic order of binary data.
-
hashBytes
public static int hashBytes(byte[] bytes, int offset, int length)Compute hash for binary data.
-
hashBytes
public static int hashBytes(byte[] bytes, int length)Compute hash for binary data.
-
readUnsignedShort
public static int readUnsignedShort(byte[] bytes, int start)Parse an unsigned short from a byte array.
-
readInt
public static int readInt(byte[] bytes, int start)Parse an integer from a byte array.
-
readFloat
public static float readFloat(byte[] bytes, int start)Parse a float from a byte array.
-
readLong
public static long readLong(byte[] bytes, int start)Parse a long from a byte array.
-
readDouble
public static double readDouble(byte[] bytes, int start)Parse a double from a byte array.
-
readVLong
public static long readVLong(byte[] bytes, int start) throws IOExceptionReads a zero-compressed encoded long from a byte array and returns it.- Parameters:
bytes- byte array with decode longstart- starting index- Returns:
- deserialized long
- Throws:
IOException
-
readVInt
public static int readVInt(byte[] bytes, int start) throws IOExceptionReads a zero-compressed encoded integer from a byte array and returns it.- Parameters:
bytes- byte array with the encoded integerstart- start index- Returns:
- deserialized integer
- Throws:
IOException
-
-