org.apache.nutch.io
Class WritableComparator

java.lang.Object
  extended byorg.apache.nutch.io.WritableComparator
All Implemented Interfaces:
Comparator
Direct Known Subclasses:
BooleanWritable.Comparator, DeleteDuplicates.IndexedDoc.ByHashDoc, DeleteDuplicates.IndexedDoc.ByHashScore, DistributedWebDBWriter.LinkInstruction.MD5Comparator, DistributedWebDBWriter.LinkInstruction.UrlComparator, DistributedWebDBWriter.PageInstruction.PageComparator, DistributedWebDBWriter.PageInstruction.UrlComparator, FloatWritable.Comparator, IntWritable.Comparator, Link.MD5Comparator, Link.UrlComparator, LongWritable.Comparator, MD5Hash.Comparator, Page.Comparator, Page.UrlComparator, UpdateSegmentsFromDb.BySegmentComparator, UpdateSegmentsFromDb.ByUrlComparator, UTF8.Comparator, WebDBWriter.LinkInstruction.MD5Comparator, WebDBWriter.LinkInstruction.UrlComparator, WebDBWriter.PageInstruction.PageComparator, WebDBWriter.PageInstruction.UrlComparator

public class WritableComparator
extends Object
implements Comparator

A Comparator for WritableComparables.

This base implemenation uses the natural ordering. To define alternate orderings, override compare(WritableComparable,WritableComparable).

One may optimize compare-intensive operations by overriding compare(byte[],int,int,byte[],int,int). Static utility methods are provided to assist in optimized implementations of this method.


Constructor Summary
protected WritableComparator(Class keyClass)
          Construct for a WritableComparable implementation.
 
Method Summary
 int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)
          Optimization hook.
 int compare(Object a, Object b)
           
 int compare(WritableComparable a, WritableComparable b)
          Compare two WritableComparables.
static int compareBytes(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)
          Lexicographic order of binary data.
static void define(Class c, WritableComparator comparator)
          Register an optimized comparator for a WritableComparable implementation.
static WritableComparator get(Class c)
          Get a comparator for a WritableComparable implementation.
 Class getKeyClass()
          Returns the WritableComparable implementation class.
 WritableComparable newKey()
          Construct a new WritableComparable instance.
static float readFloat(byte[] bytes, int start)
          Parse a float from a byte array.
static int readInt(byte[] bytes, int start)
          Parse an integer from a byte array.
static long readLong(byte[] bytes, int start)
          Parse a long from a byte array.
static int readUnsignedShort(byte[] bytes, int start)
          Parse an unsigned short from a byte array.
 
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
 

Constructor Detail

WritableComparator

protected WritableComparator(Class keyClass)
Construct for a WritableComparable implementation.

Method Detail

get

public static WritableComparator get(Class c)
Get a comparator for a WritableComparable implementation.


define

public static void define(Class c,
                          WritableComparator comparator)
Register an optimized comparator for a WritableComparable implementation.


getKeyClass

public Class getKeyClass()
Returns the WritableComparable implementation class.


newKey

public WritableComparable newKey()
Construct a new WritableComparable instance.


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 (using Writable.readFields(DataInput), then calls compare(WritableComparable,WritableComparable).


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:
compare in interface Comparator

compareBytes

public static int compareBytes(byte[] b1,
                               int s1,
                               int l1,
                               byte[] b2,
                               int s2,
                               int l2)
Lexicographic order of 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.



Copyright © 2006 The Apache Software Foundation