Top Description Inners Fields Constructors Methods
org.hsqldb.map

public Class BaseHashMap

extends Object
Class Inheritance
Known Direct Subclasses
org.hsqldb.map.ValuePoolHashMap, org.hsqldb.persist.Cache, org.hsqldb.lib.HashMap, org.hsqldb.lib.HashSet, org.hsqldb.lib.IntHashSet, org.hsqldb.lib.IntKeyHashMap, org.hsqldb.lib.IntKeyHashMapConcurrent, org.hsqldb.lib.IntKeyIntValueHashMap, org.hsqldb.lib.IntKeyLongValueHashMap, org.hsqldb.lib.IntValueHashMap, org.hsqldb.lib.LongKeyHashMap, org.hsqldb.lib.LongKeyIntValueHashMap, org.hsqldb.lib.LongKeyLongValueHashMap, org.hsqldb.lib.LongValueHashMap, org.hsqldb.lib.MultiValueHashMap, org.hsqldb.lib.OrderedLongHashSet, org.hsqldb.lib.OrderedLongKeyHashMap
Imports
java.lang.reflect.Array, java.util.Arrays, .NoSuchElementException, java.util.concurrent.atomic.AtomicInteger, org.hsqldb.lib.ArrayCounter, .ArrayUtil, .ObjectComparator, .PrimitiveIterator

Base class for hash tables or sets. The exact type of the structure is defined by the constructor. Each instance has at least a keyTable array and a HashIndex instance for looking up the keys into this table. Instances that are maps also have a valueTable the same size as the keyTable. Special getOrAddXXX() methods are used for object maps in some subclasses.
Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
1.7.2
Version
2.7.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
BaseHashMap.BaseHashIterator

Iterator returns Object, int or long and is used both for keys and values

protected class
protected class
BaseHashMap.ValueCollectionIterator

Iterator for accessing the values for a single key in MultiValueHashMap Currently only for object maps

Field Summary

Modifier and TypeField and Description
public static final int
protected AtomicInteger
protected int
protected int[]
protected ObjectComparator<T>
public static final Object[]
protected HashIndex
protected boolean
protected final int
protected static final int
protected int[]
protected int[]
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected final float
protected static final int
protected long[]
protected long[]
protected int
protected boolean
protected static final int
protected static final int
protected static final int
protected Object[]
protected Object[]
protected Object[]
protected Object[]
protected static final int
protected static final int
protected int
protected int
protected int
protected int

Constructor Summary

AccessConstructor and Description
protected
BaseHashMap(int initialCapacity, int keyType, int valueType, boolean hasAccessCount)

Method Summary

Modifier and TypeMethod and Description
protected boolean
addMultiVal(long longKey, long longValue, Object objectKey, Object objectValue)

Single method for adding key / values in multi-value maps.

protected Object
addOrRemoveObject(long longKey, Object object, boolean remove)

For object sets using long key attribute of object for equality and hash.

protected Object
addOrUpdate(long longKey, long longValue, Object objectKey, Object objectValue)

generic method for adding keys and values or updating values returns existing Object value if any or null for SETs, returns TRUE or FALSE

protected int
public void
clear()

Clear the map completely.

private void
clearElementArrays(final int from, final int to)

clear all the key / value data in a range.

private void
clearToHalf()

Clear approximately half elements from the map, starting with those with low accessTable ranking.

public BaseHashMap
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

protected final boolean
containsIntKey(int key)

protected final boolean
containsLongKey(long key)

protected final boolean
protected boolean
protected boolean
containsValue(int value)

protected boolean
containsValue(long value)

pack-priv BaseHashMap
protected int
getAccessCountCeiling(int count, int margin)

Return the max accessCount value for count elements with the lowest access count.

protected int
protected int
getLookup(Object key, int hash)

protected int
getLookup(int key)

protected int
getLookup(long key)

protected PrimitiveIterator<E>
protected int
getObjectLookup(long key)

pack-priv void
insertIntoElementArrays(int size, int lookup)

move the elements to create a gap

protected void
insertRow(int lookup)

public boolean
protected int
protected int
protected <T> T[]
pack-priv int
nextLookup(int lookup, int limitLookup, boolean hasZeroKey, int zeroKeyIndex)

find the next lookup in the key/value tables with an entry allows the use of old limit and zero int key attributes

protected int
nextLookup(int lookup)

find the next lookup in the key/value tables with an entry uses current limits and zero integer key state

protected void
rehash(int newCapacity)

