Skip to content

Add monomorphized N-way zipper merge with frontier-based dispatch and specialization#35

Open
marcin-rzeznicki wants to merge 10 commits intomasterfrom
zipper_join_n
Open

Add monomorphized N-way zipper merge with frontier-based dispatch and specialization#35
marcin-rzeznicki wants to merge 10 commits intomasterfrom
zipper_join_n

Conversation

@marcin-rzeznicki
Copy link
Copy Markdown
Collaborator

This PR introduces a generic N-way merge algorithm, extending the existing 2-way and 3-way implementations to arbitrary arity (well, <= 64) while preserving performance characteristics via specialization and careful traversal design.

N-way zipper merge (zipper_merge_n_mono)

  • Fully monomorphized over const N and the zipper type (SomeMutRefZ)
  • Uses a bitmask (active) to track participating zippers
  • Stackless traversal using zipper movements and explicit depth tracking

Frontier-based traversal

  • At each step:
    • Compute minimal byte across active zippers
    • Build a frontier (subset sharing that byte)
    • Dispatch based on frontier size:
      • |frontier| = 1 → graft (no descent)
      • 1 < |frontier| < N → subset recursion / specialization
      • |frontier| = N → fast-path full descent (no recursion)

Specialized fast paths

  • Dispatch to optimized implementations for:
    • 2-way → zipper_merge
    • 3-way → zipper_merge3
    • 4-way → zipper_merge4
  • Larger frontiers recurse into the same function with a reduced mask

Introduce macro-based “variadic” frontends and tuple-driven helpers for composing multiple zippers in a single call.

  • New macros:
    • zipper_meet_n!
    • zipper_join_n!
    • zipper_subtract_n!
  • New helpers:
    • meet_n, join_n, subtract_n
Syntax

Tuple-based argument passing (&mut r1, &mut r2, ..., &rN).meet_n(&mut out) with macro-generated impls up to 64 (current limit: 32)

or

zipper_join_n!(r1, r2, r3, ... => w); instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant