Class IDSorter

  • All Implemented Interfaces:
    java.lang.Comparable<IDSorter>

    public class IDSorter
    extends java.lang.Object
    implements java.lang.Comparable<IDSorter>
    This class is contains a comparator for use in sorting integers that have associated floating point values. One example would be sorting words by probability in a Naive Bayes model. Ties are broken by the ID.
         IDSorter[] sortedIDs = new IDSorter[n];
         for (int i=0; i<n; i++) {
           sortedIDs[i] = new IDSorter(i, weights[i]);
         }
         Arrays.sort(sortedIDs);
         
         for (int i=0; i<10; i++) {
           // do something with the nth highest weighted item
         }
       
    Author:
    David Mimno
    • Constructor Summary

      Constructors 
      Constructor Description
      IDSorter​(int id, double p)  
      IDSorter​(int id, int p)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(IDSorter o2)  
      int getID()  
      double getWeight()  
      void set​(int id, double p)
      Reinitialize an IDSorter
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IDSorter

        public IDSorter​(int id,
                        double p)
      • IDSorter

        public IDSorter​(int id,
                        int p)
    • Method Detail

      • compareTo

        public final int compareTo​(IDSorter o2)
        Specified by:
        compareTo in interface java.lang.Comparable<IDSorter>
      • getID

        public int getID()
      • getWeight

        public double getWeight()
      • set

        public void set​(int id,
                        double p)
        Reinitialize an IDSorter