rehash uses existing key and element arrays.

protected Object
remove(long longKey, long longValue, Object objectKey, Object objectValue, boolean matchValue, boolean removeRow)

generic method for removing keys returns existing Object value if any (or Object key if this is a set)

pack-priv void
removeFromElementArrays(int size, int lookup)

move the elements after a removed key / value pair to fill the gap

protected Object
removeMultiVal(long longKey, long longValue, Object objectKey, Object objectValue, boolean matchValue)

Single method for removing key / values in multi-value maps.

protected Object
removeObject(Object objectKey, boolean removeRow)

type specific method for Object sets or Object to Object maps

protected void
removeRow(int lookup)

row already freed of key / element

protected boolean
protected void
private void
resizeElementArrays(int dataLength, int newLength)

resize the arrays containing the key / value data

protected void
setAccessCountFloor(int count)

This is called after all elements below count accessCount have been removed

public int
size()

protected Object[]
toArray(boolean keys)

protected <T> T[]
toArray(T[] array, boolean keys)

protected int[]
toIntArray(int[] array, boolean keys)

protected long[]
toLongArray(long[] array, boolean keys)

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ACCESS_MAXback to summary
public static final int ACCESS_MAX
accessCountback to summary
protected AtomicInteger accessCount
accessMinback to summary
protected int accessMin
accessTableback to summary
protected int[] accessTable
comparatorback to summary
protected ObjectComparator<T> comparator
emptyObjectArrayback to summary
public static final Object[] emptyObjectArray
hashIndexback to summary
protected HashIndex hashIndex
hasZeroKeyback to summary
protected boolean hasZeroKey
initialCapacityback to summary
protected final int initialCapacity
intKeyOrValueback to summary
protected static final int intKeyOrValue
intKeyTableback to summary
protected int[] intKeyTable
intValueTableback to summary
protected int[] intValueTable
isAccessCountback to summary
protected boolean isAccessCount
isIntKeyback to summary
protected boolean isIntKey
isIntValueback to summary
protected boolean isIntValue
isLastAccessCountback to summary
protected boolean isLastAccessCount
isListback to summary
protected boolean isList
isLongKeyback to summary
protected boolean isLongKey
isLongValueback to summary
protected boolean isLongValue
isMultiValueback to summary
protected boolean isMultiValue
isNoValueback to summary
protected boolean isNoValue
isObjectKeyback to summary
protected boolean isObjectKey
isObjectValueback to summary
protected boolean isObjectValue
loadFactorback to summary
protected final float loadFactor
longKeyOrValueback to summary
protected static final int longKeyOrValue
longKeyTableback to summary
protected long[] longKeyTable
longValueTableback to summary
protected long[] longValueTable
maxCapacityback to summary
protected int maxCapacity
minimizeOnEmptyback to summary
protected boolean minimizeOnEmpty
NO_PURGEback to summary
protected static final int NO_PURGE
noKeyOrValueback to summary
protected static final int noKeyOrValue
objectKeyOrValueback to summary
protected static final int objectKeyOrValue
objectKeyTableback to summary
protected Object[] objectKeyTable
objectValueTableback to summary
protected Object[] objectValueTable
objectValueTable2back to summary
protected Object[] objectValueTable2
objectValueTable3back to summary
protected Object[] objectValueTable3
PURGE_ALLback to summary
protected static final int PURGE_ALL
PURGE_HALFback to summary
protected static final int PURGE_HALF
purgePolicyback to summary
protected int purgePolicy
thresholdback to summary
protected int threshold
zeroKeyIndexback to summary
protected int zeroKeyIndex
zeroOrNullValueCountback to summary
protected int zeroOrNullValueCount

Constructor Detail

BaseHashMapback to summary
protected BaseHashMap(int initialCapacity, int keyType, int valueType, boolean hasAccessCount) throws IllegalArgumentException

Method Detail

addMultiValback to summary
protected boolean addMultiVal(long longKey, long longValue, Object objectKey, Object objectValue)

Single method for adding key / values in multi-value maps. Values for each key are clustered.

addOrRemoveObjectback to summary
protected Object addOrRemoveObject(long longKey, Object object, boolean remove)

For object sets using long key attribute of object for equality and hash. Used in org.hsqldb.persist.Cache

addOrUpdateback to summary
protected Object addOrUpdate(long longKey, long longValue, Object objectKey, Object objectValue)

generic method for adding keys and values or updating values returns existing Object value if any or null for SETs, returns TRUE or FALSE

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

