Module org.hsqldb
Package org.hsqldb.lib

## Class DoubleIntIndex

- java.lang.Object
- - org.hsqldb.lib.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 Summary

    Constructors
    Constructor | Description
    --- | ---
    `DoubleIntIndex​(int capacity)` |
    `DoubleIntIndex​(int capacity, boolean fixedSize)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `add​(int key, int value)` | Adds a pair, maintaining sort order on current search target column.
    `int` | `add​(long key, long value)` |
    `int` | `addCount​(int key)` |
    `int` | `addCount​(int key, int value)` | Used for values as counters.
    `boolean` | `addOrReplaceUnique​(int key, int value)` | Updates the value if key is present, or adds the key/value paire.
    `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.
    `boolean` | `addUnique​(int key, int value)` | Adds a pair, ensuring no duplicate key xor value already exists in the current search target column.
    `boolean` | `addUnsorted​(int key, int value)` | Adds a pair into the table.
    `boolean` | `addUnsorted​(long key, long value)` |
    `boolean` | `addUnsorted​(LongLookup other)` |
    `int` | `capacity()` |
    `void` | `clear()` |
    `boolean` | `compactLookupAsIntervals()` |
    `void` | `copyTo​(DoubleIntIndex other)` |
    `LongLookup` | `duplicate()` |
    `int` | `findFirstEqualKeyIndex​(int value)` |
    `int` | `findFirstGreaterEqualKeyIndex​(int value)` |
    `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.
    `int` | `getKey​(int i)` |
    `int[]` | `getKeys()` |
    `long` | `getLongKey​(int i)` |
    `long` | `getLongValue​(int i)` |
    `long` | `getTotalValues()` |
    `int` | `getValue​(int i)` |
    `int[]` | `getValues()` |
    `int` | `lookup​(int key)` |
    `int` | `lookup​(int key, int def)` |
    `long` | `lookup​(long key)` |
    `long` | `lookup​(long key, long def)` |
    `int` | `lookupFirstGreaterEqual​(int key)` |
    `void` | `remove​(int position)` |
    `void` | `removeAll()` |
    `boolean` | `removeKey​(int key)` | Removes the (unique) key and its value.
    `void` | `removeRange​(int start, int limit)` |
    `void` | `setKey​(int i, int key)` | Modifies an existing pair at the given index.
    `void` | `setKeysSearchTarget()` |
    `void` | `setLongValue​(int i, long value)` | Modifies an existing pair at the given index.
    `void` | `setSize​(int newSize)` |
    `void` | `setValue​(int i, int value)` | Modifies an existing pair at the given index.
    `void` | `setValuesSearchTarget()` |
    `int` | `size()` |
    `void` | `sort()` |
    `void` | `sortOnKeys()` |
    `void` | `sortOnValues()` |

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DoubleIntIndex

          public DoubleIntIndex​(int capacity)

    - #### DoubleIntIndex

          public DoubleIntIndex​(int capacity,
                                boolean fixedSize)

  - ### Method Detail

    - #### getKey

          public int getKey​(int i)

    - #### getLongKey

          public long getLongKey​(int i)

      Specified by:
        `getLongKey` in interface `LongLookup`

    - #### getLongValue

          public long getLongValue​(int i)

      Specified by:
        `getLongValue` in interface `LongLookup`

    - #### 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()

    - #### getTotalValues

          public long getTotalValues()

      Specified by:
        `getTotalValues` in interface `LongLookup`

    - #### 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

    - #### addUnsorted

          public boolean addUnsorted​(LongLookup other)

      Specified by:
        `addUnsorted` in interface `LongLookup`

    - #### 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`

    - #### duplicate

          public LongLookup duplicate()

      Specified by:
        `duplicate` 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

    - #### compactLookupAsIntervals

          public boolean compactLookupAsIntervals()

      Specified by:
        `compactLookupAsIntervals` in interface `LongLookup`

    - #### 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()

    - #### copyTo

          public void copyTo​(DoubleIntIndex other)

    - #### remove

          public final void remove​(int position)