|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection<T>
cz.cuni.jagrlib.IntMap<T>
public class IntMap<T>
This object maps integer keys to Object values.
Each key can map to at most one Object instance, null values
are allowed.
Efficient alternative to Map<K,V> container classes.
Method signatures are as similar as possible (for convenience),
the class now implements abstract Collection interface.
| Nested Class Summary | |
|---|---|
protected class |
IntMap.CommonIterator
Common iterator ancestor. |
protected class |
IntMap.TargetIterator
Internal class handling target object iteration. |
protected class |
IntMap.TupleIterator
Internal class handling tuple-iteration. |
| Field Summary | |
|---|---|
protected float |
maxLoad
Overload bound. |
int |
NULL_KEY
Special value used in keyArray for empty (unused) slots. |
protected int |
REMOVED_KEY
Special value used in keyArray for slots with removed keys. |
| Constructor Summary | |
|---|---|
IntMap()
Dafault parameters (small initial capacity, default load factor = 0.6). |
|
IntMap(int capacity)
Explicit map capacity, default load factor ( 0.6). |
|
IntMap(int capacity,
float loadFactor)
Explicit map capacity and load-factor. |
|
IntMap(java.util.Map<? extends java.lang.Integer,? extends T> m)
The same mappings as the specified Map. |
|
| Method Summary | |
|---|---|
void |
clear()
Removes all mappings from this map. |
java.lang.Object |
clone()
Returns a shallow copy of this IntMap instance:
the values themselves are not cloned. |
void |
compact()
Rehashes the data structure to be more compact (and fast - if remove(int) operations were performed before). |
boolean |
containsKey(int key)
"Contains" predicate for keys |
boolean |
containsValue(T value)
"Contains" predicate for values. |
protected int |
find(int key)
Finds slot with the given key value. |
T |
get(int key)
Returns the value to which this map maps the specified key. |
boolean |
isEmpty()
Is the map empty? |
java.util.Iterator<T> |
iterator()
Iterates through all target values. |
java.util.Set<java.lang.Integer> |
keySet()
Returns a set view of the keys contained in this map. |
T |
put(int key,
T value)
Associates the specified value with the specified key in this map If the map previously contained a mapping for this key, the old value is replaced by the specified value (a returned back). |
void |
putAll(java.util.Map<? extends java.lang.Integer,? extends T> m)
Copies all of the mappings from the specified map to this map. |
protected void |
readObject(java.io.ObjectInputStream s)
Reconstitute the IntMap instance from a stream
(i.e. deserialize it). |
protected void |
rehash(int newSize)
Rehashes the map arrays and prepares them for the specified capacity. |
T |
remove(int key)
Removes the mapping for this key from this map if it is present Returns the value to which the map previously associated the key, or null if the map contained no mapping for this key. |
int |
size()
Returns the number of key-value mappings in this map. |
java.util.Iterator<IntTuple<T>> |
tupleIterator()
Iterates through all map tuples. |
java.util.Collection<T> |
values()
Returns a collection view of the values contained in this map. |
protected void |
writeObject(java.io.ObjectOutputStream s)
Save the state of the IntMap instance to a stream (i.e.,
serialize it). |
| Methods inherited from class java.util.AbstractCollection |
|---|
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
equals, hashCode |
| Field Detail |
|---|
public final int NULL_KEY
keyArray for empty (unused) slots.
protected final int REMOVED_KEY
keyArray for slots with removed keys.
protected float maxLoad
| Constructor Detail |
|---|
public IntMap()
0.6).
public IntMap(int capacity)
0.6).
public IntMap(int capacity,
float loadFactor)
public IntMap(java.util.Map<? extends java.lang.Integer,? extends T> m)
Map.
The IntMap is created with default load factor (0.6)
and an initial capacity sufficient to hold the mappings
in the specified Map.
m - the map whose mappings are to be placed in this map.| Method Detail |
|---|
protected void rehash(int newSize)
newSize - New map capacity.protected final int find(int key)
key - Key to be looked for.
-1 for invalid key.public final int size()
null values are counted in.
size in interface java.util.Collection<T>size in class java.util.AbstractCollection<T>public final boolean isEmpty()
isEmpty in interface java.util.Collection<T>isEmpty in class java.util.AbstractCollection<T>true if this map contains no key-value mappings.public final boolean containsKey(int key)
key - Key whose presence in this map is to be tested.
true if this map contains a mapping (even null)
for the specified key.public boolean containsValue(T value)
true if and only if this map
contains at least one mapping to a value v such that
(value==null ? v==null : value.equals(v)).
value - Value whose presence in this map is to be tested.
true if this map maps one or more keys to the
specified value.public T get(int key)
put( key, x ) was called) and mapping with null
value (put( key, null ) was called).
The containsKey predicate can be used to
distinguish these two cases.
key - Key whose associated value is to be returned.
null if the map contains no mapping for this key.containsKey(int)
public T put(int key,
T value)
key - Key with which the specified value is to be associated.value - Value to be associated with the specified key.
null
if there was no mapping for key. A null return can
also indicate that the map previously associated null
with the specified key.public T remove(int key)
Returns the value to which the map previously associated the key, or
null if the map contained no mapping for this key. (A
null return can also indicate that the map previously
associated null with the specified key).
The map will not contain a mapping for the specified key once
the call returns.
key - Key whose mapping is to be removed from the map.
null
if there was no mapping for key.public void putAll(java.util.Map<? extends java.lang.Integer,? extends T> m)
m - Mappings to be stored in this map.
java.lang.ClassCastException - if the class of a key or value in the
specified map prevents it from being stored in this map.public void clear()
clear in interface java.util.Collection<T>clear in class java.util.AbstractCollection<T>public void compact()
remove(int) operations were performed before).
public java.util.Set<java.lang.Integer> keySet()
public java.util.Collection<T> values()
public final java.util.Iterator<IntTuple<T>> tupleIterator()
IntTuple,
iterator()public final java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>iterator in interface java.util.Collection<T>iterator in class java.util.AbstractCollection<T>tupleIterator()public java.lang.Object clone()
IntMap instance:
the values themselves are not cloned.
clone in class java.lang.Object
protected void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException
IntMap instance to a stream (i.e.,
serialize it).
java.io.IOException
protected void readObject(java.io.ObjectInputStream s)
throws java.io.IOException,
java.lang.ClassNotFoundException
IntMap instance from a stream
(i.e. deserialize it).
java.io.IOException
java.lang.ClassNotFoundException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||