Module org.hsqldb

Class DoubleIntIndex

  • All Implemented Interfaces:
    LongLookup

    public class DoubleIntIndex
    extends java.lang.Object
    implements LongLookup
    Maintains an ordered integer->integer lookup table, consisting of two columns, one for keys, the other for values. Equal keys are allowed. The table is sorted on either the key or value column, depending on the calls to setKeysSearchTarget() or setValuesSearchTarget(). By default, the table is sorted on values. Equal values are sorted by key.

    findXXX() methods return the array index into the list pair containing a matching key or value, or -1 if not found.

    Sorting methods originally contributed by Tony Lai (tony_lai@users dot sourceforge.net). Non-recursive implementation of fast quicksort added by Sergio Bossa (sbtourist@users dot sourceforge.net)

    Since:
    1.8.0
    Author:
    Fred Toussi (fredt@users dot sourceforge.net)
    • Constructor Detail

      • DoubleIntIndex

        public DoubleIntIndex​(int capacity)
      • DoubleIntIndex

        public DoubleIntIndex​(int capacity,
                              boolean fixedSize)
    • Method Detail

      • getKey

        public int getKey​(int i)
      • getValue

        public int getValue​(int i)
      • setKey

        public void setKey​(int i,
                           int key)
        Modifies an existing pair at the given index.
        Parameters:
        i - the index
        key - the new key
      • setValue

        public void setValue​(int i,
                             int value)
        Modifies an existing pair at the given index.
        Parameters:
        i - the index
        value - the new value
      • setLongValue

        public void setLongValue​(int i,
                                 long value)
        Modifies an existing pair at the given index.
        Specified by:
        setLongValue in interface LongLookup
        Parameters:
        i - the index
        value - the new value
      • size

        public int size()
        Specified by:
        size in interface LongLookup
      • capacity

        public int capacity()
      • getKeys

        public int[] getKeys()
      • getValues

        public int[] getValues()
      • setSize

        public void setSize​(int newSize)
      • addUnsorted

        public boolean addUnsorted​(long key,
                                   long value)
        Specified by:
        addUnsorted in interface LongLookup
      • addUnsorted

        public boolean addUnsorted​(int key,
                                   int value)
        Adds a pair into the table.
        Parameters:
        key - the key
        value - the value
        Returns:
        true or false depending on success
      • addSorted

        public boolean addSorted​(int key,
                                 int value)
        Adds a key, value pair into the table with the guarantee that the key is equal or larger than the largest existing key. This prevents a sort from taking place on next call to find()
        Parameters:
        key - the key
        value - the value
        Returns:
        true or false depending on success
      • addUnique

        public boolean addUnique​(int key,
                                 int value)
        Adds a pair, ensuring no duplicate key xor value already exists in the current search target column.
        Parameters:
        key - the key
        value - the value
        Returns:
        true or false depending on success
      • removeKey

        public boolean removeKey​(int key)
        Removes the (unique) key and its value. Must be sorted on key.
        Parameters:
        key - the key to remove
        Returns:
        true or false depending on success
      • addOrReplaceUnique

        public boolean addOrReplaceUnique​(int key,
                                          int value)
        Updates the value if key is present, or adds the key/value paire. Must be sorted on key.
        Parameters:
        key - the key to add or find
        value - the value to add or update
        Returns:
        true or false depending on success
      • addCount

        public int addCount​(int key,
                            int value)
        Used for values as counters. Adds the value to the existing value for the key. Or adds the key - value pair.
        Parameters:
        key - the key to update or add
        value - the count to add
        Returns:
        the new count for the key
      • addCount

        public int addCount​(int key)
      • add

        public int add​(long key,
                       long value)
        Specified by:
        add in interface LongLookup
      • add

        public int add​(int key,
                       int value)
        Adds a pair, maintaining sort order on current search target column.
        Parameters:
        key - the key
        value - the value
        Returns:
        index of added key or -1 if full
      • lookup

        public long lookup​(long key)
                    throws java.util.NoSuchElementException
        Specified by:
        lookup in interface LongLookup
        Throws:
        java.util.NoSuchElementException
      • lookup

        public int lookup​(int key)
                   throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • lookup

        public long lookup​(long key,
                           long def)
        Specified by:
        lookup in interface LongLookup
      • lookup

        public int lookup​(int key,
                          int def)
      • clear

        public void clear()
        Specified by:
        clear in interface LongLookup
      • lookupFirstGreaterEqual

        public int lookupFirstGreaterEqual​(int key)
                                    throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • setValuesSearchTarget

        public void setValuesSearchTarget()
      • setKeysSearchTarget

        public void setKeysSearchTarget()
      • findFirstGreaterEqualKeyIndex

        public int findFirstGreaterEqualKeyIndex​(int value)
        Parameters:
        value - the value
        Returns:
        the index
      • findFirstEqualKeyIndex

        public int findFirstEqualKeyIndex​(int value)
        Parameters:
        value - the value
        Returns:
        the index
      • findFirstGreaterEqualSlotIndex

        public int findFirstGreaterEqualSlotIndex​(int value)
        This method is similar to findFirstGreaterEqualKeyIndex(int) but returns the index of the empty row past the end of the array if the search value is larger than all the values / keys in the searched column.
        Parameters:
        value - the value
        Returns:
        the index
      • sortOnKeys

        public void sortOnKeys()
      • sortOnValues

        public void sortOnValues()
      • sort

        public void sort()
        Specified by:
        sort in interface LongLookup
      • removeRange

        public void removeRange​(int start,
                                int limit)
      • removeAll

        public void removeAll()
      • remove

        public final void remove​(int position)