Class ConcurrentFactIndexer<T extends Iterable<PositiveAtom>>
java.lang.Object
edu.harvard.seas.pl.abcdatalog.util.datastructures.ConcurrentFactIndexer<T>
- Type Parameters:
T
- the container type
- All Implemented Interfaces:
FactIndexer
,IndexableFactCollection
public class ConcurrentFactIndexer<T extends Iterable<PositiveAtom>>
extends Object
implements FactIndexer
An index that holds facts. The facts are indexed by predicate symbol and then by the constants in
each argument position. The indexer is parameterized by the type of the container that ultimately
holds the facts (i.e., all facts that belong to the same index are added to the same container).
In the presence of multiple threads, the indexer can momentarily be in an inconsistent state. However, after the add method returns having been invoked with a fact f, the indexer will be consistent with respect to f, meaning that f is properly indexed and that it is visible as such to all threads. (This only holds, of course, if the provided container type is thread safe.)
-
Constructor Summary
ConstructorDescriptionConcurrentFactIndexer
(Supplier<T> generator, BiConsumer<T, PositiveAtom> addFunc, Function<T, Integer> size) Creates a new fact indexer.ConcurrentFactIndexer
(Supplier<T> generator, BiConsumer<T, PositiveAtom> addFunc, Supplier<T> empty, Function<T, Integer> size) Creates a new fact indexer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(PositiveAtom fact) Adds a fact to this indexer.void
Add all the facts from an indexable fact collection to this index.void
addAll
(Iterable<PositiveAtom> facts) Adds the facts to the index.void
clear()
Clears this index.getCopy()
getPreds()
Returns the set of the predicate symbols represented in this collection.Returns the atoms in the collection that potentially "match" the provided atom.Returns the atoms in the collection that potentially "match" the provided atom, after the given substitution has been applied.indexInto
(PredicateSym pred) Returns the atoms in the collection with the given predicate symbol.boolean
isEmpty()
Returns whether the collection is empty.
-
Constructor Details
-
ConcurrentFactIndexer
public ConcurrentFactIndexer(Supplier<T> generator, BiConsumer<T, PositiveAtom> addFunc, Function<T, Integer> size) Creates a new fact indexer.- Parameters:
generator
- an anonymous function that returns a containeraddFunc
- an anonymous function that adds a fact to a containersize
- an anonymous function that gets the number of items in the container
-
ConcurrentFactIndexer
public ConcurrentFactIndexer(Supplier<T> generator, BiConsumer<T, PositiveAtom> addFunc, Supplier<T> empty, Function<T, Integer> size) Creates a new fact indexer.- Parameters:
generator
- an anonymous function that returns a containeraddFunc
- an anonymous function that adds a fact to a containerempty
- an anonymous function that returns an empty container (such as a static instance)size
- an anonymous function that gets the number of items in the container
-
-
Method Details
-
add
Adds a fact to this indexer.- Specified by:
add
in interfaceFactIndexer
- Parameters:
fact
- the fact
-
addAll
Adds the facts to the index.- Specified by:
addAll
in interfaceFactIndexer
- Parameters:
facts
- the facts
-
indexInto
Description copied from interface:IndexableFactCollection
Returns the atoms in the collection that potentially "match" the provided atom. There is no guarantee that the returned atoms can actually be unified with the provided atom.- Specified by:
indexInto
in interfaceIndexableFactCollection
- Parameters:
a
- the atom to match- Returns:
- the matching facts
-
indexInto
Description copied from interface:IndexableFactCollection
Returns the atoms in the collection that potentially "match" the provided atom, after the given substitution has been applied. There is no guarantee that the returned atoms can actually be unified with the provided atom.- Specified by:
indexInto
in interfaceIndexableFactCollection
- Parameters:
a
- the atom to match- Returns:
- the matching facts
-
indexInto
Description copied from interface:IndexableFactCollection
Returns the atoms in the collection with the given predicate symbol.- Specified by:
indexInto
in interfaceIndexableFactCollection
- Parameters:
pred
- the predicate symbol- Returns:
- the matching facts
-
clear
public void clear()Clears this index. -
isEmpty
public boolean isEmpty()Description copied from interface:IndexableFactCollection
Returns whether the collection is empty.- Specified by:
isEmpty
in interfaceIndexableFactCollection
- Returns:
- whether the collection is empty
-
getCopy
-
getPreds
Description copied from interface:IndexableFactCollection
Returns the set of the predicate symbols represented in this collection.- Specified by:
getPreds
in interfaceIndexableFactCollection
- Returns:
- the predicate symbols
-
addAll
Add all the facts from an indexable fact collection to this index.- Parameters:
that
- the indexable fact collection
-