Documentation

CslibFrontier.DataStructure.Dictionary.DynamicMatching

Multi-Round Unit-Circle Dynamic Matching #

This file formalizes the multi-round consistent-hashing dynamic matching scheme of Tianxiao Li, Jingxun Liang, Huacheng Yu, and Renfei Zhou, Dynamic Dictionary with Subconstant Wasted Bits per Key ([LiLiangYuZhou2024, Section 3.1, Problem 3.1, Algorithm 1, Lemma 3.2, and Claims 3.3–3.4]; arXiv:2310.20536v1, PDF pp. 6–9 / printed pp. 5–8), building on consistent hashing on the unit circle ([KLL+97]) and memoryless worker-task assignment ([BKP+22]).

Given a key-ID (ball) universe Fin U' and a slot (bin) universe Fin n' (n' ≤ U'), a matching scheme h : Scheme U' n' consists of U' permutations on Fin (U' + n') (matching the independent Fisher–Yates permutations sampled at initialization on the Word RAM). In round i, all remaining balls A_i ⊆ Fin U' and bins B_i ⊆ Fin n' are placed on the discrete circle Fin (U' + n') via h i; each ball a ∈ A_i whose clockwise-next occupied circle position belongs to a bin b ∈ B_i is matched to b, and both a and b are removed before round i + 1.

