Package org.jacop.jasat.utils.structures
Class IntHashMap<E>
- java.lang.Object
-
- org.jacop.jasat.utils.structures.IntHashMap<E>
-
public final class IntHashMap<E> extends java.lang.Object
an efficient map with ints as keys. This is a hashtable with arrays.- Version:
- 4.7
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
IntHashMap.EntryIterator
iterator over valuesprivate class
IntHashMap.KeysIterator
class used to iterate on the keys of the map
-
Field Summary
Fields Modifier and Type Field Description private int
cardinal
private static int
HASH_PRIME
private static int
INITIAL_SIZE
private static int
MAX_BUCKET_SIZE
private int[][]
tableKey
private E[][]
tableValue
-
Constructor Summary
Constructors Modifier Constructor Description IntHashMap()
public constructorprivate
IntHashMap(int size)
builds a new map with given size
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
clear the table, removing all elementsboolean
containsKey(int key)
check if the key is in the tableboolean
containsKey(java.lang.Object arg0)
private void
doubleSize()
double the size of the tablejava.lang.Iterable<java.util.Map.Entry<java.lang.Integer,E>>
entrySet()
iterates over all entries in the mapprivate int
find(int key, int index)
try to find the key in the table.E
get(int key)
get the value associated with key, or null otherwiseprivate int
hash(int key, int length)
hash an integer and returns the result modulo lengthboolean
isEmpty()
java.util.Set<java.lang.Integer>
keySet()
E
put(int key, E value)
put the value associated with the keyboolean
remove(int key)
remove the key from the tableint
size()
-
-
-
Field Detail
-
HASH_PRIME
private static final int HASH_PRIME
- See Also:
- Constant Field Values
-
INITIAL_SIZE
private static final int INITIAL_SIZE
- See Also:
- Constant Field Values
-
MAX_BUCKET_SIZE
private static final int MAX_BUCKET_SIZE
- See Also:
- Constant Field Values
-
tableKey
private int[][] tableKey
-
tableValue
private E[][] tableValue
-
cardinal
private int cardinal
-
-
Method Detail
-
clear
public void clear()
clear the table, removing all elements
-
containsKey
public boolean containsKey(int key)
check if the key is in the table- Parameters:
key
- the key- Returns:
- true if the key is in the table
-
get
public E get(int key)
get the value associated with key, or null otherwise- Parameters:
key
- the key- Returns:
- the value associated with key, or null otherwise
-
isEmpty
public boolean isEmpty()
- Returns:
- true if the table is empty
-
put
public E put(int key, E value)
put the value associated with the key- Parameters:
key
- the keyvalue
- the value- Returns:
- the old value, or null
-
remove
public boolean remove(int key)
remove the key from the table- Parameters:
key
- the key to remove- Returns:
- true if the key was in the table
-
size
public int size()
-
containsKey
public boolean containsKey(java.lang.Object arg0)
-
doubleSize
private void doubleSize()
double the size of the table
-
find
private int find(int key, int index)
try to find the key in the table. On success, will return the index of the key in its bucket; otherwise, will return -1- Parameters:
key
- the key to searchindex
- the hash of the key- Returns:
- the index of the key in the tableKey[hash(key)], or -1 if the key is not present
-
hash
private int hash(int key, int length)
hash an integer and returns the result modulo length- Parameters:
key
- the int to hashlength
- the length (space of keys)- Returns:
- an int between 0 and length-1 inclusive
-
keySet
public java.util.Set<java.lang.Integer> keySet()
- Returns:
- the set of keys of the map
-
entrySet
public java.lang.Iterable<java.util.Map.Entry<java.lang.Integer,E>> entrySet()
iterates over all entries in the map- Returns:
- iterator for enumeration of elements in this map
-
-