Documentation

Hale.Containers.Data.IntMap

@[reducible, inline]
abbrev Data.IntMap (v : Type u) :

A map from Nat keys to values, backed by a hash map. $$\text{IntMap}(v) \cong \text{HashMap}(\mathbb{N}, v)$$ Provides amortised $O(1)$ lookup and insert.

Equations
Instances For
    @[inline]

    The empty map. $$\text{empty} = \emptyset$$

    Equations
    Instances For
      @[inline]
      def Data.IntMap.singleton {v : Type u} (key : Nat) (val : v) :

      A map with a single key-value pair. $$\text{singleton}(k, v) = \{k \mapsto v\}$$

      Equations
      Instances For
        @[inline]
        def Data.IntMap.fromList {v : Type u} (l : List (Nat × v)) :

        Build a map from an association list. Later entries override earlier ones for duplicate keys. $$\text{fromList}([(k_1,v_1),\ldots,(k_n,v_n)])$$

        Equations
        Instances For
          @[inline]
          def Data.IntMap.lookup {v : Type u} (key : Nat) (m : IntMap v) :

          Look up a key. $$\text{lookup}(k, m) = \begin{cases} \text{some}(v) & \text{if } k \mapsto v \in m \\ \text{none} & \text{otherwise} \end{cases}$$

          Equations
          Instances For
            @[inline]
            def Data.IntMap.findWithDefault {v : Type u} (dflt : v) (key : Nat) (m : IntMap v) :
            v

            Look up a key, returning a default if absent. $$\text{findWithDefault}(d, k, m) = \begin{cases} v & \text{if } k \mapsto v \in m \\ d & \text{otherwise} \end{cases}$$

            Equations
            Instances For
              @[inline]
              def Data.IntMap.member {v : Type u} (key : Nat) (m : IntMap v) :

              Test whether a key is in the map. $$\text{member}(k, m) \iff k \in \text{dom}(m)$$

              Equations
              Instances For
                @[inline]
                def Data.IntMap.null {v : Type u} (m : IntMap v) :

                Is the map empty? $$\text{null}(m) \iff m = \emptyset$$

                Equations
                Instances For
                  @[inline]
                  def Data.IntMap.size' {v : Type u} (m : IntMap v) :

                  The number of entries. $$\text{size'}(m) = |m|$$

                  Equations
                  Instances For
                    @[inline]
                    def Data.IntMap.insert' {v : Type u} (key : Nat) (val : v) (m : IntMap v) :

                    Insert a key-value pair. If the key already exists, the value is replaced. $$\text{insert}(k, v, m) = m[k \mapsto v]$$

                    Equations
                    Instances For
                      @[inline]
                      def Data.IntMap.delete {v : Type u} (key : Nat) (m : IntMap v) :

                      Delete a key from the map. $$\text{delete}(k, m) = m \setminus \{k\}$$

                      Equations
                      Instances For
                        def Data.IntMap.adjust {v : Type u} (f : vv) (key : Nat) (m : IntMap v) :

                        Adjust the value at a key, if present. $$\text{adjust}(f, k, m) = \begin{cases} m[k \mapsto f(v)] & \text{if } k \mapsto v \in m \\ m & \text{otherwise} \end{cases}$$

                        Equations
                        Instances For
                          def Data.IntMap.union {v : Type u} (m1 m2 : IntMap v) :

                          Left-biased union of two maps. $$\text{union}(m_1, m_2) = m_1 \cup m_2 \quad (\text{left-biased})$$

                          Equations
                          Instances For
                            def Data.IntMap.unionWith {v : Type u} (f : vvv) (m1 m2 : IntMap v) :

                            Union with a combining function. $$\text{unionWith}(f, m_1, m_2)[k] = \begin{cases} f(v_1, v_2) & \text{if } k \in m_1 \cap m_2 \\ v_1 & \text{if } k \in m_1 \text{ only} \\ v_2 & \text{if } k \in m_2 \text{ only} \end{cases}$$

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              def Data.IntMap.intersection {v : Type u} (m1 m2 : IntMap v) :

                              Intersection of two maps, keeping values from the first. $$\text{intersection}(m_1, m_2) = \{k \mapsto v \mid k \mapsto v \in m_1, k \in \text{dom}(m_2)\}$$

                              Equations
                              Instances For
                                def Data.IntMap.intersectionWith {v : Type u} (f : vvv) (m1 m2 : IntMap v) :

                                Intersection with a combining function. $$\text{intersectionWith}(f, m_1, m_2)[k] = f(v_1, v_2) \text{ for } k \in \text{dom}(m_1) \cap \text{dom}(m_2)$$

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  def Data.IntMap.difference {v : Type u} (m1 m2 : IntMap v) :

                                  Difference of two maps. $$\text{difference}(m_1, m_2) = \{k \mapsto v \mid k \mapsto v \in m_1, k \notin \text{dom}(m_2)\}$$

                                  Equations
                                  Instances For
                                    @[inline]
                                    def Data.IntMap.foldlWithKey {v : Type u} {α : Type u_1} (f : αNatvα) (init : α) (m : IntMap v) :
                                    α

                                    Left fold over key-value pairs (unspecified order). $$\text{foldlWithKey}(f, z, m)$$

                                    Equations
                                    Instances For
                                      def Data.IntMap.foldrWithKey {v : Type u} {α : Type u_1} (f : Natvαα) (init : α) (m : IntMap v) :
                                      α

                                      Right fold over key-value pairs (unspecified order). $$\text{foldrWithKey}(f, z, m)$$

                                      Equations
                                      Instances For
                                        @[inline]
                                        def Data.IntMap.mapValues {v : Type u} {w : Type u_1} (f : vw) (m : IntMap v) :

                                        Map a function over all values. $$\text{mapValues}(f, m)[k] = f(m[k])$$

                                        Equations
                                        Instances For
                                          @[inline]
                                          def Data.IntMap.mapWithKey {v : Type u} {w : Type u_1} (f : Natvw) (m : IntMap v) :

                                          Map a function over all key-value pairs. $$\text{mapWithKey}(f, m)[k] = f(k, m[k])$$

                                          Equations
                                          Instances For
                                            @[inline]
                                            def Data.IntMap.filterWithKey {v : Type u} (p : NatvBool) (m : IntMap v) :

                                            Filter entries by a predicate on keys and values. $$\text{filterWithKey}(p, m) = \{k \mapsto v \mid k \mapsto v \in m, p(k, v)\}$$

                                            Equations
                                            Instances For
                                              @[inline]
                                              def Data.IntMap.toList' {v : Type u} (m : IntMap v) :
                                              List (Nat × v)

                                              Convert the map to a list of key-value pairs (unspecified order). $$\text{toList'}(m) = [(k_1, v_1), \ldots, (k_n, v_n)]$$

                                              Equations
                                              Instances For
                                                def Data.IntMap.toAscList {v : Type u} (m : IntMap v) :
                                                List (Nat × v)

                                                Convert the map to an association list sorted by ascending key. $$\text{toAscList}(m) = [(k_1, v_1), \ldots, (k_n, v_n)]$$ where $k_1 < \cdots < k_n$. Note: requires $O(n \log n)$ sort since the backing HashMap is unordered.

                                                Equations
                                                Instances For
                                                  def Data.IntMap.keys {v : Type u} (m : IntMap v) :

                                                  The list of all keys (unspecified order). $$\text{keys}(m) = [k_1, \ldots, k_n]$$

                                                  Equations
                                                  Instances For
                                                    def Data.IntMap.elems {v : Type u} (m : IntMap v) :

                                                    The list of all values (unspecified order). $$\text{elems}(m) = [v_1, \ldots, v_n]$$

                                                    Equations
                                                    Instances For
                                                      def Data.IntMap.restrictKeys {v : Type u} (m : IntMap v) (ks : List Nat) :

                                                      Restrict a map to only the keys in the given list. $$\text{restrictKeys}(m, ks) = \{k \mapsto v \mid k \mapsto v \in m, k \in ks\}$$

                                                      Equations
                                                      Instances For
                                                        def Data.IntMap.withoutKeys {v : Type u} (m : IntMap v) (ks : List Nat) :

                                                        Remove all keys in the given list from the map. $$\text{withoutKeys}(m, ks) = \{k \mapsto v \mid k \mapsto v \in m, k \notin ks\}$$

                                                        Equations
                                                        Instances For
                                                          def Data.IntMap.isSubmapOf {v : Type u} [BEq v] (m1 m2 : IntMap v) :

                                                          Is m1 a submap of m2? $$\text{isSubmapOf}(m_1, m_2) \iff \forall k \in \text{dom}(m_1),\; m_1[k] = m_2[k]$$

                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For
                                                            def Data.IntMap.lookupMin {v : Type u} (m : IntMap v) :

                                                            The smallest key-value pair, or none if the map is empty. $$\text{lookupMin}(m) = \min_{k} \{(k, v) \mid k \mapsto v \in m\}$$ Note: $O(n)$ since the backing HashMap is unordered.

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For
                                                              def Data.IntMap.lookupMax {v : Type u} (m : IntMap v) :

                                                              The largest key-value pair, or none if the map is empty. $$\text{lookupMax}(m) = \max_{k} \{(k, v) \mid k \mapsto v \in m\}$$ Note: $O(n)$ since the backing HashMap is unordered.

                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For
                                                                @[implicit_reducible]
                                                                instance Data.IntMap.instRepr {v : Type u} [Repr v] :
                                                                Equations
                                                                • One or more equations did not get rendered due to their size.