K
- The type of the primary key.V
- The type of the values to be mapped.public class CorfuTable<K,V> extends Object implements ICorfuMap<K,V>
The primary interface to the CorfuTable is a Map, where the keys must be unique and each key is mapped to exactly one value. Null values are not permitted.
The CorfuTable also supports an unlimited number of secondary indexes, which the user provides at construction time as an enum which implements the IndexSpecification interface. An index specification consists of a IndexFunction, which returns a set of secondary keys (indexes) the value should be mapped to. Secondary indexes are many-to-many: values can be mapped to multiple indexes, and indexes can be mapped to multiples values. Each IndexSpecification also specifies a projection function, which specifies a transformation that can be done on a retrieval on the index. A common projection is to emit only the values.
Modifier and Type | Class and Description |
---|---|
static class |
CorfuTable.Index<K,V,I extends Comparable<?>>
Descriptor of named indexing function entry.
|
static interface |
CorfuTable.IndexFunction<K,V,I extends Comparable<?>>
Denotes a function that takes as input the key and value of an
CorfuTable
record, and computes the associated index value for the record. |
static interface |
CorfuTable.IndexName
Denotes a function that supplies the unique name of an index registered to
CorfuTable . |
static interface |
CorfuTable.IndexRegistry<K,V>
Registry hosting of a collection of
CorfuTable.Index . |
static interface |
CorfuTable.IndexSpecification<K,V,I extends Comparable<?>,P>
The interface for a index specification, which consists of a indexing function
and a projection function.
|
static interface |
CorfuTable.MultiValueIndexFunction<K,V,I extends Comparable<?>> |
static interface |
CorfuTable.ProjectionFunction<K,V,I,P>
The interface for a projection function.
|
Constructor and Description |
---|
CorfuTable()
Default constructor.
|
CorfuTable(CorfuTable.IndexRegistry<K,V> indices)
Generate a table with the given set of indexes.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
V |
computeIfAbsent(K key,
Function<? super K,? extends V> mappingFunction) |
V |
computeIfPresent(K key,
BiFunction<? super K,? super V,? extends V> remappingFunction) |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
void |
delete(K key)
Delete a key from a map.
|
Set<Map.Entry<K,V>> |
entrySet()
Makes a shallow copy of the map (i.e.
|
void |
forEach(BiConsumer<? super K,? super V> action) |
V |
get(Object key) |
<I extends Comparable<I>> |
getByIndex(CorfuTable.IndexName indexName,
I indexKey)
Get a mapping using the specified index function.
|
<I extends Comparable<I>> |
getByIndexAndFilter(CorfuTable.IndexName indexName,
Predicate<? super Map.Entry<K,V>> entryPredicate,
I indexKey)
Scan and filter using the specified index function and projection.
|
V |
getOrDefault(Object key,
V defaultValue) |
boolean |
hasSecondaryIndices()
Return whether this table has secondary indexes or not.
|
void |
insert(K key,
V value)
Insert a key-value pair into a map, overwriting any previous mapping.
|
boolean |
isEmpty() |
Set<K> |
keySet() |
protected void |
mapSecondaryIndexes(K key,
V value)
Maps the secondary indexes for a given key value pair.
|
V |
merge(K key,
V value,
BiFunction<? super V,? super V,? extends V> remappingFunction) |
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> m) |
V |
putIfAbsent(K key,
V value) |
V |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
V |
replace(K key,
V value) |
void |
replaceAll(BiFunction<? super K,? super V,? extends V> function) |
List<V> |
scanAndFilter(Predicate<? super V> p)
Returns a filtered
List view of the values contained in this map. |
Collection<Map.Entry<K,V>> |
scanAndFilterByEntry(Predicate<? super Map.Entry<K,V>> entryPredicate)
Returns a
Collection filtered by entries (keys and/or values). |
int |
size() |
protected void |
undoPut(CorfuTable<K,V> table,
V undoRecord,
K key,
V value) |
protected V |
undoPutRecord(CorfuTable<K,V> table,
K key,
V value) |
protected void |
undoRemove(CorfuTable<K,V> table,
V undoRecord,
K key) |
protected V |
undoRemoveRecord(CorfuTable<K,V> table,
K key) |
protected void |
unmapSecondaryIndexes(K key,
V value)
Unmaps the secondary indexes for a given key value pair.
|
Collection<V> |
values() |
public CorfuTable(CorfuTable.IndexRegistry<K,V> indices)
public CorfuTable()
public boolean hasSecondaryIndices()
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
@Nonnull public <I extends Comparable<I>> Collection<Map.Entry<K,V>> getByIndex(@Nonnull CorfuTable.IndexName indexName, I indexKey)
indexName
- Name of the the secondary index to query.indexKey
- The index key used to query the secondary index@Nonnull public <I extends Comparable<I>> Collection<Map.Entry<K,V>> getByIndexAndFilter(@Nonnull CorfuTable.IndexName indexName, @Nonnull Predicate<? super Map.Entry<K,V>> entryPredicate, I indexKey)
indexName
- Name of the the secondary index to query.entryPredicate
- The predicate to scan and filter with.indexKey
- A collection of Map.Entrypublic void insert(K key, V value)
public List<V> scanAndFilter(Predicate<? super V> p)
List
view of the values contained in this map.
This method has a memory/CPU advantage over the map iterators as no deep copy
is actually performed.p
- java predicate (function to evaluate)public Collection<Map.Entry<K,V>> scanAndFilterByEntry(Predicate<? super Map.Entry<K,V>> entryPredicate)
Collection
filtered by entries (keys and/or values).
This method has a memory/CPU advantage over the map iterators as no deep copy
is actually performed.scanAndFilterByEntry
in interface ICorfuMap<K,V>
entryPredicate
- java predicate (function to evaluate)protected V undoRemoveRecord(CorfuTable<K,V> table, K key)
protected void undoRemove(CorfuTable<K,V> table, V undoRecord, K key)
public void delete(K key)
@Nonnull public Set<Map.Entry<K,V>> entrySet()
public V getOrDefault(Object key, V defaultValue)
getOrDefault
in interface Map<K,V>
public void forEach(BiConsumer<? super K,? super V> action)
public void replaceAll(BiFunction<? super K,? super V,? extends V> function)
replaceAll
in interface Map<K,V>
public V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
computeIfAbsent
in interface Map<K,V>
public V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
computeIfPresent
in interface Map<K,V>
protected void unmapSecondaryIndexes(K key, V value)
key
- The primary key (index) for the mapping.value
- The value to unmap.Copyright © 2019 CorfuDB. All rights reserved.