Documentation

Batteries.Data.AssocList.Basic

Association lists #

AssocList α β is a List (α × β) with the pair structure flattened into the list constructor. This file defines the type and its operations; the lemmas relating those operations to the corresponding List operations along AssocList.toList are in Batteries.Data.AssocList.Lemmas.

inductive Batteries.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_reducible]
    instance Batteries.instInhabitedAssocList {a✝ : Type u_1} {a✝¹ : Type u_2} :
    Inhabited (AssocList a✝ a✝¹)
    Equations
    def Batteries.AssocList.toList {α : Type u_1} {β : Type u_2} :
    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
      @[instance_reducible]
      Equations
      def Batteries.AssocList.isEmpty {α : Type u_1} {β : Type u_2} :
      AssocList α βBool

      O(1). Is the list empty?

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

        The number of entries in an AssocList.

        Equations
        Instances For
          @[specialize #[]]
          def Batteries.AssocList.foldlM {m : Type u_1 → Type u_2} {δ : Type u_1} {α : Type u_3} {β : Type u_4} [Monad m] (f : δαβm δ) (init : δ) :
          AssocList α βm δ

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

          Equations
          Instances For
            @[inline]
            def Batteries.AssocList.foldl {δ : Type u_1} {α : Type u_2} {β : Type u_3} (f : δαβδ) (init : δ) (as : AssocList α β) :
            δ

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

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

              Optimized version of toList.

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

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

                Equations
                Instances For
                  def Batteries.AssocList.mapKey {α : Type u_1} {δ : Type u_2} {β : Type u_3} (f : αδ) :
                  AssocList α βAssocList δ β

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

                  Equations
                  Instances For
                    def Batteries.AssocList.mapVal {α : Type u_1} {β : Type u_2} {δ : Type u_3} (f : αβδ) :
                    AssocList α βAssocList α δ

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

                    Equations
                    Instances For
                      @[specialize #[]]
                      def Batteries.AssocList.findEntryP? {α : Type u_1} {β : Type u_2} (p : αβBool) :
                      AssocList α βOption (α × β)

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

                      Equations
                      Instances For
                        @[inline]
                        def Batteries.AssocList.findEntry? {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (l : AssocList α β) :
                        Option (α × β)

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

                        Equations
                        Instances For
                          def Batteries.AssocList.find? {α : Type u_1} {β : Type u_2} [BEq α] (a : α) :
                          AssocList α βOption β

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

                          Equations
                          Instances For
                            @[specialize #[]]
                            def Batteries.AssocList.any {α : Type u_1} {β : Type u_2} (p : αβBool) :
                            AssocList α βBool

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

                            Equations
                            Instances For
                              @[specialize #[]]
                              def Batteries.AssocList.all {α : Type u_1} {β : Type u_2} (p : αβBool) :
                              AssocList α βBool

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

                              Equations
                              Instances For
                                def Batteries.AssocList.All {α : Type u_1} {β : Type u_2} (p : αβProp) (l : AssocList α β) :

                                Returns true if every entry in the list satisfies p.

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

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

                                  Equations
                                  Instances For
                                    def Batteries.AssocList.replace {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (b : β) :
                                    AssocList α βAssocList α β

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

                                    Equations
                                    Instances For
                                      @[specialize #[]]
                                      def Batteries.AssocList.eraseP {α : Type u_1} {β : Type u_2} (p : αβBool) :
                                      AssocList α βAssocList α β

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

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

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

                                        Equations
                                        Instances For
                                          def Batteries.AssocList.modify {α : Type u_1} {β : Type u_2} [BEq α] (a : α) (f : αββ) :
                                          AssocList α βAssocList α β

                                          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
                                            @[specialize #[]]
                                            def Batteries.AssocList.forIn {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_4} {δ : Type u_1} [Monad m] (as : AssocList α β) (init : δ) (f : α × βδm (ForInStep δ)) :
                                            m δ

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

                                            Equations
                                            Instances For
                                              @[instance_reducible]
                                              instance Batteries.AssocList.instForInProdOfMonad {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_4} [Monad m] :
                                              ForIn m (AssocList α β) (α × β)
                                              Equations
                                              def Batteries.AssocList.pop? {α : Type u_1} {β : Type u_2} :
                                              AssocList α βOption ((α × β) × AssocList α β)

                                              Split the list into head and tail, if possible.

                                              Equations
                                              Instances For
                                                @[instance_reducible]
                                                instance Batteries.AssocList.instToStream {α : Type u_1} {β : Type u_2} :
                                                Equations
                                                @[instance_reducible]
                                                instance Batteries.AssocList.instStreamProd {α : Type u_1} {β : Type u_2} :
                                                Std.Stream (AssocList α β) (α × β)
                                                Equations
                                                def List.toAssocList {α : Type u_1} {β : Type u_2} :
                                                List (α × β)Batteries.AssocList α β

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

                                                Equations
                                                Instances For
                                                  @[instance_reducible]
                                                  instance Batteries.AssocList.instBEq {α : Type u_1} {β : Type u_2} [BEq α] [BEq β] :
                                                  BEq (AssocList α β)

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

                                                  Equations