ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
use super::{EqJoin, HashJoin, Join};

/// A root that hashes and one that does not, sharing a shape — the two rows of the mechanism table
/// made comparable rather than two unrelated fixtures.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct Hashable(&'static str);

/// A root whose one member is a FLOAT, so [`Hash`](core::hash::Hash) is unavailable to it and
/// [`EqJoin`] is the only mechanism it can fuse through.
#[derive(Debug, Clone, PartialEq)]
struct Unhashable(f64);

/// **The contract the fold depends on**: dense indices from zero, in admission order, and the same
/// index every time a root comes back.
#[test]
fn both_mechanisms_number_the_roots_densely_from_zero() {
  fn walk<R: Clone, J: Join<R>>(roots: &[R]) -> Vec<Option<usize>> {
    let mut join = J::empty();
    roots.iter().map(|root| join.place(root)).collect()
  }

  let roots = [
    Hashable("m1"),
    Hashable("m2"),
    Hashable("m1"),
    Hashable("m3"),
    Hashable("m2"),
    Hashable("m1"),
  ];

  // `None` at each first sighting — the fold pushes there — and the admitted index every time after.
  let placed = vec![None, None, Some(0), None, Some(1), Some(0)];
  assert_eq!(walk::<_, HashJoin<_>>(&roots), placed);
  assert_eq!(walk::<_, EqJoin<_>>(&roots), placed);
}

/// The escape actually escapes: a root with no [`Hash`](core::hash::Hash) joins through the equality
/// mechanism, and the same call against [`HashJoin`] would not compile.
#[test]
fn the_equality_mechanism_takes_a_root_that_cannot_hash() {
  let mut join = EqJoin::empty();

  assert_eq!(join.place(&Unhashable(0.5)), None);
  assert_eq!(join.place(&Unhashable(0.25)), None);
  assert_eq!(join.place(&Unhashable(0.5)), Some(0));
  assert_eq!(join.place(&Unhashable(0.25)), Some(1));
}

/// A join starts EMPTY, which is what makes each fused query independent of the last: there is no
/// membership carried between calls, and v1 has no cursor for one to ride.
#[test]
fn a_join_starts_empty() {
  let mut hashed: HashJoin<Hashable> = Join::empty();
  let mut walked: EqJoin<Hashable> = Join::empty();

  assert_eq!(hashed.place(&Hashable("m1")), None);
  assert_eq!(walked.place(&Hashable("m1")), None);
}