Documentation

Std.Data.TreeSet.Raw.Basic

structure Std.TreeSet.Raw (α : Type u) (cmp : ααOrdering := by exact compare) :

Tree sets without a bundled well-formedness invariant, suitable for use in nested inductive types. The well-formedness invariant is called Raw.WF. When in doubt, prefer TreeSet over TreeSet.Raw. Lemmas about the operations on Std.TreeSet.Raw are available in the module Std.Data.TreeSet.Raw.Lemmas.

A tree set stores elements of a certain type in a certain order. It depends on a comparator function that defines an ordering on the keys and provides efficient order-dependent queries, such as retrieval of the minimum or maximum.

To ensure that the operations behave as expected, the comparator function cmp should satisfy certain laws that ensure a consistent ordering:

  • If a is less than (or equal) to b, then b is greater than (or equal) to a and vice versa (see the OrientedCmp typeclass).
  • If a is less than or equal to b and b is, in turn, less than or equal to c, then a is less than or equal to c (see the TransCmp typeclass).

Keys for which cmp a b = Ordering.eq are considered the same, i.e only one of them can be contained in a single tree set at the same time.

To avoid expensive copies, users should make sure that the tree set is used linearly.

Internally, the tree sets are represented as size-bounded trees, a type of self-balancing binary search tree with efficient order statistic lookups.

  • inner : TreeMap.Raw α Unit cmp

    Internal implementation detail of the tree set.

Instances For
structure Std.TreeSet.Raw.WF {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) :

Well-formedness predicate for tree sets. Users of TreeSet will not need to interact with this. Users of TreeSet.Raw will need to provide proofs of WF to lemmas and should use lemmas like WF.empty and WF.insert (which are always named exactly like the operations they are about) to show that set operations preserve well-formedness. The constructors of this type are internal implementation details and should not be accessed by users.

  • out : t.inner.WF

    Internal implementation detail of the tree map.