Clear the map completely.

clearElementArraysback to summary
private void clearElementArrays(final int from, final int to)

clear all the key / value data in a range.

clearToHalfback to summary
private void clearToHalf()

Clear approximately half elements from the map, starting with those with low accessTable ranking. Only for value maps

cloneback to summary
public BaseHashMap clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

containsIntKeyback to summary
protected final boolean containsIntKey(int key)
containsLongKeyback to summary
protected final boolean containsLongKey(long key)
containsObjectKeyback to summary
protected final boolean containsObjectKey(Object key)
containsValueback to summary
protected boolean containsValue(Object value)
containsValueback to summary
protected boolean containsValue(int value)
containsValueback to summary
protected boolean containsValue(long value)
duplicateback to summary
pack-priv BaseHashMap duplicate()
getAccessCountCeilingback to summary
protected int getAccessCountCeiling(int count, int margin)

Return the max accessCount value for count elements with the lowest access count. Always return at least accessMin + 1

getLookupback to summary
protected int getLookup(Object key)
getLookupback to summary
protected int getLookup(Object key, int hash)
getLookupback to summary
protected int getLookup(int key)
getLookupback to summary
protected int getLookup(long key)
getMultiValuesIteratorback to summary
protected PrimitiveIterator<E> getMultiValuesIterator(Object key)
getObjectLookupback to summary
protected int getObjectLookup(long key)
insertIntoElementArraysback to summary
pack-priv void insertIntoElementArrays(int size, int lookup)

move the elements to create a gap

insertRowback to summary
protected void insertRow(int lookup)
isEmptyback to summary
public boolean isEmpty()
multiValueElementCountback to summary
protected int multiValueElementCount(Object key)
multiValueKeyCountback to summary
protected int multiValueKeyCount()
multiValueKeysToArrayback to summary
protected <T> T[] multiValueKeysToArray(T[] array)
nextLookupback to summary
pack-priv int nextLookup(int lookup, int limitLookup, boolean hasZeroKey, int zeroKeyIndex)

find the next lookup in the key/value tables with an entry allows the use of old limit and zero int key attributes

nextLookupback to summary
protected int nextLookup(int lookup)

find the next lookup in the key/value tables with an entry uses current limits and zero integer key state

rehashback to summary
protected void rehash(int newCapacity)

rehash uses existing key and element arrays. key / value pairs are put back into the arrays from the top, removing any gaps. any redundant key / value pairs duplicated at the end of the array are then cleared. newCapacity must be larger or equal to existing number of elements.

removeback to summary
protected Object remove(long longKey, long longValue, Object objectKey, Object objectValue, boolean matchValue, boolean removeRow)

generic method for removing keys returns existing Object value if any (or Object key if this is a set)

removeFromElementArraysback to summary
pack-priv void removeFromElementArrays(int size, int lookup)

move the elements after a removed key / value pair to fill the gap

removeMultiValback to summary
protected Object removeMultiVal(long longKey, long longValue, Object objectKey, Object objectValue, boolean matchValue)

Single method for removing key / values in multi-value maps.

removeObjectback to summary
protected Object removeObject(Object objectKey, boolean removeRow)

type specific method for Object sets or Object to Object maps

removeRowback to summary
protected void removeRow(int lookup)

row already freed of key / element

resetback to summary
protected boolean reset()
resetAccessCountback to summary
protected void resetAccessCount()
resizeElementArraysback to summary
private void resizeElementArrays(int dataLength, int newLength)

resize the arrays containing the key / value data

setAccessCountFloorback to summary
protected void setAccessCountFloor(int count)

This is called after all elements below count accessCount have been removed

sizeback to summary
public int size()
toArrayback to summary
protected Object[] toArray(boolean keys)
toArrayback to summary
protected <T> T[] toArray(T[] array, boolean keys)
toIntArrayback to summary
protected int[] toIntArray(int[] array, boolean keys)
toLongArrayback to summary
protected long[] toLongArray(long[] array, boolean keys)
org.hsqldb.map back to summary

protected Class BaseHashMap.BaseHashIterator

