|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ix.isim.util.LongKeyTreeMap
public class LongKeyTreeMap
This is a Red-Black-Tree-based implementation of a sorted map, mapping
long
s to objects. This class guarantees that the map will be
in ascending key order and the Iterator
returned by
values()
will list the values (not the keys) in ascending key
order.
This implementation provides guaranteed log(n) time cost for the
containsKey(...)
, get(...)
, put(...)
and remove(...)
operations. Algorithms are adaptations of those
in Cormen, Leiserson, and Rivest's Introduction to Algorithms.
This implementation should essentially behave like the one in the
java.util package. The main difference is that keys are long
s
here which are not ojbects. The use of long
s rather than
Double
s greatly improves the efficiency of the implementation.
Nested Class Summary | |
---|---|
(package private) static class |
LongKeyTreeMap.Entry
A node in the tree. |
(package private) class |
LongKeyTreeMap.LongKeyTreeMapIterator
|
Field Summary | |
---|---|
protected LongKeyTreeMap.Entry |
root
the root of the tree |
Constructor Summary | |
---|---|
LongKeyTreeMap()
This constructor creates a new, empty map. |
Method Summary | |
---|---|
void |
clear()
This function removes all mappings from this map. |
protected java.lang.Object |
clone()
This class does not support cloning and an exception will be thrown if this method is called. |
boolean |
containsKey(long key)
This function returns true if this map contains a mapping
for the specified key. |
long |
firstKey()
This function returns the first (lowest) key currently in this sorted map. |
java.lang.Object |
get(long key)
This function returns the value to which this map maps the specified key. |
long |
lastKey()
This function returns the last (highest) key currently in this sorted map. |
java.lang.Object |
put(long key,
java.lang.Object value)
This function associates the specified value with the specified key in this map. |
java.lang.Object |
remove(long key)
This function removes the mapping for this key from this map if it was present. |
int |
size()
This function returns the number of key-value mappings in this map. |
java.util.Iterator |
values()
This function returns an iterator for the objects in this map. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected LongKeyTreeMap.Entry root
Constructor Detail |
---|
public LongKeyTreeMap()
This constructor creates a new, empty map.
Method Detail |
---|
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
This class does not support cloning and an exception will be thrown if this method is called.
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- will be thrownpublic int size()
This function returns the number of key-value mappings in this map.
public boolean containsKey(long key)
This function returns true
if this map contains a mapping
for the specified key.
key
- the key whose presence in this map is to be tested
true
if this map contains a mapping for the
specified keypublic java.lang.Object get(long key)
This function returns the value to which this map maps the specified
key. It returns null
if the map contains no mapping for this
key. A return value of null
does not necessarily
indicate that the map contains no mapping for the key; it's also possible
that the map explicitly maps the key to null
. The
containsKey(...)
operation may be used to distinguish these
two cases.
key
- key whose associated value is to be returned
null
if the map contains no mapping for the keypublic long firstKey() throws java.util.NoSuchElementException
This function returns the first (lowest) key currently in this sorted map.
NoSuchElementException
- if the map is emptypublic long lastKey() throws java.util.NoSuchElementException
This function returns the last (highest) key currently in this sorted map.
NoSuchElementException
- if the map is emptypublic java.lang.Object put(long key, java.lang.Object value)
This function 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. A null
return may indicate that the map
previously associated null
with the specified key.
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified key
null
if there was no mapping for the keypublic java.lang.Object remove(long key)
This function removes the mapping for this key from this map if it was
present. A null
return may indicate that the map previously
associated null
with the specified key.
key
- the key to the mapping that is to be removed
null
if there was no mapping for the keypublic void clear()
This function removes all mappings from this map.
public java.util.Iterator values()
This function returns an iterator for the objects in this map. They will be returned in the (ascending) order of their keys.
Iterator
of the values (not keys) in this
map
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |