Top Description Fields Constructors Methods
org.hsqldb.lib

public Class DoubleIntIndex

extends Object
implements LongLookup
Class Inheritance
All Implemented Interfaces
org.hsqldb.lib.LongLookup
Imports
java.util.Arrays, .NoSuchElementException

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)

Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
1.8.0
Version
2.7.4

Field Summary

Modifier and TypeField and Description
private int
private int
private final boolean
private int[]
private boolean
private boolean
private int
private int[]

Constructor Summary

AccessConstructor and Description
public
DoubleIntIndex(int capacity)

public
DoubleIntIndex(int capacity, boolean fixedSize)

Method Summary

Modifier and TypeMethod and Description
public int
add(long key, long value)

Implements org.hsqldb.lib.LongLookup.add.

public int

Returns:

index of added key or -1 if full
add
(int
the key
key
,
int
the value
value
)

Adds a pair, maintaining sort order on current search target column.

public int

Returns:

the new count for the key
addCount
(int
the key to update or add
key
,
int
the count to add
value
)

Used for values as counters.

public int
addCount(int key)

public boolean

Returns:

true or false depending on success
addOrReplaceUnique
(int
the key to add or find
key
,
int
the value to add or update
value
)

Updates the value if key is present, or adds the key/value paire.

public boolean

Returns:

true or false depending on success
addSorted
(int
the key
key
,
int
the value
value
)

Adds a key, value pair into the table with the guarantee that the key is equal or larger than the largest existing key.

public boolean

Returns:

true or false depending on success
addUnique
(int
the key
key
,
int
the value
value
)

Adds a pair, ensuring no duplicate key xor value already exists in the current search target column.

public boolean
addUnsorted(long key, long value)

Implements org.hsqldb.lib.LongLookup.addUnsorted.

public boolean

Returns:

true or false depending on success
addUnsorted
(int
the key
key
,
int
the value
value
)

Adds a pair into the table.

public boolean
private int

Returns:

the index
binaryEmptySlotSearch
()

Returns the index of the lowest element > the given search target or count or -1 if target is found

private int

Returns:

index or -1 if not found
binaryFirstSearch
()

Returns the index of the lowest element == the given search target, or -1

private int

Returns:

the index or count.
binarySlotSearch
(boolean
ignored
fullCompare
)

Returns the index of the lowest element >= the given search target, or count.

public int
public void
public boolean
protected int

Returns:

-1, 0 or +1
compare
(int
the index
i
)

Check if targeted column value in the row indexed i is less than the search target object.

public void
protected void
public LongLookup
private boolean
private void
fastQuickSort()

fast quicksort using a stack on the heap to reduce stack use

private void
fastQuickSortRecursive()

fast quicksort with recursive quicksort implementation

public int
findFirstEqualKeyIndex(int
the value
value
)

Returns: the index

public int
findFirstGreaterEqualKeyIndex(int
the value
value
)

Returns: the index

public int

Returns:

