IndexMultiMap #
This module defines a generic IndexMultiMap type that maps keys to multiple values.
The implementation stores entries in a flat array for iteration and an index HashMap
for fast key lookups. Each key always has at least one associated value.
A structure for managing ordered key-value pairs where each key can have multiple values.
Flat array of all key-value entries in insertion order.
Maps each key to its indices in
entries. Each array is non-empty.
Instances For
Equations
Equations
- Std.Internal.instInhabitedIndexMultiMap = { default := { entries := #[], indexes := Std.HashMap.emptyWithCapacity, validity := ⋯ } }
Equations
- Std.Internal.IndexMultiMap.instMembership = { mem := fun (map : Std.Internal.IndexMultiMap α β) (key : α) => key ∈ map.indexes }
Retrieves all values for the given key.
Equations
Instances For
Retrieves the first value for the given key.
Equations
Instances For
Retrieves all values for the given key, or none if the key is absent.
Instances For
Retrieves the first value for the given key, or none if the key is absent.
Instances For
Checks if the key-value pair is present in the map.
Equations
Instances For
Retrieves the last value for the given key.
Returns none if the key is absent.
Instances For
Inserts a new key-value pair into the map. If the key already exists, appends the value to existing values.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Inserts multiple values for a given key, appending to any existing values.
Equations
- map.insertMany key values = Array.foldl (fun (x : Std.Internal.IndexMultiMap α β) => x.insert key) map values
Instances For
Creates an empty multimap.
Equations
- Std.Internal.IndexMultiMap.empty = { entries := #[], indexes := Std.HashMap.emptyWithCapacity, validity := ⋯ }
Instances For
Creates a multimap from a list of key-value pairs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Updates all values associated with key by applying f to each one.
If the key is absent, returns the map unchanged.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Replaces the last value associated with key with value.
If the key is absent, returns the map unchanged.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Removes a key and all its values from the map. This function rebuilds the entire
entries array and indexes map from scratch by filtering out all pairs whose
key matches, then re-inserting the survivors.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Merges two multimaps, combining values for shared keys.
Equations
- m1.merge m2 = Array.foldl (fun (acc : Std.Internal.IndexMultiMap α β) (x : α × β) => match x with | (k, v) => acc.insert k v) m1 m2.entries
Instances For
Equations
- Std.Internal.IndexMultiMap.instEmptyCollection = { emptyCollection := Std.Internal.IndexMultiMap.empty }
Equations
- Std.Internal.IndexMultiMap.instInsertProdOfEquivBEqOfLawfulHashable = { insert := fun (x : α × β) (m : Std.Internal.IndexMultiMap α β) => match x with | (a, b) => m.insert a b }