Documentation

Std.Http.Internal.MultiMap

MultiMap #

This module defines a generic MultiMap type that maps keys to multiple values while remembering the order in which entries were inserted.

Entries live in one array and lookups scan it. Header maps hold at most a few dozen entries and see a handful of lookups per message, so a scan costs less than maintaining any index on insert.

structure Std.Internal.MultiMap (α : Type u) (β : Type v) :
Type (max u v)

A structure for managing ordered key-value pairs where each key can have multiple values.

  • entries : Array (α × β)

    All key-value entries in insertion order.

Instances For
    @[instance_reducible]
    instance Std.Internal.instInhabitedMultiMap {a✝ : Type u_1} {a✝¹ : Type u_2} :
    Inhabited (MultiMap a✝ a✝¹)
    Equations
    def Std.Internal.instReprMultiMap.repr {α✝ : Type u_1} {β✝ : Type u_2} [Repr α✝] [Repr β✝] :
    MultiMap α✝ β✝ → Nat → Format
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[instance_reducible]
      instance Std.Internal.instReprMultiMap {α✝ : Type u_1} {β✝ : Type u_2} [Repr α✝] [Repr β✝] :
      Repr (MultiMap α✝ β✝)
      Equations
      @[instance_reducible]
      instance Std.Internal.MultiMap.instMembershipOfBEq {α : Type u} {β : Type v} [BEq α] :
      Membership α (MultiMap α β)
      Equations
      @[instance_reducible]
      instance Std.Internal.MultiMap.instDecidableMem {α : Type u} {β : Type v} [BEq α] (key : α) (map : MultiMap α β) :
      Decidable (key ∈ map)
      Equations
      @[irreducible, specialize #[]]
      def Std.Internal.MultiMap.findIdxFrom {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) (i : Nat) :

      Position of the first entry at or after i whose key is key, or map.entries.size if there is none.

      Equations
      Instances For
        @[specialize #[]]
        def Std.Internal.MultiMap.findLastIdxBelow {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) :
        Nat → Nat

        Position of the last entry below i whose key is key, or map.entries.size if there is none.

        Equations
        Instances For
          theorem Std.Internal.MultiMap.findIdxFrom_lt_size {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) (i : Nat) (h : ∃ (j : Nat), ∃ (x : j < map.entries.size), i ≤ j ∧ (map.entries[j].fst == key) = true) :
          map.findIdxFrom key i < map.entries.size

          findIdxFrom stays in bounds when some entry at or after i has the key.

          theorem Std.Internal.MultiMap.findIdxFrom_zero_lt_size {α : Type u} {β : Type v} [BEq α] {map : MultiMap α β} {key : α} (h : key ∈ map) :
          map.findIdxFrom key 0 < map.entries.size

          The first entry with a key that is in the map lies within entries.

          @[inline]
          def Std.Internal.MultiMap.getAll {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) (_h : key ∈ map) :

          Retrieves all values for the given key.

          Equations
          Instances For
            @[inline]
            def Std.Internal.MultiMap.get {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) (h : key ∈ map) :
            β

            Retrieves the first value for the given key.

            Equations
            Instances For
              @[inline]
              def Std.Internal.MultiMap.getAll? {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) :

              Retrieves all values for the given key, or none if the key is absent.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                @[inline]
                def Std.Internal.MultiMap.get? {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) :

                Retrieves the first value for the given key, or none if the key is absent.

                Equations
                Instances For
                  @[inline]
                  def Std.Internal.MultiMap.hasEntry {α : Type u} {β : Type v} [BEq α] [BEq β] (map : MultiMap α β) (key : α) (value : β) :

                  Checks if the key-value pair is present in the map.

                  Equations
                  Instances For
                    @[inline]
                    def Std.Internal.MultiMap.getLast? {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) :

                    Retrieves the last value for the given key. Returns none if the key is absent.

                    Equations
                    Instances For
                      @[inline]
                      def Std.Internal.MultiMap.getD {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) (d : β) :
                      β

                      Like get?, but returns a default value if absent.

                      Equations
                      Instances For
                        @[inline]
                        def Std.Internal.MultiMap.get! {α : Type u} {β : Type v} [BEq α] [Inhabited β] (map : MultiMap α β) (key : α) :
                        β

                        Like get?, but panics if absent.

                        Equations
                        Instances For
                          @[inline]
                          def Std.Internal.MultiMap.insert {α : Type u} {β : Type v} (map : MultiMap α β) (key : α) (value : β) :
                          MultiMap α β

                          Inserts a new key-value pair into the map. If the key already exists, appends the value to existing values.

                          Equations
                          Instances For
                            @[inline]
                            def Std.Internal.MultiMap.insertMany {α : Type u} {β : Type v} (map : MultiMap α β) (key : α) (values : Array β) :
                            MultiMap α β

                            Inserts multiple values for a given key, appending to any existing values.

                            Equations
                            Instances For
                              def Std.Internal.MultiMap.empty {α : Type u} {β : Type v} :
                              MultiMap α β

                              Creates an empty multimap.

                              Equations
                              Instances For
                                def Std.Internal.MultiMap.ofList {α : Type u} {β : Type v} (pairs : List (α × β)) :
                                MultiMap α β

                                Creates a multimap from a list of key-value pairs.

                                Equations
                                Instances For
                                  @[inline]
                                  def Std.Internal.MultiMap.contains {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) :

                                  Checks if a key exists in the map.

                                  Equations
                                  Instances For
                                    @[inline]
                                    def Std.Internal.MultiMap.update {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) (f : β → β) :
                                    MultiMap α β

                                    Updates all values associated with key by applying f to each one. If the key is absent, returns the map unchanged.

                                    Equations
                                    Instances For
                                      @[inline]
                                      def Std.Internal.MultiMap.replaceLast {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) (value : β) :
                                      MultiMap α β

                                      Replaces the last value associated with key with value. If the key is absent, returns the map unchanged.

                                      Equations
                                      Instances For
                                        @[inline]
                                        def Std.Internal.MultiMap.erase {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (key : α) :
                                        MultiMap α β

                                        Removes a key and all its values from the map.

                                        Equations
                                        Instances For
                                          @[inline]
                                          def Std.Internal.MultiMap.eraseMany {α : Type u} {β : Type v} [BEq α] (map : MultiMap α β) (keys : Array α) :
                                          MultiMap α β

                                          Removes multiple keys and all their associated values from the map. Keys not present in the map are ignored.

                                          Equations
                                          Instances For
                                            @[inline]
                                            def Std.Internal.MultiMap.size {α : Type u} {β : Type v} (map : MultiMap α β) :

                                            Gets the number of entries in the map.

                                            Equations
                                            Instances For
                                              @[inline]
                                              def Std.Internal.MultiMap.isEmpty {α : Type u} {β : Type v} (map : MultiMap α β) :

                                              Checks if the map is empty.

                                              Equations
                                              Instances For
                                                def Std.Internal.MultiMap.toArray {α : Type u} {β : Type v} (map : MultiMap α β) :
                                                Array (α × β)

                                                Converts the multimap to an array of key-value pairs (flattened).

                                                Equations
                                                Instances For
                                                  def Std.Internal.MultiMap.toList {α : Type u} {β : Type v} (map : MultiMap α β) :
                                                  List (α × β)

                                                  Converts the multimap to a list of key-value pairs (flattened).

                                                  Equations
                                                  Instances For
                                                    def Std.Internal.MultiMap.merge {α : Type u} {β : Type v} (m1 m2 : MultiMap α β) :
                                                    MultiMap α β

                                                    Merges two multimaps, combining values for shared keys.

                                                    Equations
                                                    Instances For
                                                      @[instance_reducible]
                                                      instance Std.Internal.MultiMap.instSingletonProd {α : Type u} {β : Type v} :
                                                      Singleton (α × β) (MultiMap α β)
                                                      Equations
                                                      @[instance_reducible]
                                                      instance Std.Internal.MultiMap.instInsertProd {α : Type u} {β : Type v} :
                                                      Insert (α × β) (MultiMap α β)
                                                      Equations
                                                      @[instance_reducible]
                                                      instance Std.Internal.MultiMap.instUnion {α : Type u} {β : Type v} :
                                                      Union (MultiMap α β)
                                                      Equations
                                                      @[instance_reducible]
                                                      instance Std.Internal.MultiMap.instForInProdOfMonad {α : Type u} {β : Type v} {m : Type u_1 → Type u_2} [Monad m] :
                                                      ForIn m (MultiMap α β) (α × β)
                                                      Equations