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

## Interface IIndexTable

- All Known Subinterfaces:
    `ITableWriterBinary.Table<Source,​Target>`, `ITableWriterGeneric.Table`, `ITableWriterUnary.Table<Value>`
  All Known Implementing Classes:
    `AbstractIndexTable`, `DefaultIndexTable`, `DisjointUnionTable`, `SimpleBinaryTable`, `SimpleUnaryTable`

      public interface IIndexTable

  Read-only interface that provides the `IInputKey`-specific slice of an instance store to realize a `IQueryRuntimeContext`. Implemented by a customizable data store that is responsible for:
  - storing the instance tuples of the `IInputKey`,
  - providing efficient lookup via storage-specific indexing,
  - delivering notifications. (TODO not designed yet)

  Can be specialized for unary / binary / etc., opposite edges or node subtypes, specific types, distributed storage, etc.

  Writeable API is specific to the customized implementations (e.g. unary).

  Precondition: the associated input key is enumerable, see `IQueryMetaContext.isEnumerable(IInputKey)`.

  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
  No Implement:
    This interface is not intended to be implemented directly. Extend `AbstractIndexTable` instead.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addUpdateListener​(Tuple seed, IQueryRuntimeContextListener listener)` | Subscribes for updates in the table, optionally seeded with the given tuple.
    `boolean` | `containsTuple​(ITuple seed)` | Simpler form of `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.
    `default java.lang.Iterable<Tuple>` | `enumerateTuples​(TupleMask seedMask, ITuple seed)` | Returns the tuples, optionally seeded with the given tuple.
    `default java.lang.Iterable<? extends java.lang.Object>` | `enumerateValues​(TupleMask seedMask, ITuple seed)` | Simpler form of `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.
    `IInputKey` | `getInputKey()` |
    `void` | `removeUpdateListener​(Tuple seed, IQueryRuntimeContextListener listener)` | Unsubscribes from updates in the table, optionally seeded with the given tuple.
    `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 `enumerateTuples(TupleMask, ITuple)` in the case where all values of the tuples are bound by the seed except for one.

- - ### Method Detail

    - #### getInputKey

          IInputKey getInputKey()

      Returns:
        the input key indexed by this table

    - #### enumerateTuples

          default java.lang.Iterable<Tuple> enumerateTuples​(TupleMask seedMask,
                                                            ITuple seed)

      Returns the tuples, optionally seeded with the given tuple.

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

      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

    - #### streamTuples

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

      Returns the tuples, optionally seeded with the given tuple.
      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
      Since:
        2.1

    - #### enumerateValues

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

      Simpler form of `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 `streamValues(TupleMask, ITuple)` instead.

      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

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

      Simpler form of `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.

      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
      Since:
        2.1

    - #### containsTuple

          boolean containsTuple​(ITuple seed)

      Simpler form of `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.

      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

    - #### countTuples

          int countTuples​(TupleMask seedMask,
                          ITuple seed)

      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.

      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

          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. 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.

      Since:
        2.1

    - #### addUpdateListener

          void addUpdateListener​(Tuple seed,
                                 IQueryRuntimeContextListener listener)

      Subscribes for updates in the table, optionally seeded with the given tuple.

      This should be called after initializing a result cache by an enumeration method.

      Parameters:
        `seed` - can be null or a tuple with matching arity; if non-null, notifications will delivered only about those updates of the table that match the seed at positions where the seed is non-null.
        `listener` - will be notified of future changes
      Since:
        2.1

    - #### removeUpdateListener

          void removeUpdateListener​(Tuple seed,
                                    IQueryRuntimeContextListener listener)

      Unsubscribes from updates in the table, optionally seeded with the given tuple.
      Parameters:
        `seed` - can be null or a tuple with matching arity; see `addUpdateListener(Tuple, IQueryRuntimeContextListener)` for definition.
        `listener` - will no longer be notified of future changes
      Since:
        2.1