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 Details

    • ConcurrentFactIndexer

      public ConcurrentFactIndexer(Supplier<T> generator, BiConsumer<T,PositiveAtom> addFunc)
      Creates a new fact indexer.
      Parameters:
      generator - an anonymous function that returns a container
      addFunc - an anonymous function that adds a fact to a container
    • ConcurrentFactIndexer

      public ConcurrentFactIndexer(Supplier<T> generator, BiConsumer<T,PositiveAtom> addFunc, Supplier<T> empty)
      Creates a new fact indexer.
      Parameters:
      generator - an anonymous function that returns a container
      addFunc - an anonymous function that adds a fact to a container
      empty - an anonymous function that returns an empty container (such as a static instance)
  • Method Details

    • add

      public void add(PositiveAtom fact)
      Adds a fact to this indexer.
      Specified by:
      add in interface FactIndexer
      Parameters:
      fact - the fact
    • addAll

      public void addAll(Iterable<PositiveAtom> facts)
      Adds the facts to the index.
      Specified by:
      addAll in interface FactIndexer
      Parameters:
      facts - the facts
    • indexInto

      public T indexInto(PositiveAtom a)
      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 interface IndexableFactCollection
      Parameters:
      a - the atom to match
      Returns:
      the matching facts
    • indexInto

      public T indexInto(PositiveAtom a, ConstOnlySubstitution s)
      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 interface IndexableFactCollection
      Parameters:
      a - the atom to match
      Returns:
      the matching facts
    • indexInto

      public T indexInto(PredicateSym pred)
      Description copied from interface: IndexableFactCollection
      Returns the atoms in the collection with the given predicate symbol.
      Specified by:
      indexInto in interface IndexableFactCollection
      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 interface IndexableFactCollection
      Returns:
      whether the collection is empty
    • getCopy

      public ConcurrentFactIndexer<T> getCopy()
    • getPreds

      public Set<PredicateSym> getPreds()
      Description copied from interface: IndexableFactCollection
      Returns the set of the predicate symbols represented in this collection.
      Specified by:
      getPreds in interface IndexableFactCollection
      Returns:
      the predicate symbols
    • addAll

      public void addAll(IndexableFactCollection that)
      Add all the facts from an indexable fact collection to this index.
      Parameters:
      that - the indexable fact collection