public class BTreeMap<K,V>
extends java.lang.Object
implements java.util.NavigableMap<K,V>
NavigableMap
implementation for Object keys and Object 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<K,V> |
ceilingEntry(K key) |
K |
ceilingKey(K key) |
void |
clear() |
java.util.Comparator<? super K> |
comparator() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
static <K extends java.lang.Comparable<? super K>,V> |
create()
Create as empty
BTreeMap that uses the natural order of the keys |
static <K,V> BTreeMap<K,V> |
create(java.util.Comparator<? super K> comparator)
Create an empty
BTreeMap that uses a custom comparator on the keys. |
static <K,V> BTreeMap<K,V> |
create(java.util.Map<? extends K,? extends V> that)
Create a new map that contains the same entries as the specified
Map , and uses the natural ordering on the keys |
static <K,V> BTreeMap<K,V> |
create(java.util.SortedMap<K,? extends V> 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<K> |
descendingKeySet() |
java.util.NavigableMap<K,V> |
descendingMap() |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
boolean |
equals(java.lang.Object that) |
java.util.Map.Entry<K,V> |
firstEntry() |
K |
firstKey() |
K |
firstKeyObject()
Returns the key of the entry that would be returned by
firstEntry() |
java.util.Map.Entry<K,V> |
floorEntry(K key) |
K |
floorKey(K key) |
V |
get(java.lang.Object key) |
V |
getOrDefault(java.lang.Object key,
V dflt) |
int |
hashCode() |
java.util.SortedMap<K,V> |
headMap(K toKey) |
java.util.NavigableMap<K,V> |
headMap(K toKey,
boolean inclusive) |
java.util.Map.Entry<K,V> |
higherEntry(K key) |
K |
higherKey(K key) |
boolean |
isEmpty() |
java.util.NavigableSet<K> |
keySet() |
java.util.Map.Entry<K,V> |
lastEntry() |
K |
lastKey() |
K |
lastKeyObject()
Returns the key of the entry that would be returned by
lastEntry() |
java.util.Map.Entry<K,V> |
lowerEntry(K key) |
K |
lowerKey(K key) |
java.util.NavigableSet<K> |
navigableKeySet() |
java.util.Map.Entry<K,V> |
pollFirstEntry() |
java.util.Map.Entry<K,V> |
pollLastEntry() |
V |
put(K key,
V value) |
void |
putAll(java.util.Map<? extends K,? extends V> that) |
V |
remove(java.lang.Object key) |
int |
size() |
java.util.NavigableMap<K,V> |
subMap(K fromKey,
boolean fromInclusive,
K toKey,
boolean toInclusive) |
java.util.SortedMap<K,V> |
subMap(K fromKey,
K toKey) |
java.util.SortedMap<K,V> |
tailMap(K fromKey) |
java.util.NavigableMap<K,V> |
tailMap(K fromKey,
boolean inclusive) |
java.lang.String |
toString() |
java.util.Collection<V> |
values() |
public static <K extends java.lang.Comparable<? super K>,V> BTreeMap<K,V> create()
BTreeMap
that uses the natural order of the keyspublic static <K,V> BTreeMap<K,V> create(java.util.Comparator<? super K> comparator)
BTreeMap
that uses a custom comparator on the keys.comparator
- If null, the natural order of the keys will be usedpublic static <K,V> BTreeMap<K,V> create(java.util.SortedMap<K,? extends V> that)
SortedMap
, and also shares a key ordering with itpublic static <K,V> BTreeMap<K,V> create(java.util.Map<? extends K,? extends V> that)
Map
, and uses the natural ordering on the keyspublic java.util.Comparator<? super K> comparator()
public boolean containsKey(java.lang.Object key)
public boolean containsValue(java.lang.Object value)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object that)
public int hashCode()
public java.util.NavigableSet<K> navigableKeySet()
public java.util.NavigableSet<K> descendingKeySet()
public java.util.NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
public K firstKeyObject()
firstEntry()
java.util.NoSuchElementException
- if the map is emptypublic K lastKeyObject()
lastEntry()
java.util.NoSuchElementException
- if the map is emptypublic java.util.NavigableSet<K> keySet()
public java.util.Collection<V> values()