the index
findFirstGreaterEqualSlotIndex
(int
the value
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.

public int
getKey(int i)

public int[]
public long
public long
public long
public int
getValue(int i)

public int[]
private void
insertionSort(int lo0, int hi0)

protected boolean

Returns:

true or false
lessThan
(int
the first index
i
,
int
the second index
j
)

Check if row indexed i is less than row indexed j

public long
public int
lookup(int key)

public long
lookup(long key, long def)

Implements org.hsqldb.lib.LongLookup.lookup.

public int
lookup(int key, int def)

public int
protected void
moveAndInsertRow(int i, int j)

protected void
moveRows(int fromIndex, int toIndex, int rows)

private int
partition(int start, int end)

pack-priv int

Returns:

int key
peekKey
()

peek the key at top of stack.

pack-priv int

Returns:

int value
peekValue
()

peek the value at top of stack

pack-priv boolean

Returns:

boolean if there was an element
pop
()

pop the pair at top of stack

pack-priv boolean

Returns:

boolean true if successful
push
(int
the key
key
,
int
the value
value
)

push key - value pair

private void
quickSort(int l, int r)

public final void
remove(int position)

public void
public boolean

Returns:

true or false depending on success
removeKey
(int
the key to remove
key
)

Removes the (unique) key and its value.

public void
removeRange(int start, int limit)

public void
setKey(int
the index
i
,
int
the new key
key
)

Modifies an existing pair at the given index.

public void
public void
setLongValue(int
the index
i
,
long
the new value
value
)

Implements org.hsqldb.lib.LongLookup.setLongValue.

Modifies an existing pair at the given index.

public void
setSize(int newSize)

public void
setValue(int
the index
i
,
int
the new value
value
)

Modifies an existing pair at the given index.

public void
public int
public void
public void
public void
protected void
swap(int i1, int i2)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

capacityback to summary
private int capacity
countback to summary
private int count
fixedSizeback to summary
private final boolean fixedSize
keysback to summary
private int[] keys
sortedback to summary
private boolean sorted
sortOnValuesback to summary
private boolean sortOnValues
targetSearchValueback to summary
private int targetSearchValue
valuesback to summary
private int[] values

Constructor Detail

DoubleIntIndexback to summary
public DoubleIntIndex(int capacity)
DoubleIntIndexback to summary
public DoubleIntIndex(int capacity, boolean fixedSize)

Method Detail

addback to summary
public int add(long key, long value)

Implements org.hsqldb.lib.LongLookup.add.

addback to summary
public int add(int key, int value)

Adds a pair, maintaining sort order on current search target column.

Parameters
key:int

the key

value:int

the value

Returns:int

index of added key or -1 if full

addCountback to summary
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:int

the key to update or add

value:int

the count to add

Returns:int

the new count for the key

addCountback to summary
public int addCount(int key)
addOrReplaceUniqueback to summary
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:int

the key to add or find

value:int

the value to add or update

Returns:boolean

true or false depending on success

addSortedback to summary
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:int

the key

value:int

the value

Returns:boolean

true or false depending on success

addUniqueback to summary
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:int

the key

value:int

the value

Returns:boolean

true or false depending on success

addUnsortedback to summary
public boolean addUnsorted(long key, long value)

Implements org.hsqldb.lib.LongLookup.addUnsorted.

addUnsortedback to summary
public boolean addUnsorted(int key, int value)

Adds a pair into the table.

Parameters
key:int

the key

value:int

the value

Returns:boolean

true or false depending on success

addUnsortedback to summary
public boolean addUnsorted(LongLookup other)

Implements org.hsqldb.lib.LongLookup.addUnsorted.

binaryEmptySlotSearchback to summary
private int binaryEmptySlotSearch()

Returns the index of the lowest element > the given search target or count or -1 if target is found

Returns:int

the index

binaryFirstSearchback to summary
private int binaryFirstSearch()

Returns the index of the lowest element == the given search target, or -1

Returns:int

index or -1 if not found

binarySlotSearchback to summary
private int binarySlotSearch(boolean fullCompare)

Returns the index of the lowest element >= the given search target, or count.

Parameters
fullCompare:boolean

ignored

Returns:int

the index or count.

capacityback to summary
public int capacity()
clearback to summary
public void clear()

Implements org.hsqldb.lib.LongLookup.clear.

compactLookupAsIntervalsback to summary
public boolean compactLookupAsIntervals()

Implements org.hsqldb.lib.LongLookup.compactLookupAsIntervals.

compareback to summary
protected int compare(int i)

Check if targeted column value in the row indexed i is less than the search target object.

Parameters
i:int

the index

Returns:int

-1, 0 or +1

copyToback to summary
public void copyTo(DoubleIntIndex other)
doubleCapacityback to summary
protected void doubleCapacity()
duplicateback to summary
public LongLookup duplicate()

Implements org.hsqldb.lib.LongLookup.duplicate.

ensureCapacityToAddback to summary
private boolean ensureCapacityToAdd(int extra)
fastQuickSortback to summary
private void fastQuickSort()

fast quicksort using a stack on the heap to reduce stack use

fastQuickSortRecursiveback to summary
private void fastQuickSortRecursive()

fast quicksort with recursive quicksort implementation

findFirstEqualKeyIndexback to summary
public int findFirstEqualKeyIndex(int value)
Parameters
value:int

the value

Returns:int

the index

findFirstGreaterEqualKeyIndexback to summary
public int findFirstGreaterEqualKeyIndex(int value)
Parameters
value:int

the value

Returns:int

the index

findFirstGreaterEqualSlotIndexback to summary
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:int

the value

Returns:int

the index

getKeyback to summary
public int getKey(int i)
getKeysback to summary
public int[] getKeys()
getLongKeyback to summary
public long getLongKey(int i)

Implements org.hsqldb.lib.LongLookup.getLongKey.

getLongValueback to summary
public long getLongValue(int i)

Implements org.hsqldb.lib.LongLookup.getLongValue.

getTotalValuesback to summary
public long getTotalValues()

Implements org.hsqldb.lib.LongLookup.getTotalValues.

getValueback to summary
public int getValue(int i)
getValuesback to summary
public int[] getValues()
insertionSortback to summary
private void insertionSort(int lo0, int hi0)
lessThanback to summary
protected boolean lessThan(int i, int j)

Check if row indexed i is less than row indexed j

Parameters
i:int

the first index

j:int

the second index

Returns:boolean

true or false

lookupback to summary
public long lookup(long key) throws NoSuchElementException

Implements org.hsqldb.lib.LongLookup.lookup.

lookupback to summary
public int lookup(int key) throws NoSuchElementException
lookupback to summary
public long lookup(long key, long def)

Implements org.hsqldb.lib.LongLookup.lookup.

lookupback to summary
public int lookup(int key, int def)
lookupFirstGreaterEqualback to summary
public int lookupFirstGreaterEqual(int key) throws NoSuchElementException
moveAndInsertRowback to summary
protected void moveAndInsertRow(int i, int j)
moveRowsback to summary
protected void moveRows(int fromIndex, int toIndex, int rows)
partitionback to summary
private int partition(int start, int end)
peekKeyback to summary
pack-priv int peekKey()

peek the key at top of stack. Uses the data structure as a stack.

Returns:int

int key

peekValueback to summary
pack-priv int peekValue()

peek the value at top of stack

Returns:int

int value

popback to summary
pack-priv boolean pop()

pop the pair at top of stack

Returns:boolean

boolean if there was an element

pushback to summary
pack-priv boolean push(int key, int value)

push key - value pair

Parameters
key:int

the key

value:int

the value

Returns:boolean

boolean true if successful

quickSortback to summary
private void quickSort(int l, int r)
removeback to summary
public final void remove(int position)
removeAllback to summary
public void removeAll()
removeKeyback to summary
public boolean removeKey(int key)

Removes the (unique) key and its value. Must be sorted on key.

Parameters
key:int

the key to remove

Returns:boolean

true or false depending on success

removeRangeback to summary
public void removeRange(int start, int limit)
setKeyback to summary
public void setKey(int i, int key)

Modifies an existing pair at the given index.

Parameters
i:int

the index

key:int

the new key

setKeysSearchTargetback to summary
public void setKeysSearchTarget()
setLongValueback to summary
public void setLongValue(int i, long value)

Implements org.hsqldb.lib.LongLookup.setLongValue.

Modifies an existing pair at the given index.

Parameters
i:int

the index

value:long

the new value

setSizeback to summary
public void setSize(int newSize)
setValueback to summary
public void setValue(int i, int value)

Modifies an existing pair at the given index.

Parameters
i:int

the index

value:int

the new value

setValuesSearchTargetback to summary
public void setValuesSearchTarget()
sizeback to summary
public int size()

Implements org.hsqldb.lib.LongLookup.size.

sortback to summary
public void sort()

Implements org.hsqldb.lib.LongLookup.sort.

sortOnKeysback to summary
public void sortOnKeys()
sortOnValuesback to summary
public void sortOnValues()
swapback to summary
protected void swap(int i1, int i2)