Documentation

Std.Data.AssocList

inductive Std.AssocList (α : Type u) (β : Type v) :
Type (max u v)

AssocList α β is "the same as" List (α × β), but flattening the structure leads to one fewer pointer indirection (in the current code generator). It is mainly intended as a component of HashMap, but it can also be used as a plain key-value map.

Instances For
    instance Std.instInhabitedAssocList :
    {a : Type u_1} → {a_1 : Type u_2} → Inhabited (Std.AssocList a a_1)
    Equations
    • Std.instInhabitedAssocList = { default := Std.AssocList.nil }
    def Std.AssocList.toList {α : Type u_1} {β : Type u_2} :
    Std.AssocList α βList (α × β)

    O(n). Convert an AssocList α β into the equivalent List (α × β). This is used to give specifications for all the AssocList functions in terms of corresponding list functions.

    Equations
    Instances For
      Equations
      • Std.AssocList.instEmptyCollectionAssocList = { emptyCollection := Std.AssocList.nil }
      @[simp]
      theorem Std.AssocList.empty_eq {α : Type u_1} {β : Type u_2} :
      = Std.AssocList.nil
      def Std.AssocList.isEmpty {α : Type u_1} {β : Type u_2} :

      O(1). Is the list empty?

      Equations
      Instances For
        def Std.AssocList.length {α : Type u_1} {β : Type u_2} (L : Std.AssocList α β) :

        The number of entries in an AssocList.

        Equations
        Instances For
          @[simp]
          theorem Std.AssocList.length_nil {α : Type u_1} {β : Type u_2} :
          Std.AssocList.length Std.AssocList.nil = 0
          @[simp]
          theorem Std.AssocList.length_cons :
          ∀ {α : Type u_1} {a : α} {β : Type u_2} {b : β} {t : Std.AssocList α β}, Std.AssocList.length (Std.AssocList.cons a b t) = Std.AssocList.length t + 1
          @[specialize #[]]
          def Std.AssocList.foldlM {m : Type u_1 → Type u_2} {δ : Type u_1} {α : Type u_3} {β : Type u_4} [Monad m] (f : δαβm δ) (init : δ) :
          Std.AssocList α βm δ

          O(n). Fold a monadic function over the list, from head to tail.

          Equations
          Instances For
            @[simp]
            theorem Std.AssocList.foldlM_eq {m : Type u_1 → Type u_2} {δ : Type u_1} {α : Type u_3} {β : Type u_4} [Monad m] (f : δαβm δ) (init : δ) (l : Std.AssocList α β) :
            Std.AssocList.foldlM f init l = List.foldlM (fun (d : δ) (x : α × β) => match x with | (a, b) => f d a b) init (Std.AssocList.toList l)
            @[inline]
            def Std.AssocList.foldl {δ : Type u_1} {α : Type u_2} {β : Type u_3} (f : δαβδ) (init : δ) (as : Std.AssocList α β) :
            δ

            O(n). Fold a function over the list, from head to tail.

            Equations
            Instances For
              @[simp]
              theorem Std.AssocList.foldl_eq {δ : Type u_1} {α : Type u_2} {β : Type u_3} (f : δαβδ) (init : δ) (l : Std.AssocList α β) :
              Std.AssocList.foldl f init l = List.foldl (fun (d : δ) (x : α × β) => match x with | (a, b) => f d a b) init (Std.AssocList.toList l)
              def Std.AssocList.toListTR {α : Type u_1} {β : Type u_2} (as : Std.AssocList α β) :
              List (α × β)

              Optimized version of toList.

              Equations
              Instances For
                @[specialize #[]]
                def Std.AssocList.forM {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_4} [Monad m] (f : αβm PUnit) :
                Std.AssocList α βm PUnit

                O(n). Run monadic function f on all elements in the list, from head to tail.

                Equations
                Instances For
                  @[simp]
                  theorem Std.AssocList.forM_eq {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_4} [Monad m] (f : αβm PUnit) (l : Std.AssocList α β) :
                  Std.AssocList.forM f l = List.forM (Std.AssocList.toList l) fun (x : α × β) => match x with | (a, b) => f a b
                  def Std.AssocList.mapKey {α : Type u_1} {δ : Type u_2} {β : Type u_3} (f : αδ) :

                  O(n). Map a function f over the keys of the list.

                  Equations
                  Instances For
                    @[simp]
                    theorem Std.AssocList.toList_mapKey {α : Type u_1} {δ : Type u_2} {β : Type u_3} (f : αδ) (l : Std.AssocList α β) :
                    Std.AssocList.toList (Std.AssocList.mapKey f l) = List.map (fun (x : α × β) => match x with | (a, b) => (f a, b)) (Std.AssocList.toList l)
                    @[simp]
                    theorem Std.AssocList.length_mapKey :
                    ∀ {α : Type u_1} {α_1 : Type u_2} {f : αα_1} {β : Type u_3} {l : Std.AssocList α β}, Std.AssocList.length (Std.AssocList.mapKey f l) = Std.AssocList.length l
                    def Std.AssocList.mapVal {α : Type u_1} {β : Type u_2} {δ : Type u_3} (f : αβδ) :

                    O(n). Map a function f over the values of the list.

                    Equations
                    Instances For
                      @[simp]
                      theorem Std.AssocList.toList_mapVal {α : Type u_1} {β : Type u_2} {δ : Type u_3} (f : αβδ) (l : Std.AssocList α β) :
                      Std.AssocList.toList (Std.AssocList.mapVal f l) = List.map (fun (x : α × β) => match x with | (a, b) => (a, f a b)) (Std.AssocList.toList l)
                      @[simp]
                      theorem Std.AssocList.length_mapVal :
                      ∀ {α : Type u_1} {β : Type u_2} {β_1 : Type u_3} {f : αββ_1} {l : Std.AssocList α β}, Std.AssocList.length (Std.AssocList.mapVal f l) = Std.AssocList.length l
                      @[specialize #[]]
                      def Std.AssocList.findEntryP? {α : Type u_1} {β : Type u_2} (p : αβBool) :
                      Std.AssocList α βOption (α × β)

                      O(n). Returns the first entry in the list whose entry satisfies p.

                      Equations
                      Instances For
                        @[simp]
                        theorem Std.AssocList.findEntryP?_eq {α : Type u_1} {β : Type u_2} (p : αβBool) (l : Std.AssocList α β) :
                        Std.AssocList.findEntryP? p l = List.find? (fun (x : α × β) => match x with | (a, b) => p a b) (Std.AssocList.toList l)
                        @[inline]
                        def Std.AssocList.findEntry? {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (l : Std.AssocList α β) :
                        Option (α × β)

                        O(n). Returns the first entry in the list whose key is equal to a.

                        Equations
                        Instances For
                          @[simp]
                          theorem Std.AssocList.findEntry?_eq {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (l : Std.AssocList α β) :
                          Std.AssocList.findEntry? a l = List.find? (fun (x : α × β) => x.fst == a) (Std.AssocList.toList l)
                          def Std.AssocList.find? {α : Type u_1} {β : Type u_2} [BEq α] (a : α) :
                          Std.AssocList α βOption β

                          O(n). Returns the first value in the list whose key is equal to a.

                          Equations
                          Instances For
                            theorem Std.AssocList.find?_eq_findEntry? {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (l : Std.AssocList α β) :
                            Std.AssocList.find? a l = Option.map (fun (x : α × β) => x.snd) (Std.AssocList.findEntry? a l)
                            @[simp]
                            theorem Std.AssocList.find?_eq {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (l : Std.AssocList α β) :
                            Std.AssocList.find? a l = Option.map (fun (x : α × β) => x.snd) (List.find? (fun (x : α × β) => x.fst == a) (Std.AssocList.toList l))
                            @[specialize #[]]
                            def Std.AssocList.any {α : Type u_1} {β : Type u_2} (p : αβBool) :

                            O(n). Returns true if any entry in the list satisfies p.

                            Equations
                            Instances For
                              @[simp]
                              theorem Std.AssocList.any_eq {α : Type u_1} {β : Type u_2} (p : αβBool) (l : Std.AssocList α β) :
                              Std.AssocList.any p l = List.any (Std.AssocList.toList l) fun (x : α × β) => match x with | (a, b) => p a b
                              @[specialize #[]]
                              def Std.AssocList.all {α : Type u_1} {β : Type u_2} (p : αβBool) :

                              O(n). Returns true if every entry in the list satisfies p.

                              Equations
                              Instances For
                                @[simp]
                                theorem Std.AssocList.all_eq {α : Type u_1} {β : Type u_2} (p : αβBool) (l : Std.AssocList α β) :
                                Std.AssocList.all p l = List.all (Std.AssocList.toList l) fun (x : α × β) => match x with | (a, b) => p a b
                                def Std.AssocList.All {α : Type u_1} {β : Type u_2} (p : αβProp) (l : Std.AssocList α β) :

                                Returns true if every entry in the list satisfies p.

                                Equations
                                Instances For
                                  @[inline]
                                  def Std.AssocList.contains {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (l : Std.AssocList α β) :

                                  O(n). Returns true if there is an element in the list whose key is equal to a.

                                  Equations
                                  Instances For
                                    @[simp]
                                    theorem Std.AssocList.contains_eq {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (l : Std.AssocList α β) :
                                    Std.AssocList.contains a l = List.any (Std.AssocList.toList l) fun (x : α × β) => x.fst == a
                                    def Std.AssocList.replace {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (b : β) :

                                    O(n). Replace the first entry in the list with key equal to a to have key a and value b.

                                    Equations
                                    Instances For
                                      @[simp]
                                      theorem Std.AssocList.toList_replace {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (b : β) (l : Std.AssocList α β) :
                                      Std.AssocList.toList (Std.AssocList.replace a b l) = List.replaceF (fun (x : α × β) => bif x.fst == a then some (a, b) else none) (Std.AssocList.toList l)
                                      @[simp]
                                      theorem Std.AssocList.length_replace {α : Type u_1} :
                                      ∀ {β : Type u_2} {b : β} {l : Std.AssocList α β} [inst : BEq α] {a : α}, Std.AssocList.length (Std.AssocList.replace a b l) = Std.AssocList.length l
                                      @[specialize #[]]
                                      def Std.AssocList.eraseP {α : Type u_1} {β : Type u_2} (p : αβBool) :

                                      O(n). Remove the first entry in the list with key equal to a.

                                      Equations
                                      Instances For
                                        @[simp]
                                        theorem Std.AssocList.toList_eraseP {α : Type u_1} {β : Type u_2} (p : αβBool) (l : Std.AssocList α β) :
                                        Std.AssocList.toList (Std.AssocList.eraseP p l) = List.eraseP (fun (x : α × β) => match x with | (a, b) => p a b) (Std.AssocList.toList l)
                                        @[inline]
                                        def Std.AssocList.erase {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (l : Std.AssocList α β) :

                                        O(n). Remove the first entry in the list with key equal to a.

                                        Equations
                                        Instances For
                                          @[simp]
                                          theorem Std.AssocList.toList_erase {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (l : Std.AssocList α β) :
                                          def Std.AssocList.modify {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (f : αββ) :

                                          O(n). Replace the first entry a', b in the list with key equal to a to have key a and value f a' b.

                                          Equations
                                          Instances For
                                            @[simp]
                                            theorem Std.AssocList.toList_modify {α : Type u_1} {β : Type u_2} {f : αββ} [BEq α] (a : α) (l : Std.AssocList α β) :
                                            Std.AssocList.toList (Std.AssocList.modify a f l) = List.replaceF (fun (x : α × β) => match x with | (k, v) => bif k == a then some (a, f k v) else none) (Std.AssocList.toList l)
                                            @[simp]
                                            theorem Std.AssocList.length_modify {α : Type u_1} :
                                            ∀ {β : Type u_2} {f : αββ} {l : Std.AssocList α β} [inst : BEq α] {a : α}, Std.AssocList.length (Std.AssocList.modify a f l) = Std.AssocList.length l
                                            @[specialize #[]]
                                            def Std.AssocList.forIn {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_4} {δ : Type u_1} [Monad m] (as : Std.AssocList α β) (init : δ) (f : α × βδm (ForInStep δ)) :
                                            m δ

                                            The implementation of ForIn, which enables for (k, v) in aList do ... notation.

                                            Equations
                                            Instances For
                                              instance Std.AssocList.instForInAssocListProd {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_4} :
                                              ForIn m (Std.AssocList α β) (α × β)
                                              Equations
                                              • Std.AssocList.instForInAssocListProd = { forIn := fun {β_1 : Type u_1} [Monad m] => Std.AssocList.forIn }
                                              @[simp]
                                              theorem Std.AssocList.forIn_eq {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_4} {δ : Type u_1} [Monad m] (l : Std.AssocList α β) (init : δ) (f : α × βδm (ForInStep δ)) :
                                              forIn l init f = forIn (Std.AssocList.toList l) init f
                                              def Std.AssocList.pop? {α : Type u_1} {β : Type u_2} :
                                              Std.AssocList α βOption ((α × β) × Std.AssocList α β)

                                              Split the list into head and tail, if possible.

                                              Equations
                                              Instances For
                                                instance Std.AssocList.instToStreamAssocList {α : Type u_1} {β : Type u_2} :
                                                Equations
                                                • Std.AssocList.instToStreamAssocList = { toStream := fun (x : Std.AssocList α β) => x }
                                                instance Std.AssocList.instStreamAssocListProd {α : Type u_1} {β : Type u_2} :
                                                Stream (Std.AssocList α β) (α × β)
                                                Equations
                                                • Std.AssocList.instStreamAssocListProd = { next? := Std.AssocList.pop? }
                                                def List.toAssocList {α : Type u_1} {β : Type u_2} :
                                                List (α × β)Std.AssocList α β

                                                Converts a list into an AssocList. This is the inverse function to AssocList.toList.

                                                Equations
                                                Instances For
                                                  @[simp]
                                                  theorem List.toList_toAssocList {α : Type u_1} {β : Type u_2} (l : List (α × β)) :
                                                  @[simp]
                                                  theorem List.length_toAssocList {α : Type u_1} {β : Type u_2} (l : List (α × β)) :
                                                  def Std.AssocList.beq {α : Type u_1} {β : Type u_2} [BEq α] [BEq β] :
                                                  Std.AssocList α βStd.AssocList α βBool

                                                  Implementation of == on AssocList.

                                                  Equations
                                                  Instances For
                                                    instance Std.AssocList.instBEqAssocList {α : Type u_1} {β : Type u_2} [BEq α] [BEq β] :

                                                    Boolean equality for AssocList. (This relation cares about the ordering of the key-value pairs.)

                                                    Equations
                                                    • Std.AssocList.instBEqAssocList = { beq := Std.AssocList.beq }
                                                    @[simp]
                                                    theorem Std.AssocList.beq_nil₂ {α : Type u_1} {β : Type u_2} [BEq α] [BEq β] :
                                                    (Std.AssocList.nil == Std.AssocList.nil) = true
                                                    @[simp]
                                                    theorem Std.AssocList.beq_nil_cons {α : Type u_1} {β : Type u_2} {a : α} {b : β} {t : Std.AssocList α β} [BEq α] [BEq β] :
                                                    (Std.AssocList.nil == Std.AssocList.cons a b t) = false
                                                    @[simp]
                                                    theorem Std.AssocList.beq_cons_nil {α : Type u_1} {β : Type u_2} {a : α} {b : β} {t : Std.AssocList α β} [BEq α] [BEq β] :
                                                    (Std.AssocList.cons a b t == Std.AssocList.nil) = false
                                                    @[simp]
                                                    theorem Std.AssocList.beq_cons₂ {α : Type u_1} {β : Type u_2} {a : α} {b : β} {t : Std.AssocList α β} {a' : α} {b' : β} {t' : Std.AssocList α β} [BEq α] [BEq β] :
                                                    (Std.AssocList.cons a b t == Std.AssocList.cons a' b' t') = (a == a' && b == b' && t == t')
                                                    Equations
                                                    • =
                                                    theorem Std.AssocList.beq_eq {α : Type u_1} {β : Type u_2} [BEq α] [BEq β] {l : Std.AssocList α β} {m : Std.AssocList α β} :