Documentation

CslibFrontier.DataStructure.Rope.Join

Ropes: join #

Rope.join l r concatenates two ropes. When one side is more than one level taller, it descends the facing spine of the taller rope until the heights differ by at most one, makes a node there, and rebuilds the spine with Rope.balanceNode on the way back up. This is the AVL join of Blelloch, Ferizovic and Sun, Figure 2, without the middle key. The descents are the helpers Rope.joinRight and Rope.joinLeft, which are public only because the exposed join calls them. Join never merges, splits or copies a leaf, so the leaf chunks of the result are those of l followed by those of r.

For well-formed inputs the result is well-formed and its height is between max l.height r.height and one more. When one side is empty, the result is the other side.

Rope α has an Append instance given by join, so l ++ r is join l r.

Main definitions #

Main results #

References #

def Cslib.DataStructure.Rope.joinRight {α : Type u} (l r : Rope α) :
Rope α

Join when l is the taller side: descend the right spine of l while l is more than one level taller than r, then rebuild with balanceNode.

def Cslib.DataStructure.Rope.joinLeft {α : Type u} (l r : Rope α) :
Rope α

Join when r is the taller side: the mirror image of joinRight, descending the left spine of r.

def Cslib.DataStructure.Rope.join {α : Type u} :
Rope α → Rope α → Rope α

The concatenation of two ropes. An empty side is dropped. Otherwise the taller side's spine is descended until the heights differ by at most one.

@[instance_reducible]
@[simp]
theorem Cslib.DataStructure.Rope.append_eq_join {α : Type u} (l r : Rope α) :
l ++ r = l.join r
@[simp]

The leaf chunks and the list model #

@[simp]
theorem Cslib.DataStructure.Rope.chunks_join {α : Type u} (l r : Rope α) :

Join keeps the leaf chunks of its arguments, in order: it never merges, splits or copies a leaf.

@[simp]
theorem Cslib.DataStructure.Rope.toList_join {α : Type u} (l r : Rope α) :

Join represents the concatenation of its arguments, with no hypotheses.

Well-formedness and the height effect #

theorem Cslib.DataStructure.Rope.isWF_join {α : Type u} {B : ℕ} {l r : Rope α} (hl : IsWF B l) (hr : IsWF B r) :
IsWF B (l.join r)

Join of well-formed ropes is well-formed.

theorem Cslib.DataStructure.Rope.height_join {α : Type u} {B : ℕ} {l r : Rope α} (hl : IsWF B l) (hr : IsWF B r) :

The height of a join is between max l.height r.height and one more. When one side is empty, the result is the other side, so the lower bound is an equality.

theorem Cslib.DataStructure.Rope.length_join {α : Type u} {B : ℕ} {l r : Rope α} (hl : IsWF B l) (hr : IsWF B r) :

The length of a join is the sum of the lengths.