K
- Type of keysV
- Type of valuespublic class BTreeMap<K,V>
extends java.lang.Object
implements java.util.NavigableMap<K,V>
NavigableMap
implementation.
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() |
static <K,V> BTreeMap<K,V> |
create(java.util.Comparator<K> comparator) |
static <K,V> BTreeMap<K,V> |
create(java.util.Map<? extends K,? extends V> that) |
static <K,V> BTreeMap<K,V> |
create(java.util.SortedMap<K,? extends V> that) |
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() |
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() |
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()
public static <K,V> BTreeMap<K,V> create(java.util.Comparator<K> comparator)
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)
public static <K,V> BTreeMap<K,V> create(java.util.Map<? extends K,? extends V> that)
public 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 java.util.NavigableSet<K> keySet()
public java.util.Collection<V> values()