org.hsqldb.lib
Class DoubleIntIndex
- java.lang.Object
-
- org.hsqldb.lib.DoubleIntIndex
-
- All Implemented Interfaces:
- IntLookup, LongLookup
public class DoubleIntIndex extends java.lang.Object implements IntLookup, LongLookup
Maintains an ordered integer->integer lookup table, consisting of two columns, one for keys, the other for values. 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.findXXX() methods return the array index into the list pair containing a matching key or value, or 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
-
-
Constructor Summary
Constructors Constructor and Description DoubleIntIndex(int capacity, boolean fixedSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intadd(int key, int value)Adds a pair, maintaining sort order on current search target column.intadd(long key, long value)booleanaddSorted(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.booleanaddUnique(int key, int value)Adds a pair, ensuring no duplicate key xor value already exists in the current search target column.booleanaddUnsorted(int key, int value)Adds a pair into the table.booleanaddUnsorted(long key, long value)intcapacity()voidclear()voidcopyTo(DoubleIntIndex other)intfindFirstEqualKeyIndex(int value)intfindFirstGreaterEqualKeyIndex(int value)intfindFirstGreaterEqualSlotIndex(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.intgetKey(int i)int[]getKeys()longgetTotalValues()intgetValue(int i)int[]getValues()intlookup(int key)intlookup(int key, int def)longlookup(long key)longlookup(long key, long def)intlookupFirstGreaterEqual(int key)voidremove(int position)voidremoveAll()voidremoveRange(int start, int limit)voidsetKey(int i, int key)Modifies an existing pair.voidsetKeysSearchTarget()voidsetSize(int newSize)voidsetValue(int i, int value)Modifies an existing pair.voidsetValuesSearchTarget()intsize()voidsort()
-
-
-
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.- Parameters:
i- the indexkey- the key
-
setValue
public void setValue(int i, int value)Modifies an existing pair.- Parameters:
i- the indexvalue- the value
-
size
public int size()
-
capacity
public int capacity()
-
getKeys
public int[] getKeys()
-
getValues
public int[] getValues()
-
getTotalValues
public long getTotalValues()
-
setSize
public void setSize(int newSize)
-
addUnsorted
public boolean addUnsorted(long key, long value)- Specified by:
addUnsortedin interfaceLongLookup
-
addUnsorted
public boolean addUnsorted(int key, int value)Adds a pair into the table.- Specified by:
addUnsortedin interfaceIntLookup- Parameters:
key- the keyvalue- 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 keyvalue- 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 keyvalue- the value- Returns:
- true or false depending on success
-
add
public int add(long key, long value)- Specified by:
addin interfaceLongLookup
-
add
public int add(int key, int value)Adds a pair, maintaining sort order on current search target column.
-
lookup
public long lookup(long key) throws java.util.NoSuchElementException- Specified by:
lookupin interfaceLongLookup- Throws:
java.util.NoSuchElementException
-
lookup
public int lookup(int key) throws java.util.NoSuchElementException
-
lookup
public long lookup(long key, long def)- Specified by:
lookupin interfaceLongLookup
-
clear
public void clear()
- Specified by:
clearin interfaceIntLookup- Specified by:
clearin interfaceLongLookup
-
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
-
sort
public void sort()
-
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)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG