Skip to content

Full API

boris-kap edited this page Jan 13, 2022 · 2 revisions

Oak supports similar to ConcurrentNavigableMap API, unusual API methods are discussed in the README

Data Update

// If the key exists, the old value is replaced
void put(K key, V value); 

// If the key doesn’t exist, associate it with the given value
boolean putIfAbsent(K key, V value); 

// Removes the mapping for the key, if it is present
void remove(K key); 

// Updates the value for the key, using the user-supplied computer function
boolean computeIfPresent(K key, Consumer<OakWBuffer> computer);

// If the key doesn’t exist, associate it with the given value, 
// otherwise update the value for the key
void putIfAbsentComputeIfPresent(K key, V value, Consumer<OakWBuffer> computer);

Data Retrieval

Oak iterators implement the standard Iterator interface. The follwoing functions are supported.

  • hasNext(): Returns true if the iteration has more elements.
  • next(): Returns the next element in the iteration.
  • remove(): Removes from the underlying collection the last element returned by this iterator. This method can be called only once per call to next(). If the entry was changed, between the call of the next() and remove(), it is deleted regardless.
// Returns deserialized copy of the value to which the key is mapped
V get(K key); 

// Iterates over the values contained in the map
CloseableIterator<V> valuesIterator(); 

// Iterates over the mappings contained in the map
CloseableIterator<Map.Entry<K, V>> entriesIterator(); 

// Iterates over the keys contained in the map
CloseableIterator<K> keysIterator(); 

Map Modification

// Returns a view of the portion of the map with keys range from fromKey to toKey
OakMap subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive);

// Returns a view of the portion of the map with keys less than toKey
OakMap headMap(K toKey, boolean inclusive); 

// Returns a view of the portion of the map with keys greater than toKey
OakMap tailMap(K fromKey, boolean inclusive); 

// Returns a reverse order view of the mappings contained in the map
OakMap descendingMap(); 

Retrieval Views

// get the mappings as OakRBuffers without costly deserialization
OakBufferView createBufferView(); 

// get the transformed mappings, using user-supplied transform function
OakTransformView 
createTransformView(Function<Map.Entry<ByteBuffer, ByteBuffer>, T> transformer);

Miscellaneous

public void close(); // Cleans off heap memory
public long memorySize(); // Returns current off heap memory usage in bytes
public int entries(); // Number of key-value pairs inside the map
K getMinKey(); // The minimal key in the map
K getMaxKey(); // The maximal key in the map
Clone this wiki locally