Class ChildCardinality

java.lang.Object
io.bloviate.gen.ChildCardinality

public final class ChildCardinality extends Object
Deterministic mapping from a parent row's global (row-major) index to the number of child rows it owns, drawn from the inclusive range [minChildren, maxChildren].

This models variable parent-child cardinality — a child table whose per-parent row count differs from row to row (e.g. TPC-C orders with a random number of order lines, or TPC-H orders with a random number of line items). It is the shared source of truth that lets a parent table and its child table agree on counts even though they are filled independently: a "number of children" column on the parent (see ChildCountGenerator) returns count(k) for the k-th parent, and the child's key generators (see ChildKeyComponentGenerator) emit exactly that many rows for parent k. Because count(long) is a pure function of the parent index (a splitmix64 hash, no random state), every consumer computes identical values.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    ChildCardinality(int minChildren, int maxChildren, long seed)
    Creates a cardinality over the inclusive range [minChildren, maxChildren].
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    count(long parentIndex)
    Returns the deterministic child count for the parent at the given global index.
    int
    Returns the maximum children per parent (inclusive).
    int
    Returns the minimum children per parent (inclusive).
    long
    total(long parentCount)
    Returns the total number of child rows across the first parentCount parents, i.e.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ChildCardinality

      public ChildCardinality(int minChildren, int maxChildren, long seed)
      Creates a cardinality over the inclusive range [minChildren, maxChildren].
      Parameters:
      minChildren - minimum children per parent (inclusive), >= 0
      maxChildren - maximum children per parent (inclusive), >= minChildren
      seed - salt mixed into the hash, so different datasets can vary independently
  • Method Details

    • count

      public int count(long parentIndex)
      Returns the deterministic child count for the parent at the given global index.
      Parameters:
      parentIndex - the 0-based, row-major parent index
      Returns:
      a value in [minChildren, maxChildren]
    • total

      public long total(long parentCount)
      Returns the total number of child rows across the first parentCount parents, i.e. sum(count(k)) for k in [0, parentCount).

      When the count is fixed (minChildren == maxChildren) this is closed-form and O(1). Otherwise it is a single O(parentCount) pass with no intermediate storage, so memory stays constant even for very large datasets.

      Parameters:
      parentCount - the number of parents
      Returns:
      the total child-row count
    • minChildren

      public int minChildren()
      Returns the minimum children per parent (inclusive).
      Returns:
      the minimum child count
    • maxChildren

      public int maxChildren()
      Returns the maximum children per parent (inclusive).
      Returns:
      the maximum child count