public class IntIntBTreeMap
extends java.lang.Object
implements java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
NavigableMap
implementation for int keys and int values.
To get started, call create()
.
All values in the map are stored at leaf nodes, and all leaf nodes are at the same depth. This ensures that accesses
to the map via e.g. get
, put
and remove
all take log(n) time. In contrast to a balanced binary
tree (like that used by TreeMap
), each node may holds more than one key. This makes the datastructure
more cache-friendly: you can expect it to be around 50% faster than TreeMap
for workloads that do not fit in cache.
The map is sorted either according to the Comparable method of the key type, or via a user-supplied Comparator
.
This ordering should be consistent with equals
.
The implementation is unsynchronized, and there are no guarantees as to what will happen if you make use of iterator that was created before some operation that modified the map.
Entry
instances returned by this class are immutable and hence do not support the Entry#setValue(Object)
method.
Modifier and Type | Method and Description |
---|---|
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
ceilingEntry(int key)
Returns the entry with smallest key greater than or equal to
key , or null if no such entry exists |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
ceilingEntry(java.lang.Integer key) |
java.lang.Integer |
ceilingKey(int key)
Returns the key of the entry returned by
ceilingEntry(java.lang.Integer) , or null if no such entry exists |
java.lang.Integer |
ceilingKey(java.lang.Integer key) |
int |
ceilingKeyInt(int key)
Returns the key of the entry returned by
ceilingEntry(java.lang.Integer) , or the most negative int value if no such entry exists |
void |
clear() |
IntComparator |
comparator() |
boolean |
containsKey(int key)
Returns true iff an entry exists in the map with the supplied key.
|
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
static IntIntBTreeMap |
create()
Create as empty
BTreeMap that uses the natural order of the keys |
static IntIntBTreeMap |
create(java.util.Comparator<? super java.lang.Integer> comparator)
Create an empty
BTreeMap that uses a custom comparator on the keys. |
static IntIntBTreeMap |
create(IntComparator comparator)
Create an empty
BTreeMap that uses a custom comparator on the keys. |
static IntIntBTreeMap |
create(java.util.Map<? extends java.lang.Integer,? extends java.lang.Integer> that)
Create a new map that contains the same entries as the specified
Map , and uses the natural ordering on the keys |
static IntIntBTreeMap |
create(java.util.SortedMap<java.lang.Integer,? extends java.lang.Integer> that)
Create a new map that contains the same entries as the specified
SortedMap , and also shares a key ordering with it |
java.util.NavigableSet<java.lang.Integer> |
descendingKeySet() |
java.util.NavigableMap<java.lang.Integer,java.lang.Integer> |
descendingMap() |
java.util.Set<java.util.Map.Entry<java.lang.Integer,java.lang.Integer>> |
entrySet() |
boolean |
equals(java.lang.Object that) |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
firstEntry() |
java.lang.Integer |
firstKey() |
int |
firstKeyInt()
Returns the key of the entry that would be returned by
firstEntry() |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
floorEntry(int key)
Returns entry with largest key less than or equal to
key , or null if no such entry exists |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
floorEntry(java.lang.Integer key) |
java.lang.Integer |
floorKey(int key)
Returns the key of the entry returned by
floorEntry(java.lang.Integer) , or null if no such entry exists |
java.lang.Integer |
floorKey(java.lang.Integer key) |
int |
floorKeyInt(int key)
Returns the key of the entry returned by
floorEntry(java.lang.Integer) , or the most negative int value if no such entry exists |
java.lang.Integer |
get(int key)
Gets the value at the given key.
|
java.lang.Integer |
get(java.lang.Object key) |
int |
getInt(int key)
Gets the value at the given key.
|
int |
getInt(java.lang.Object key)
Gets the value at the given key.
|
java.lang.Integer |
getOrDefault(int key,
java.lang.Integer dflt)
Gets the value at the given key.
|
java.lang.Integer |
getOrDefault(java.lang.Object key,
java.lang.Integer dflt) |
int |
getOrDefaultInt(int key,
int dflt)
Gets the value at the given key.
|
int |
getOrDefaultInt(java.lang.Object key,
int dflt)
Gets the value at the given key.
|
int |
hashCode() |
java.util.SortedMap<java.lang.Integer,java.lang.Integer> |
headMap(java.lang.Integer toKey) |
java.util.NavigableMap<java.lang.Integer,java.lang.Integer> |
headMap(java.lang.Integer toKey,
boolean inclusive) |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
higherEntry(int key)
Returns the entry with smallest key strictly greater than
key , or null if no such entry exists |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
higherEntry(java.lang.Integer key) |
java.lang.Integer |
higherKey(int key)
Returns the key of the entry returned by
higherEntry(java.lang.Integer) , or null if no such entry exists |
java.lang.Integer |
higherKey(java.lang.Integer key) |
int |
higherKeyInt(int key)
Returns the key of the entry returned by
higherEntry(java.lang.Integer) , or the most negative int value if no such entry exists |
boolean |
isEmpty() |
java.util.NavigableSet<java.lang.Integer> |
keySet() |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
lastEntry() |
java.lang.Integer |
lastKey() |
int |
lastKeyInt()
Returns the key of the entry that would be returned by
lastEntry() |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
lowerEntry(int key)
Returns the entry with largest key strictly less than
key , or null if no such entry exists |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
lowerEntry(java.lang.Integer key) |
java.lang.Integer |
lowerKey(int key)
Returns the key of the entry returned by
lowerEntry(java.lang.Integer) , or null if no such entry exists |
java.lang.Integer |
lowerKey(java.lang.Integer key) |
int |
lowerKeyInt(int key)
Returns the key of the entry returned by
lowerEntry(java.lang.Integer) , or the most negative int value if no such entry exists |
java.util.NavigableSet<java.lang.Integer> |
navigableKeySet() |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
pollFirstEntry() |
java.util.Map.Entry<java.lang.Integer,java.lang.Integer> |
pollLastEntry() |
java.lang.Integer |
put(java.lang.Integer key,
java.lang.Integer value) |
java.lang.Integer |
put(int key,
int value)
Adds a new entry to the map, and returns the old value associated with this key.
|
void |
putAll(java.util.Map<? extends java.lang.Integer,? extends java.lang.Integer> that) |
int |
putInt(int key,
int value)
Adds a new entry to the map, and returns the old value associated with this key.
|
java.lang.Integer |
remove(int key)
Remove the entry with the specified key, returning the value of the removed entry.
|
java.lang.Integer |
remove(java.lang.Object key) |
int |
removeInt(int key)
Remove the entry with the specified key, returning the value of the removed entry.
|
int |
removeInt(java.lang.Object key)
Remove the entry with the specified key, returning the value of the removed entry.
|
int |
size() |
java.util.NavigableMap<java.lang.Integer,java.lang.Integer> |
subMap(java.lang.Integer fromKey,
boolean fromInclusive,
java.lang.Integer toKey,
boolean toInclusive) |
java.util.SortedMap<java.lang.Integer,java.lang.Integer> |
subMap(java.lang.Integer fromKey,
java.lang.Integer toKey) |
java.util.SortedMap<java.lang.Integer,java.lang.Integer> |
tailMap(java.lang.Integer fromKey) |
java.util.NavigableMap<java.lang.Integer,java.lang.Integer> |
tailMap(java.lang.Integer fromKey,
boolean inclusive) |
java.lang.String |
toString() |
java.util.Collection<java.lang.Integer> |
values() |
public static IntIntBTreeMap create()
BTreeMap
that uses the natural order of the keyspublic static IntIntBTreeMap create(java.util.Comparator<? super java.lang.Integer> comparator)
BTreeMap
that uses a custom comparator on the keys.comparator
- If null, the natural order of the keys will be usedpublic static IntIntBTreeMap create(IntComparator comparator)
BTreeMap
that uses a custom comparator on the keys.comparator
- If null, the natural order of the keys will be usedpublic static IntIntBTreeMap create(java.util.SortedMap<java.lang.Integer,? extends java.lang.Integer> that)
SortedMap
, and also shares a key ordering with itpublic static IntIntBTreeMap create(java.util.Map<? extends java.lang.Integer,? extends java.lang.Integer> that)
Map
, and uses the natural ordering on the keyspublic void clear()
clear
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
public IntComparator comparator()
comparator
in interface java.util.SortedMap<java.lang.Integer,java.lang.Integer>
public void putAll(java.util.Map<? extends java.lang.Integer,? extends java.lang.Integer> that)
putAll
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
public java.lang.Integer get(java.lang.Object key)
get
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
public int getInt(java.lang.Object key)
int
value.public java.lang.Integer get(int key)
public int getInt(int key)
int
value.public java.lang.Integer getOrDefault(java.lang.Object key, java.lang.Integer dflt)
getOrDefault
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
public java.lang.Integer getOrDefault(int key, java.lang.Integer dflt)
public int getOrDefaultInt(java.lang.Object key, int dflt)
int
value.public int getOrDefaultInt(int key, int dflt)
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
public boolean containsKey(int key)
public java.lang.Integer put(int key, int value)
public int putInt(int key, int value)
int
value.public java.lang.Integer put(java.lang.Integer key, java.lang.Integer value)
put
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
java.lang.NullPointerException
- if either the key or value are nullpublic int size()
size
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
public boolean isEmpty()
isEmpty
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object that)
equals
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
hashCode
in class java.lang.Object
public java.lang.Integer lowerKey(java.lang.Integer key)
lowerKey
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
java.lang.NullPointerException
- if the key is nullpublic int lowerKeyInt(int key)
lowerEntry(java.lang.Integer)
, or the most negative int
value if no such entry existspublic java.lang.Integer lowerKey(int key)
lowerEntry(java.lang.Integer)
, or null if no such entry existspublic java.lang.Integer higherKey(java.lang.Integer key)
higherKey
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
java.lang.NullPointerException
- if the key is nullpublic int higherKeyInt(int key)
higherEntry(java.lang.Integer)
, or the most negative int
value if no such entry existspublic java.lang.Integer higherKey(int key)
higherEntry(java.lang.Integer)
, or null if no such entry existspublic java.lang.Integer floorKey(java.lang.Integer key)
floorKey
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
java.lang.NullPointerException
- if the key is nullpublic int floorKeyInt(int key)
floorEntry(java.lang.Integer)
, or the most negative int
value if no such entry existspublic java.lang.Integer floorKey(int key)
floorEntry(java.lang.Integer)
, or null if no such entry existspublic java.lang.Integer ceilingKey(java.lang.Integer key)
ceilingKey
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
java.lang.NullPointerException
- if the key is nullpublic int ceilingKeyInt(int key)
ceilingEntry(java.lang.Integer)
, or the most negative int
value if no such entry existspublic java.lang.Integer ceilingKey(int key)
ceilingEntry(java.lang.Integer)
, or null if no such entry existspublic java.util.Map.Entry<java.lang.Integer,java.lang.Integer> lowerEntry(java.lang.Integer key)
lowerEntry
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
java.lang.NullPointerException
- if key is nullpublic java.util.Map.Entry<java.lang.Integer,java.lang.Integer> lowerEntry(int key)
key
, or null if no such entry existspublic java.util.Map.Entry<java.lang.Integer,java.lang.Integer> floorEntry(java.lang.Integer key)
floorEntry
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
java.lang.NullPointerException
- if key is nullpublic java.util.Map.Entry<java.lang.Integer,java.lang.Integer> floorEntry(int key)
key
, or null if no such entry existspublic java.util.Map.Entry<java.lang.Integer,java.lang.Integer> ceilingEntry(java.lang.Integer key)
ceilingEntry
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
java.lang.NullPointerException
- if key is nullpublic java.util.Map.Entry<java.lang.Integer,java.lang.Integer> ceilingEntry(int key)
key
, or null if no such entry existspublic java.util.Map.Entry<java.lang.Integer,java.lang.Integer> higherEntry(java.lang.Integer key)
higherEntry
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
java.lang.NullPointerException
- if key is nullpublic java.util.Map.Entry<java.lang.Integer,java.lang.Integer> higherEntry(int key)
key
, or null if no such entry existspublic java.util.Map.Entry<java.lang.Integer,java.lang.Integer> firstEntry()
firstEntry
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
public java.util.Map.Entry<java.lang.Integer,java.lang.Integer> lastEntry()
lastEntry
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
public java.util.Map.Entry<java.lang.Integer,java.lang.Integer> pollFirstEntry()
pollFirstEntry
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
public java.util.Map.Entry<java.lang.Integer,java.lang.Integer> pollLastEntry()
pollLastEntry
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
public java.util.NavigableMap<java.lang.Integer,java.lang.Integer> descendingMap()
descendingMap
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
public java.util.NavigableSet<java.lang.Integer> navigableKeySet()
navigableKeySet
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
public java.util.NavigableSet<java.lang.Integer> descendingKeySet()
descendingKeySet
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
public java.util.NavigableMap<java.lang.Integer,java.lang.Integer> subMap(java.lang.Integer fromKey, boolean fromInclusive, java.lang.Integer toKey, boolean toInclusive)
subMap
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
public java.util.NavigableMap<java.lang.Integer,java.lang.Integer> headMap(java.lang.Integer toKey, boolean inclusive)
headMap
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
public java.util.NavigableMap<java.lang.Integer,java.lang.Integer> tailMap(java.lang.Integer fromKey, boolean inclusive)
tailMap
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
public java.util.SortedMap<java.lang.Integer,java.lang.Integer> subMap(java.lang.Integer fromKey, java.lang.Integer toKey)
subMap
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
subMap
in interface java.util.SortedMap<java.lang.Integer,java.lang.Integer>
public java.util.SortedMap<java.lang.Integer,java.lang.Integer> headMap(java.lang.Integer toKey)
headMap
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
headMap
in interface java.util.SortedMap<java.lang.Integer,java.lang.Integer>
public java.util.SortedMap<java.lang.Integer,java.lang.Integer> tailMap(java.lang.Integer fromKey)
tailMap
in interface java.util.NavigableMap<java.lang.Integer,java.lang.Integer>
tailMap
in interface java.util.SortedMap<java.lang.Integer,java.lang.Integer>
public java.lang.Integer firstKey()
firstKey
in interface java.util.SortedMap<java.lang.Integer,java.lang.Integer>
public int firstKeyInt()
firstEntry()
java.util.NoSuchElementException
- if the map is emptypublic java.lang.Integer lastKey()
lastKey
in interface java.util.SortedMap<java.lang.Integer,java.lang.Integer>
public int lastKeyInt()
lastEntry()
java.util.NoSuchElementException
- if the map is emptypublic java.util.NavigableSet<java.lang.Integer> keySet()
keySet
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
keySet
in interface java.util.SortedMap<java.lang.Integer,java.lang.Integer>
public java.util.Collection<java.lang.Integer> values()
values
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
values
in interface java.util.SortedMap<java.lang.Integer,java.lang.Integer>
public java.util.Set<java.util.Map.Entry<java.lang.Integer,java.lang.Integer>> entrySet()
entrySet
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
entrySet
in interface java.util.SortedMap<java.lang.Integer,java.lang.Integer>
public int removeInt(java.lang.Object key)
int
value.public int removeInt(int key)
int
value.public java.lang.Integer remove(java.lang.Object key)
remove
in interface java.util.Map<java.lang.Integer,java.lang.Integer>
public java.lang.Integer remove(int key)