org.eclipse.viatra.query.runtime.matchers.scopes.tables

## Class SimpleBinaryTable<Source,Target>

- java.lang.Object
- - org.eclipse.viatra.query.runtime.matchers.scopes.tables.AbstractIndexTable
  - - org.eclipse.viatra.query.runtime.matchers.scopes.tables.SimpleBinaryTable<Source,Target>

- All Implemented Interfaces:
    IIndexTable, ITableWriterBinary<Source,Target>, ITableWriterBinary.Table<Source,Target>

      public class SimpleBinaryTable<Source,Target>
      extends AbstractIndexTable
      implements ITableWriterBinary.Table<Source,Target>

  Simple source-target bidirectional mapping.

  TODO: specialize for to-one features and unique to-many features

  TODO: on-demand construction of valueToHolderMap

  TODO: support for lean indexing, opposites, long surrogate ids, etc.

  EXPERIMENTAL. This class or interface has been added as part of a work in progress. There is no guarantee that this API will work or that it will remain the same.

  Since:
    2.0

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.eclipse.viatra.query.runtime.matchers.scopes.tables.AbstractIndexTable

      `AbstractIndexTable.ColumnBoundListeners, AbstractIndexTable.GenericBoundListeners, AbstractIndexTable.IListenersWithSameMask, AbstractIndexTable.UniversalListeners`

    - ### Nested classes/interfaces inherited from interface org.eclipse.viatra.query.runtime.matchers.scopes.tables.ITableWriterBinary

      `ITableWriterBinary.Nop<Source,Target>, ITableWriterBinary.Table<Source,Target>`

  - ### Field Summary

    - ### Fields inherited from class org.eclipse.viatra.query.runtime.matchers.scopes.tables.AbstractIndexTable

      `emitNotifications, emptyMask, emptyTuple, listenerGroups, tableContext`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleBinaryTable(IInputKey inputKey, ITableContext tableContext, boolean unique)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `containsRow(Source source, Target target)`
    `boolean` | `containsTuple(ITuple seed)` Simpler form of `IIndexTable.enumerateTuples(TupleMask, ITuple)` in the case where all values of the tuples are bound by the seed.
    `int` | `countTuples(TupleMask seedMask, ITuple seed)` Returns the number of tuples, optionally seeded with the given tuple.
    `java.lang.Iterable<? extends java.lang.Object>` | `enumerateValues(TupleMask seedMask, ITuple seed)` Simpler form of `IIndexTable.enumerateTuples(TupleMask, ITuple)` in the case where all values of the tuples are bound by the seed except for one.
    `java.util.Optional<java.lang.Long>` | `estimateProjectionSize(TupleMask groupMask, Accuracy requiredAccuracy)` Gives an estimate of the number of different groups the tuples of the table are projected into by the given mask (e.g.
    `java.lang.Iterable<Source>` | `getAllDistinctHolders()`
    `java.util.stream.Stream<Source>` | `getAllDistinctHoldersStream()`
    `java.lang.Iterable<Target>` | `getAllDistinctValues()`
    `java.util.stream.Stream<Target>` | `getAllDistinctValuesStream()`
    `java.util.Set<Source>` | `getDistinctHoldersOfValue(Target value)`
    `java.util.Set<Target>` | `getDistinctValuesOfHolder(Source holder)`
    `java.util.stream.Stream<? extends Tuple>` | `streamTuples(TupleMask seedMask, ITuple seed)` Returns the tuples, optionally seeded with the given tuple.
    `java.util.stream.Stream<? extends java.lang.Object>` | `streamValues(TupleMask seedMask, ITuple seed)` Simpler form of `IIndexTable.enumerateTuples(TupleMask, ITuple)` in the case where all values of the tuples are bound by the seed except for one.
    `void` | `write(Direction direction, Source holder, Target value)` Adds/removes a row to/from the table.

    - ### Methods inherited from class org.eclipse.viatra.query.runtime.matchers.scopes.tables.AbstractIndexTable

      `addUpdateListener, deliverChangeNotifications, getInputKey, getListenerGroup, logError, removeUpdateListener, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.viatra.query.runtime.matchers.scopes.tables.IIndexTable

      `addUpdateListener, enumerateTuples, getInputKey, removeUpdateListener`

- - ### Constructor Detail

    - #### SimpleBinaryTable

          public SimpleBinaryTable(IInputKey inputKey,
                                   ITableContext tableContext,
                                   boolean unique)

      Parameters:
        `unique` - client promises to only insert a given tuple with multiplicity one

  - ### Method Detail

    - #### write

          public void write(Direction direction,
                            Source holder,
                            Target value)

      Description copied from interface: `ITableWriterBinary`
      Adds/removes a row to/from the table.
      Specified by:
        `write` in interface `ITableWriterBinary<Source,Target>`
      Parameters:
        `direction` - tells whether putting a row into the table or deleting TODO: store as multiset, return bool?

    - #### countTuples

          public int countTuples(TupleMask seedMask,
                                 ITuple seed)

      Description copied from interface: `IIndexTable`
      Returns the number of tuples, optionally seeded with the given tuple.

      Selects the tuples in the table, optionally seeded with the given tuple, and then returns their number.

      Specified by:
        `countTuples` in interface `IIndexTable`
      Parameters:
        `seedMask` - a mask that extracts those parameters of the input key (from the entire parameter list) that should be bound to a fixed value; must not be null. Note: any given index must occur at most once in seedMask.
        `seed` - the tuple of fixed values restricting the row set to be considered, in the same order as given in parameterSeedMask, so that for each considered row tuple, projectedParameterSeed.equals(parameterSeedMask.transform(row)) should hold. Must not be null.
      Returns:
        the number of tuples in the table for the given key and seed

    - #### estimateProjectionSize

          public java.util.Optional<java.lang.Long> estimateProjectionSize(TupleMask groupMask,
                                                                           Accuracy requiredAccuracy)

      Description copied from interface: `IIndexTable`
      Gives an estimate of the number of different groups the tuples of the table are projected into by the given mask (e.g. for an identity mask, this means the full relation size). The estimate must meet the required accuracy.

      Derived tables may return `Optional.empty()` if it would be costly to provide an answer up to the required precision. Direct storage tables are expected to always be able to give an exact count.

      PRE: `TupleMask.isNonrepeating()` must hold for the group mask.

      Specified by:
        `estimateProjectionSize` in interface `IIndexTable`

    - #### streamTuples

          public java.util.stream.Stream<? extends Tuple> streamTuples(TupleMask seedMask,
                                                                       ITuple seed)

      Description copied from interface: `IIndexTable`
      Returns the tuples, optionally seeded with the given tuple.
      Specified by:
        `streamTuples` in interface `IIndexTable`
      Parameters:
        `seedMask` - a mask that extracts those parameters of the input key (from the entire parameter list) that should be bound to a fixed value; must not be null. Note: any given index must occur at most once in seedMask.
        `seed` - the tuple of fixed values restricting the row set to be considered, in the same order as given in parameterSeedMask, so that for each considered row tuple, projectedParameterSeed.equals(parameterSeedMask.transform(row)) should hold. Must not be null.
      Returns:
        the tuples in the table for the given key and seed

    - #### enumerateValues

          public java.lang.Iterable<? extends java.lang.Object> enumerateValues(TupleMask seedMask,
                                                                                ITuple seed)

      Description copied from interface: `IIndexTable`
      Simpler form of `IIndexTable.enumerateTuples(TupleMask, ITuple)` in the case where all values of the tuples are bound by the seed except for one.

      Selects the tuples in the table, optionally seeded with the given tuple, and then returns the single value from each tuple which is not bound by the seed mask.

      Consider using the more idiomatic `IIndexTable.streamValues(TupleMask, ITuple)` instead.

      Specified by:
        `enumerateValues` in interface `IIndexTable`
      Parameters:
        `seedMask` - a mask that extracts those parameters of the input key (from the entire parameter list) that should be bound to a fixed value; must not be null. Note: any given index must occur at most once in seedMask, and seedMask must include all parameters in any arbitrary order except one.
        `seed` - the tuple of fixed values restricting the row set to be considered, in the same order as given in parameterSeedMask, so that for each considered row tuple, projectedParameterSeed.equals(parameterSeedMask.transform(row)) should hold. Must not be null.
      Returns:
        the objects in the table for the given key and seed

    - #### streamValues

          public java.util.stream.Stream<? extends java.lang.Object> streamValues(TupleMask seedMask,
                                                                                  ITuple seed)

      Description copied from interface: `IIndexTable`
      Simpler form of `IIndexTable.enumerateTuples(TupleMask, ITuple)` in the case where all values of the tuples are bound by the seed except for one.

      Selects the tuples in the table, optionally seeded with the given tuple, and then returns the single value from each tuple which is not bound by the seed mask.

      Specified by:
        `streamValues` in interface `IIndexTable`
      Parameters:
        `seedMask` - a mask that extracts those parameters of the input key (from the entire parameter list) that should be bound to a fixed value; must not be null. Note: any given index must occur at most once in seedMask, and seedMask must include all parameters in any arbitrary order except one.
        `seed` - the tuple of fixed values restricting the row set to be considered, in the same order as given in parameterSeedMask, so that for each considered row tuple, projectedParameterSeed.equals(parameterSeedMask.transform(row)) should hold. Must not be null.
      Returns:
        the objects in the table for the given key and seed

    - #### containsTuple

          public boolean containsTuple(ITuple seed)

      Description copied from interface: `IIndexTable`
      Simpler form of `IIndexTable.enumerateTuples(TupleMask, ITuple)` in the case where all values of the tuples are bound by the seed.

      Returns whether the given tuple is in the table identified by the input key.

      Specified by:
        `containsTuple` in interface `IIndexTable`
      Parameters:
        `seed` - a row tuple of fixed values whose presence in the table is queried
      Returns:
        true iff there is a row tuple contained in the table that corresponds to the given seed

    - #### containsRow

          public boolean containsRow(Source source,
                                     Target target)

    - #### getAllDistinctHolders

          public java.lang.Iterable<Source> getAllDistinctHolders()

    - #### getAllDistinctHoldersStream

          public java.util.stream.Stream<Source> getAllDistinctHoldersStream()

    - #### getAllDistinctValues

          public java.lang.Iterable<Target> getAllDistinctValues()

    - #### getAllDistinctValuesStream

          public java.util.stream.Stream<Target> getAllDistinctValuesStream()

    - #### getDistinctHoldersOfValue

          public java.util.Set<Source> getDistinctHoldersOfValue(Target value)

    - #### getDistinctValuesOfHolder

          public java.util.Set<Target> getDistinctValuesOfHolder(Source holder)