Package org.aksw.commons.index.core
Class StorageNodeDictionary<D1,C1,D2,C2,V,X extends StorageNodeMutable<D2,C2,V>>
java.lang.Object
org.aksw.commons.index.core.StorageNodeDictionary<D1,C1,D2,C2,V,X>
- All Implemented Interfaces:
StorageNode<D1,,C1, V> StorageNodeMutable<D1,C1, V>
public class StorageNodeDictionary<D1,C1,D2,C2,V,X extends StorageNodeMutable<D2,C2,V>>
extends Object
implements StorageNodeMutable<D1,C1,V>
A wrapper for a storage node that adds a dictionary for the components
Can be used to map e.g. Nodes to Integers or canonical instances
Maybe this fits better on a TupleAccessor?
The issue with storage nodes is that they are stateless. So if we wanted to wrap an exiting structure
with a dictionary we would end up with:
Dictionary<Alt3<...>, Map<Node, Integer>
Probably it would not be too bad because we could still easily get the nested map structure out
Actually, why shouldn't the storage node have a state?
StorageNode<int[], int, ?> intStorage;
TupleAccessor intAccessor;
TupleAccessor tripleAccessor = TupleAccessorTriple.INSTANCE
StorageNodeDictionary<Triple, Node, ?> tripleStorageWrapper =
StorageNodeDictionary.wrap(intStorage, nodeAccessor, (dict, c) -> dict.size(), intAccessor)
BiMap<Node, Integer> tripleStorageWrapper.getDictionary();
- Author:
- raven
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Xprotected TupleBridge<D1,C1> protected TupleBridge<D2,C2> -
Constructor Summary
ConstructorsConstructorDescriptionStorageNodeDictionary(X delegate, com.google.common.collect.BiMap<C1, C2> dictionary, TupleBridge<D1, C1> sourceTupleAccessor, TupleBridge<D2, C2> targetTupleAccessor) -
Method Summary
Modifier and TypeMethodDescriptionbooleanchooseSubStore(V store, int subStoreIdx) voidClear a store's content.List<? extends StorageNode<D1,C1, ?>> Each node in the storage expression may have 0 or more childrengetKeyComponentRaw(Object key, int idx) Obtain components from the internal representation of key that was used for indexing w.r.t.int[]The component indexes by which this node indexes May be empty but never nullFuture: Allow the storageNode to answer how efficiently it can answer the constraints in a given constraint list E.g.booleanprotected C2mapSourceToTarget(D1 sourceTuple) mapTargetToSource(D2 targetTuple) newStore()boolean<T> Stream<?>streamEntries(V store, T tupleLike, TupleAccessor<? super T, ? extends C1> tupleAccessor) Stream all entries under equality constraints obtained from a tuple-like patternstreamerForKeyAndSubStoreAlts(T pattern, TupleAccessor<? super T, ? extends C1> accessor) The streamer returns entry that hold a tuple-like key and conceptually alternatives of sub-stores The tuple components of the key can be accessed usingStorageNode.getKeyComponentRaw(Object, int)There are as many components as the length ofStorageNode.getKeyTupleIdxs()If there is 0 components then any invocation ofStorageNode.getKeyComponentRaw(Object, int)will fail with aUnsupportedOperationException.streamerForKeys(T pattern, TupleAccessor<? super T, ? extends C1> accessor) streamerForKeysAsComponent(T pattern, TupleAccessor<? super T, ? extends C1> accessor) Compiles from a given pattern a function that can stream the matching keys from the appropriate store.streamerForKeysAsTuples(T pattern, TupleAccessor<? super T, ? extends C1> accessor) Compiles from a given pattern a function that can stream the matching keys from the appropriate store.streamerForValues(T pattern, TupleAccessor<? super T, ? extends C1> accessor) Returns an object that can extract the stream of values at an index node under constraints map: { entry.value | entry in map and entry.key matches condition} leafSet: set.entries.stream() A leaf set does not have any keys that could affect the result streamMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.aksw.commons.index.core.StorageNode
chooseSubStoreRaw, getPublicDelegate, getStoreAsList, getStoreAsMap, getStoreAsSet, holdsDomainTuples, isAltNode, isDelegate, isListNode, isMapNode, isSetNode, streamEntries, streamEntriesRaw, streamEntriesRawMethods inherited from interface org.aksw.commons.index.core.StorageNodeMutable
addRaw, clearRaw, isEmptyRaw, removeRaw
-
Field Details
-
delegate
-
dictionary
-
sourceTupleAccessor
-
targetTupleAccessor
-
-
Constructor Details
-
StorageNodeDictionary
public StorageNodeDictionary(X delegate, com.google.common.collect.BiMap<C1, C2> dictionary, TupleBridge<D1, C1> sourceTupleAccessor, TupleBridge<D2, C2> targetTupleAccessor)
-
-
Method Details
-
makeEntry
-
mapSourceToTarget
-
mapTargetToSource
-
add
- Specified by:
addin interfaceStorageNodeMutable<D1,C1, D2>
-
remove
- Specified by:
removein interfaceStorageNodeMutable<D1,C1, D2>
-
clear
Description copied from interface:StorageNodeMutableClear a store's content. Cascades to any sub-stores.- Specified by:
clearin interfaceStorageNodeMutable<D1,C1, D2>
-
newStore
- Specified by:
newStorein interfaceStorageNodeMutable<D1,C1, D2>
-
isEmpty
- Specified by:
isEmptyin interfaceStorageNodeMutable<D1,C1, D2>
-
getChildren
Description copied from interface:StorageNodeEach node in the storage expression may have 0 or more children- Specified by:
getChildrenin interfaceStorageNode<D1,C1, D2> - Returns:
-
getKeyTupleIdxs
public int[] getKeyTupleIdxs()Description copied from interface:StorageNodeThe component indexes by which this node indexes May be empty but never null- Specified by:
getKeyTupleIdxsin interfaceStorageNode<D1,C1, D2> - Returns:
-
getTupleAccessor
Description copied from interface:StorageNodeFuture: Allow the storageNode to answer how efficiently it can answer the constraints in a given constraint list E.g. O(1) or O(log(n)) or O(n)- Specified by:
getTupleAccessorin interfaceStorageNode<D1,C1, D2> - Returns:
-
streamerForKeysAsComponent
public <T> Streamer<V,C1> streamerForKeysAsComponent(T pattern, TupleAccessor<? super T, ? extends C1> accessor) Description copied from interface:StorageNodeCompiles from a given pattern a function that can stream the matching keys from the appropriate store. The keys must be instances of the component type otherwise an exception is raised- Specified by:
streamerForKeysAsComponentin interfaceStorageNode<D1,C1, D2> - Returns:
-
streamerForKeysAsTuples
public <T> Streamer<V,List<C1>> streamerForKeysAsTuples(T pattern, TupleAccessor<? super T, ? extends C1> accessor) Description copied from interface:StorageNodeCompiles from a given pattern a function that can stream the matching keys from the appropriate store. The keys must be instances of the component type otherwise an exception is raised if getKeyTupleIdxs().length == 0 then returns a single tuple that projects no components- Specified by:
streamerForKeysAsTuplesin interfaceStorageNode<D1,C1, D2> - Returns:
-
streamerForKeys
- Specified by:
streamerForKeysin interfaceStorageNode<D1,C1, D2>
-
getKeyComponentRaw
Description copied from interface:StorageNodeObtain components from the internal representation of key that was used for indexing w.r.t.StorageNode.getKeyTupleIdxs().- Specified by:
getKeyComponentRawin interfaceStorageNode<D1,C1, D2> idx- In the range 0 to {@link getKeyTupleIdxs().length} (exclusive) If a key has no components calling this method will always raiseIndexOutOfBoundsException- Returns:
-
chooseSubStore
- Specified by:
chooseSubStorein interfaceStorageNode<D1,C1, D2>
-
streamerForValues
public <T> Streamer<V,?> streamerForValues(T pattern, TupleAccessor<? super T, ? extends C1> accessor) Description copied from interface:StorageNodeReturns an object that can extract the stream of values at an index node under constraints map: { entry.value | entry in map and entry.key matches condition} leafSet: set.entries.stream() A leaf set does not have any keys that could affect the result stream- Specified by:
streamerForValuesin interfaceStorageNode<D1,C1, D2> - Returns:
-
streamerForKeyAndSubStoreAlts
public <T> Streamer<V,? extends Map.Entry<?, streamerForKeyAndSubStoreAlts?>> (T pattern, TupleAccessor<? super T, ? extends C1> accessor) Description copied from interface:StorageNodeThe streamer returns entry that hold a tuple-like key and conceptually alternatives of sub-stores The tuple components of the key can be accessed usingStorageNode.getKeyComponentRaw(Object, int)There are as many components as the length ofStorageNode.getKeyTupleIdxs()If there is 0 components then any invocation ofStorageNode.getKeyComponentRaw(Object, int)will fail with aUnsupportedOperationException. To extract a specific alternative from the substore useStorageNode.chooseSubStore(Object, int). IfStorageNode.getChildren()is not empty then there are as many substore indices as there are children If there are no children then there is an implicit single sub store with index 0- Specified by:
streamerForKeyAndSubStoreAltsin interfaceStorageNode<D1,C1, D2> - Returns:
-
streamEntries
public <T> Stream<?> streamEntries(V store, T tupleLike, TupleAccessor<? super T, ? extends C1> tupleAccessor) Description copied from interface:StorageNodeStream all entries under equality constraints obtained from a tuple-like pattern- Specified by:
streamEntriesin interfaceStorageNode<D1,C1, D2> - Returns:
-