extends Object
implements PrimitiveIterator
Class Inheritance
All Implemented Interfaces
org.hsqldb.lib.PrimitiveIterator, org.hsqldb.lib.Iterator
Known Direct Subclasses
org.hsqldb.lib.HashMap.EntrySetIterator, org.hsqldb.lib.IntKeyHashMap.EntrySetIterator, org.hsqldb.lib.IntKeyHashMapConcurrent.EntrySetIterator, org.hsqldb.lib.IntKeyIntValueHashMap.EntrySetIterator, org.hsqldb.lib.IntKeyLongValueHashMap.EntrySetIterator, org.hsqldb.lib.IntValueHashMap.EntrySetIterator, org.hsqldb.lib.LongKeyHashMap.EntrySetIterator, org.hsqldb.lib.LongKeyIntValueHashMap.EntrySetIterator, org.hsqldb.lib.LongKeyLongValueHashMap.EntrySetIterator, org.hsqldb.lib.LongValueHashMap.EntrySetIterator, org.hsqldb.lib.MultiValueHashMap.EntrySetIterator, org.hsqldb.lib.OrderedLongKeyHashMap.EntrySetIterator

Iterator returns Object, int or long and is used both for keys and values

Field Summary

Modifier and TypeField and Description
protected int
protected boolean
protected int
protected boolean

Constructor Summary

AccessConstructor and Description
public
BaseHashIterator()

default is iterator for values

public
BaseHashIterator(boolean keys)

Method Summary

Modifier and TypeMethod and Description
public int
public int
public boolean
public Object
public int
public long
public void
public void
public void
setAccessCount(int count)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

counterback to summary
protected int counter
keysback to summary
protected boolean keys
lookupback to summary
protected int lookup
removedback to summary
protected boolean removed

Constructor Detail

BaseHashIteratorback to summary
public BaseHashIterator()

default is iterator for values

BaseHashIteratorback to summary
public BaseHashIterator(boolean keys)

Method Detail

getAccessCountback to summary
public int getAccessCount()
getLookupback to summary
public int getLookup()
hasNextback to summary
public boolean hasNext()

Implements org.hsqldb.lib.Iterator.hasNext.

nextback to summary
public Object next() throws NoSuchElementException

Implements org.hsqldb.lib.Iterator.next.

nextIntback to summary
public int nextInt() throws NoSuchElementException

Overrides default org.hsqldb.lib.Iterator.nextInt.

nextLongback to summary
public long nextLong() throws NoSuchElementException

Overrides default org.hsqldb.lib.Iterator.nextLong.

removeback to summary
public void remove() throws NoSuchElementException

Overrides default org.hsqldb.lib.Iterator.remove.

resetback to summary
public void reset()
setAccessCountback to summary
public void setAccessCount(int count)
org.hsqldb.map back to summary

protected Class BaseHashMap.MultiValueKeyIterator

extends Object
implements PrimitiveIterator
Class Inheritance
All Implemented Interfaces
org.hsqldb.lib.PrimitiveIterator, org.hsqldb.lib.Iterator

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv int
pack-priv Object
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
public Object
public int
public long
public void
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexback to summary
pack-priv int index
lookupback to summary
pack-priv int lookup
oldKeyback to summary
pack-priv Object oldKey
removedback to summary
pack-priv boolean removed

Constructor Detail

MultiValueKeyIteratorback to summary
public MultiValueKeyIterator()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements org.hsqldb.lib.Iterator.hasNext.

nextback to summary
public Object next() throws NoSuchElementException

Implements org.hsqldb.lib.Iterator.next.

nextIntback to summary
public int nextInt() throws NoSuchElementException

Overrides default org.hsqldb.lib.Iterator.nextInt.

nextLongback to summary
public long nextLong() throws NoSuchElementException

Overrides default org.hsqldb.lib.Iterator.nextLong.

removeback to summary
public void remove() throws NoSuchElementException

Overrides default org.hsqldb.lib.Iterator.remove.

toNextLookupback to summary
private void toNextLookup()
org.hsqldb.map back to summary

protected Class BaseHashMap.ValueCollectionIterator

extends Object
implements PrimitiveIterator
Class Inheritance
All Implemented Interfaces
org.hsqldb.lib.PrimitiveIterator, org.hsqldb.lib.Iterator

Iterator for accessing the values for a single key in MultiValueHashMap Currently only for object maps

Field Summary

Modifier and TypeField and Description
pack-priv Object
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
public Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

keyback to summary
pack-priv Object key
lookupback to summary
pack-priv int lookup

Constructor Detail

ValueCollectionIteratorback to summary
pack-priv ValueCollectionIterator(Object key, int lookup)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements org.hsqldb.lib.Iterator.hasNext.

nextback to summary
public Object next() throws NoSuchElementException

Implements org.hsqldb.lib.Iterator.next.