Instances For
instance Std.TreeSet.Raw.instCoeWFWFUnitInner {α : Type u} {cmp : ααOrdering} {t : Raw α cmp} :
Equations
@[inline]
def Std.TreeSet.Raw.empty {α : Type u} {cmp : ααOrdering} :
Raw α cmp

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
instance Std.TreeSet.Raw.instEmptyCollection {α : Type u} {cmp : ααOrdering} :
Equations
instance Std.TreeSet.Raw.instInhabited {α : Type u} {cmp : ααOrdering} :
Inhabited (Raw α cmp)
Equations
@[simp]
theorem Std.TreeSet.Raw.empty_eq_emptyc {α : Type u} {cmp : ααOrdering} :
@[inline]
def Std.TreeSet.Raw.insert {α : Type u} {cmp : ααOrdering} (l : Raw α cmp) (a : α) :
Raw α cmp

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
instance Std.TreeSet.Raw.instSingleton {α : Type u} {cmp : ααOrdering} :
Singleton α (Raw α cmp)
Equations
instance Std.TreeSet.Raw.instInsert {α : Type u} {cmp : ααOrdering} :
Insert α (Raw α cmp)
Equations
instance Std.TreeSet.Raw.instLawfulSingleton {α : Type u} {cmp : ααOrdering} :
LawfulSingleton α (Raw α cmp)
@[inline]
def Std.TreeSet.Raw.containsThenInsert {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (a : α) :
Bool × Raw α cmp

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.contains {α : Type u} {cmp : ααOrdering} (l : Raw α cmp) (a : α) :

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
instance Std.TreeSet.Raw.instMembership {α : Type u} {cmp : ααOrdering} :
Membership α (Raw α cmp)
Equations
instance Std.TreeSet.Raw.instDecidableMem {α : Type u} {cmp : ααOrdering} {t : Raw α cmp} {a : α} :
Equations
@[inline]
def Std.TreeSet.Raw.size {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) :

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.isEmpty {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) :

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.erase {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (a : α) :
Raw α cmp

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.get? {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (a : α) :

Checks if given key is contained and returns the key if it is, otherwise none. The result in the some case is guaranteed to be pointer equal to the key in the map.

Equations
@[inline]
def Std.TreeSet.Raw.get {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (a : α) (h : a t) :
α

Retrieves the key from the set that matches a. Ensures that such a key exists by requiring a proof of a ∈ m. The result is guaranteed to be pointer equal to the key in the set.

Equations
@[inline]
def Std.TreeSet.Raw.get! {α : Type u} {cmp : ααOrdering} [Inhabited α] (t : Raw α cmp) (a : α) :
α

Checks if given key is contained and returns the key if it is, otherwise panics. If no panic occurs the result is guaranteed to be pointer equal to the key in the set.

Equations
@[inline]
def Std.TreeSet.Raw.getD {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (a fallback : α) :
α

Checks if given key is contained and returns the key if it is, otherwise fallback. If they key is contained the result is guaranteed to be pointer equal to the key in the set.

Equations
@[inline]
def Std.TreeSet.Raw.min? {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) :

Tries to retrieve the smallest element of the tree set, returning none if the set is empty.

Equations

We do not provide min for the raw trees.

@[inline]
def Std.TreeSet.Raw.min! {α : Type u} {cmp : ααOrdering} [Inhabited α] (t : Raw α cmp) :
α

Tries to retrieve the smallest element of the tree set, panicking if the set is empty.

Equations
@[inline]
def Std.TreeSet.Raw.minD {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (fallback : α) :
α

Tries to retrieve the smallest element of the tree set, returning fallback if the tree set is empty.

Equations
@[inline]
def Std.TreeSet.Raw.max? {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) :

Tries to retrieve the largest element of the tree set, returning none if the set is empty.

Equations

We do not provide max for the raw trees.

@[inline]
def Std.TreeSet.Raw.max! {α : Type u} {cmp : ααOrdering} [Inhabited α] (t : Raw α cmp) :
α

Tries to retrieve the largest element of the tree set, panicking if the set is empty.

Equations
@[inline]
def Std.TreeSet.Raw.maxD {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (fallback : α) :
α

Tries to retrieve the largest element of the tree set, returning fallback if the tree set is empty.

Equations
@[inline]
def Std.TreeSet.Raw.atIdx? {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (n : Nat) :

Returns the n-th smallest element, or none if n is at least t.size.

Equations

We do not provide entryAtIdx for the raw trees.

@[inline]
def Std.TreeSet.Raw.atIdx! {α : Type u} {cmp : ααOrdering} [Inhabited α] (t : Raw α cmp) (n : Nat) :
α

Returns the n-th smallest element, or panics if n is at least t.size.

Equations
@[inline]
def Std.TreeSet.Raw.atIdxD {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (n : Nat) (fallback : α) :
α

Returns the n-th smallest element, or fallback if n is at least t.size.

Equations
@[inline]
def Std.TreeSet.Raw.getGE? {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (k : α) :

Tries to retrieve the smallest element that is greater than or equal to the given element, returning none if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.getGT? {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (k : α) :

Tries to retrieve the smallest element that is greater than the given element, returning none if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.getLE? {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (k : α) :

Tries to retrieve the largest element that is less than or equal to the given element, returning none if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.getLT? {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (k : α) :

Tries to retrieve the smallest element that is less than the given element, returning none if no such element exists.

Equations

We do not provide getGE, getGT, getLE, getLT for the raw trees.

@[inline]
def Std.TreeSet.Raw.getGE! {α : Type u} {cmp : ααOrdering} [Inhabited α] (t : Raw α cmp) (k : α) :
α

Tries to retrieve the smallest element that is greater than or equal to the given element, panicking if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.getGT! {α : Type u} {cmp : ααOrdering} [Inhabited α] (t : Raw α cmp) (k : α) :
α

Tries to retrieve the smallest element that is greater than the given element, panicking if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.getLE! {α : Type u} {cmp : ααOrdering} [Inhabited α] (t : Raw α cmp) (k : α) :
α

Tries to retrieve the largest element that is less than or equal to the given element, panicking if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.getLT! {α : Type u} {cmp : ααOrdering} [Inhabited α] (t : Raw α cmp) (k : α) :
α

Tries to retrieve the smallest element that is less than the given element, panicking if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.getGED {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (k fallback : α) :
α

Tries to retrieve the smallest element that is greater than or equal to the given element, returning fallback if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.getGTD {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (k fallback : α) :
α

Tries to retrieve the smallest element that is greater than the given element, returning fallback if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.getLED {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (k fallback : α) :
α

Tries to retrieve the largest element that is less than or equal to the given element, returning fallback if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.getLTD {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (k fallback : α) :
α

Tries to retrieve the smallest element that is less than the given element, returning fallback if no such element exists.

Equations
@[inline]
def Std.TreeSet.Raw.filter {α : Type u} {cmp : ααOrdering} (f : αBool) (t : Raw α cmp) :
Raw α cmp

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.foldlM {α : Type u} {cmp : ααOrdering} {δ : Type w} {m : Type w → Type w₂} [Monad m] (f : δαm δ) (init : δ) (t : Raw α cmp) :
m δ

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline, deprecated Std.TreeSet.Raw.foldlM (since := "2025-02-12")]
def Std.TreeSet.Raw.foldM {α : Type u} {cmp : ααOrdering} {δ : Type w} {m : Type w → Type w₂} [Monad m] (f : δαm δ) (init : δ) (t : Raw α cmp) :
m δ

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.foldl {α : Type u} {cmp : ααOrdering} {δ : Type w} (f : δαδ) (init : δ) (t : Raw α cmp) :
δ

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline, deprecated Std.TreeSet.Raw.foldl (since := "2025-02-12")]
def Std.TreeSet.Raw.fold {α : Type u} {cmp : ααOrdering} {δ : Type w} (f : δαδ) (init : δ) (t : Raw α cmp) :
δ

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.foldrM {α : Type u} {cmp : ααOrdering} {δ : Type w} {m : Type w → Type w₂} [Monad m] (f : αδm δ) (init : δ) (t : Raw α cmp) :
m δ

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.foldr {α : Type u} {cmp : ααOrdering} {δ : Type w} (f : αδδ) (init : δ) (t : Raw α cmp) :
δ

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline, deprecated Std.TreeSet.Raw.foldr (since := "2025-02-12")]
def Std.TreeSet.Raw.revFold {α : Type u} {cmp : ααOrdering} {δ : Type w} (f : δαδ) (init : δ) (t : Raw α cmp) :
δ

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.partition {α : Type u} {cmp : ααOrdering} (f : αBool) (t : Raw α cmp) :
Raw α cmp × Raw α cmp

Partitions a tree set into two tree sets based on a predicate.

Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Std.TreeSet.Raw.forM {α : Type u} {cmp : ααOrdering} {m : Type w → Type w₂} [Monad m] (f : αm PUnit) (t : Raw α cmp) :

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.forIn {α : Type u} {cmp : ααOrdering} {δ : Type w} {m : Type w → Type w₂} [Monad m] (f : αδm (ForInStep δ)) (init : δ) (t : Raw α cmp) :
m δ

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
instance Std.TreeSet.Raw.instForM {α : Type u} {cmp : ααOrdering} {m : Type w → Type w₂} :
ForM m (Raw α cmp) α
Equations
instance Std.TreeSet.Raw.instForIn {α : Type u} {cmp : ααOrdering} {t : Type w → Type w} :
ForIn t (Raw α cmp) α
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Std.TreeSet.Raw.any {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (p : αBool) :

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.all {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) (p : αBool) :

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.toList {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) :
List α

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.ofList {α : Type u} (l : List α) (cmp : ααOrdering := by exact compare) :
Raw α cmp

Transforms a list into a tree set.

Equations
@[inline, deprecated Std.TreeSet.Raw.ofList (since := "2025-02-12")]
def Std.TreeSet.Raw.fromList {α : Type u} (l : List α) (cmp : ααOrdering) :
Raw α cmp

Transforms a list into a tree set.

Equations
@[inline]
def Std.TreeSet.Raw.toArray {α : Type u} {cmp : ααOrdering} (t : Raw α cmp) :

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.ofArray {α : Type u} (a : Array α) (cmp : ααOrdering := by exact compare) :
Raw α cmp

Transforms an array into a tree set.

Equations
@[inline, deprecated Std.TreeSet.Raw.ofArray (since := "2025-02-12")]
def Std.TreeSet.Raw.fromArray {α : Type u} (a : Array α) (cmp : ααOrdering) :
Raw α cmp

Transforms an array into a tree set.

Equations
@[inline]
def Std.TreeSet.Raw.merge {α : Type u} {cmp : ααOrdering} (t₁ t₂ : Raw α cmp) :
Raw α cmp

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
@[inline]
def Std.TreeSet.Raw.insertMany {α : Type u} {cmp : ααOrdering} {ρ : Type u_1} [ForIn Id ρ α] (t : Raw α cmp) (l : ρ) :
Raw α cmp

Inserts multiple elements into the tree set by iterating over the given collection and calling insert. If the same element (with respect to cmp) appears multiple times, the first occurrence takes precedence.

Note: this precedence behavior is true for TreeSet and TreeSet.Raw. The insertMany function on TreeMap, DTreeMap, TreeMap.Raw and DTreeMap.Raw behaves differently: it will prefer the last appearance.

Equations
@[inline]
def Std.TreeSet.Raw.eraseMany {α : Type u} {cmp : ααOrdering} {ρ : Type u_1} [ForIn Id ρ α] (t : Raw α cmp) (l : ρ) :
Raw α cmp

Creates a new empty tree set. It is also possible and recommended to use the empty collection notations and {} to create an empty tree set. simp replaces empty with .

Equations
instance Std.TreeSet.Raw.instRepr {α : Type u} {cmp : ααOrdering} [Repr α] :
Repr (Raw α cmp)
Equations