Because h is fixed in advance, the resulting assignment matching h A (for B = Finset.univ of all n' slots, or more generally matchOptOn h A B for any B with A.card ≤ B.card) depends solely on h and the current active set A. For any fixed h with T := rounds h A, when active cardinality stays ≤ n', a single insertion or deletion changes at most 2 * (T + 1) ball assignments ([LiLiangYuZhou2024, Claim 3.4]), and an atomic replacement insert y (A.erase x) changes at most 4 * T + 6 assignments ([LiLiangYuZhou2024, Section 5.2 via Claim 3.4]). Under uniform independent permutations (schemePMF), the expected round count is at most ⌈log₂ |A|⌉ + 2 = O(log (max |A| 2)) ([LiLiangYuZhou2024, Claim 3.3]), giving expected O(log (max |A| 2)) single-update relocation cost ([LiLiangYuZhou2024, Lemma 3.2]).

Scope note #

This module supplies the pure mathematical dynamic-matching primitive for the large-parameter-regime dynamic dictionary of [LiLiangYuZhou2024, Section 5]. Word-RAM Fisher–Yates permutation sampling, precomputed lookup-table evaluation, variable-length B-way word/bit adapters (Section 3.3), adapter trees (Section 4), strong history independence, dynamic resizing, and super-polynomial key universes are not formalized here.

Main definitions #

Main results #

References #

@[reducible, inline]

Single-round permutation on the combined universe Fin (U' + n') of U' balls and n' bins.

@[reducible, inline]

Predetermined U'-round dynamic matching scheme (Algorithm 1, line 1).

Uniform distribution over U' independent permutations on Fin (U' + n').

Test whether a combined item z : Fin (U' + n') is a bin binItem U' b.

Clockwise successor on a finite circle subset #

Permuted item circle and single-round matching #

def Cslib.DataStructure.Dictionary.DynamicMatching.roundMatchOpt {U' n' : ℕ} (π : RoundPerm U' n') (A : Finset (Fin U')) (B : Finset (Fin n')) (a : Fin U') :
Option (Fin n')

Single-round match attempt (Algorithm 1, lines 7–9): ball a matches to bin b iff a ∈ A and the clockwise-next active item in activeItems A B under π is binItem U' b.

Single-round state update (Algorithm 1, lines 5–10): remove matched balls from A and matched bins from B.

theorem Cslib.DataStructure.Dictionary.DynamicMatching.card_balls_roundStep_lt {U' n' : ℕ} (π : RoundPerm U' n') {A : Finset (Fin U')} {B : Finset (Fin n')} (hA : A.Nonempty) (hB : B.Nonempty) :
(roundStep π (A, B)).1.card < A.card

Every round with A.Nonempty and B.Nonempty matches at least one ball (Algorithm 1 termination property, [LiLiangYuZhou2024, Section 3.1]).

Multi-round execution, canonical injection, and round count #

def Cslib.DataStructure.Dictionary.DynamicMatching.stateAt {U' n' : ℕ} (h : Scheme U' n') (A : Finset (Fin U')) (B : Finset (Fin n')) :
ℕ → Finset (Fin U') × Finset (Fin n')

Remaining (A_i, B_i) state just before round i (0-indexed) when running Algorithm 1 on (A, B) under scheme h.

def Cslib.DataStructure.Dictionary.DynamicMatching.matchOptOn {U' n' : ℕ} (h : Scheme U' n') (A : Finset (Fin U')) (B : Finset (Fin n')) :
Fin U' → Option (Fin n')

Partial matching σ_{A, B} : Fin U' → Option (Fin n') after all U' rounds of Algorithm 1 on (A, B).

def Cslib.DataStructure.Dictionary.DynamicMatching.matchOpt {U' n' : ℕ} (h : Scheme U' n') (A : Finset (Fin U')) :
Fin U' → Option (Fin n')

Partial matching σ_A : Fin U' → Option (Fin n') against all n' slots (B = Finset.univ).

Number of active rounds T executed by Algorithm 1 on (A, B).

Number of active rounds T executed by Algorithm 1 on (A, Finset.univ).

Ball-relocation distance Δ(σ, σ') = #{a : Fin U' | σ a ≠ σ' a} (Problem 3.1, [LiLiangYuZhou2024, Section 3.1]).

theorem Cslib.DataStructure.Dictionary.DynamicMatching.relocDist_triangle {U' n' : ℕ} (σ₁ σ₂ σ₃ : Fin U' → Option (Fin n')) :
relocDist σ₁ σ₃ ≤ relocDist σ₁ σ₂ + relocDist σ₂ σ₃
theorem Cslib.DataStructure.Dictionary.DynamicMatching.stateAt_balls_eq_empty {U' n' : ℕ} (h : Scheme U' n') {A : Finset (Fin U')} {B : Finset (Fin n')} (hle : A.card ≤ B.card) {i : ℕ} (hi : A.card ≤ i) :
(stateAt h A B i).1 = ∅

Algorithm 1 matches all balls within A.card rounds whenever A.card ≤ B.card.

theorem Cslib.DataStructure.Dictionary.DynamicMatching.roundsOn_le_card {U' n' : ℕ} (h : Scheme U' n') {A : Finset (Fin U')} {B : Finset (Fin n')} (hle : A.card ≤ B.card) :
roundsOn h A B ≤ A.card
theorem Cslib.DataStructure.Dictionary.DynamicMatching.matchOptOn_isSome_iff {U' n' : ℕ} (h : Scheme U' n') {A : Finset (Fin U')} {B : Finset (Fin n')} (hle : A.card ≤ B.card) (a : Fin U') :
(matchOptOn h A B a).isSome = true ↔ a ∈ A
theorem Cslib.DataStructure.Dictionary.DynamicMatching.matchOptOn_injective {U' n' : ℕ} (h : Scheme U' n') (A : Finset (Fin U')) (B : Finset (Fin n')) {a₁ a₂ : Fin U'} {b : Fin n'} (h₁ : matchOptOn h A B a₁ = some b) (h₂ : matchOptOn h A B a₂ = some b) :
a₁ = a₂
theorem Cslib.DataStructure.Dictionary.DynamicMatching.matchOpt_isSome_iff {U' n' : ℕ} (h : Scheme U' n') {A : Finset (Fin U')} (hA : A.card ≤ n') (a : Fin U') :
(matchOpt h A a).isSome = true ↔ a ∈ A
theorem Cslib.DataStructure.Dictionary.DynamicMatching.matchOpt_injective {U' n' : ℕ} (h : Scheme U' n') (A : Finset (Fin U')) {a₁ a₂ : Fin U'} {b : Fin n'} (h₁ : matchOpt h A a₁ = some b) (h₂ : matchOpt h A a₂ = some b) :
a₁ = a₂
def Cslib.DataStructure.Dictionary.DynamicMatching.matching {U' n' : ℕ} (h : Scheme U' n') (A : Finset (Fin U')) (hA : A.card ≤ n') :
↥A ↪ Fin n'

Canonical history-independent dynamic matching σ_A : A ↪ Fin n' (Problem 3.1, Algorithm 1) for any active ball set A ⊆ Fin U' of size A.card ≤ n'.

@[simp]
theorem Cslib.DataStructure.Dictionary.DynamicMatching.matching_apply {U' n' : ℕ} (h : Scheme U' n') (A : Finset (Fin U')) (hA : A.card ≤ n') (a : ↥A) :
matchOpt h A ↑a = some ((matching h A hA) a)

Expected round bound (Claim 3.3) #

theorem Cslib.DataStructure.Dictionary.DynamicMatching.expect_roundsOn_le {U' n' : ℕ} {A : Finset (Fin U')} {B : Finset (Fin n')} (hle : A.card ≤ B.card) :
∑ h : Scheme U' n', ((schemePMF U' n') h).toReal * ↑(roundsOn h A B) ≤ ↑(Nat.clog 2 A.card) + 2

Claim 3.3 ([LiLiangYuZhou2024, Section 3.1]): for any A ⊆ Fin U' and B ⊆ Fin n' with A.card ≤ B.card, the expected number of rounds T = roundsOn h A B under uniform independent permutations is at most ⌈log₂ |A|⌉ + 2.

theorem Cslib.DataStructure.Dictionary.DynamicMatching.expect_rounds_le {U' n' : ℕ} {A : Finset (Fin U')} (hA : A.card ≤ n') :
∑ h : Scheme U' n', ((schemePMF U' n') h).toReal * ↑(rounds h A) ≤ 3 * ↑(Nat.clog 2 (max A.card 2))

Specialization of Claim 3.3 to all n' slots (B = Finset.univ): for A.card ≤ n', 𝔼[rounds h A] ≤ ⌈log₂ |A|⌉ + 2 ≤ 3 * ⌈log₂ (max |A| 2)⌉.

Single-operation relocation bounds (Claim 3.4 and Lemma 3.2) #

theorem Cslib.DataStructure.Dictionary.DynamicMatching.relocDist_insert_le {U' n' : ℕ} (h : Scheme U' n') {A : Finset (Fin U')} (x : Fin U') (hins : (insert x A).card ≤ n') :
relocDist (matchOpt h A) (matchOpt h (insert x A)) ≤ 2 * (rounds h A + 1)

Single-key insertion relocation bound (Claim 3.4, B = Finset.univ).

theorem Cslib.DataStructure.Dictionary.DynamicMatching.relocDist_delete_le {U' n' : ℕ} (h : Scheme U' n') {A : Finset (Fin U')} (x : Fin U') (hA : A.card ≤ n') :
relocDist (matchOpt h A) (matchOpt h (A.erase x)) ≤ 2 * (rounds h A + 1)

Single-key deletion relocation bound (Claim 3.4, B = Finset.univ).

theorem Cslib.DataStructure.Dictionary.DynamicMatching.relocDist_replace_le {U' n' : ℕ} (h : Scheme U' n') {A : Finset (Fin U')} (x y : Fin U') (hA : A.card ≤ n') (hrep : (insert y (A.erase x)).card ≤ n') :
relocDist (matchOpt h A) (matchOpt h (insert y (A.erase x))) ≤ 4 * rounds h A + 6

Atomic key-replacement relocation bound (Section 5.2 leaf minimap replacement (A \ {x}) ∪ {y} at fixed capacity A.card ≤ n'): decomposes through A.erase x without ever exceeding n' active balls.

theorem Cslib.DataStructure.Dictionary.DynamicMatching.expect_le_of_le_add_mul_rounds {U' n' : ℕ} {A : Finset (Fin U')} (hA : A.card ≤ n') (cost : Scheme U' n' → ℕ) (a b : ℕ) (hcost : ∀ (h : Scheme U' n'), cost h ≤ a + b * rounds h A) :
∑ h : Scheme U' n', ((schemePMF U' n') h).toReal * ↑(cost h) ≤ ↑(a + 3 * b) * ↑(Nat.clog 2 (max A.card 2))

A scheme-indexed cost bounded by a + b * rounds h A for every scheme h has expectation at most (a + 3 b) * ⌈log₂ (max |A| 2)⌉: average the pointwise bound and apply expect_rounds_le.

theorem Cslib.DataStructure.Dictionary.DynamicMatching.expect_relocDist_insert_le {U' n' : ℕ} {A : Finset (Fin U')} (x : Fin U') (hins : (insert x A).card ≤ n') :
∑ h : Scheme U' n', ((schemePMF U' n') h).toReal * ↑(relocDist (matchOpt h A) (matchOpt h (insert x A))) ≤ 8 * ↑(Nat.clog 2 (max A.card 2))

Lemma 3.2 ([LiLiangYuZhou2024, Section 3.1]) for ball insertion: expected relocation cost is O(log (max |A| 2)).

theorem Cslib.DataStructure.Dictionary.DynamicMatching.expect_relocDist_delete_le {U' n' : ℕ} {A : Finset (Fin U')} (x : Fin U') (hA : A.card ≤ n') :
∑ h : Scheme U' n', ((schemePMF U' n') h).toReal * ↑(relocDist (matchOpt h A) (matchOpt h (A.erase x))) ≤ 8 * ↑(Nat.clog 2 (max A.card 2))

Lemma 3.2 for ball deletion: expected relocation cost is O(log (max |A| 2)).

theorem Cslib.DataStructure.Dictionary.DynamicMatching.expect_relocDist_replace_le {U' n' : ℕ} {A : Finset (Fin U')} (x y : Fin U') (hA : A.card ≤ n') (hrep : (insert y (A.erase x)).card ≤ n') :
∑ h : Scheme U' n', ((schemePMF U' n') h).toReal * ↑(relocDist (matchOpt h A) (matchOpt h (insert y (A.erase x)))) ≤ 18 * ↑(Nat.clog 2 (max A.card 2))

Lemma 3.2 for atomic ball replacement (A.erase x) ∪ {y}: expected relocation cost is O(log (max |A| 2)).