Add a map type to LF
See original GitHub issueThere have been several discussion to add a new type Map K V
to DAML-LF in order to give us maps with arbitrary keys in DAML and a sensible representation in app languages. The issues that arise are:
- The engine needs to be deterministic. Which means the representation of the map needs to be as well. @remyhaemmerle-da recommends defining an internal ordering on
Value
and using a tree map. - gRPC doesn’t have arbitrary maps so we need to represent maps as a
[(K, V)]
on the wire. Again, to get determinism, this needs to be ordered so we have complexityn log(n)
somewhere. - JS doesn’t have a good map type for us to use in the bindings. @stefanobaghino-da recommends implementing our own.
If I got this right, the work would be
- Define/implement ordering on
Value
- Implement LF type
TreeMap K V
and serialisation to and from[(K, V)]
(with the write path doing the ordering and checking for duplicate keys) - Implement JS
Map
type - Translate
[(K, V)]
to and from idiomatic maps in Java and JS - Write a
DA.TreeMap
DAML lib
And the main tradeoff is that our maps would be O(log(n))
, but I find that perfectly acceptable. If anyone needs an O(1)
, they can always write a MapKey
instance.
Anything I missed? Does this sound like a good way to go? If so, how much effort would this be?
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
add an option for ignore layout · Issue #274 · gokcehan/lf
hi i use two layout on my system. lf not detect my shortcut in second ... map y # unmaps the current default...
Read more >Total and Partial Maps - Software Foundations
We build up to partial maps in two steps. First, we define a type of total maps that return a default value when...
Read more >lf - command - Go Packages
Load modified files and directories. This command is automatically called when required. reload (default '<c-r>'). Flush the cache and reload all files and ......
Read more >Map Functions and Operators — Presto 0.278.1 Documentation
Returns the union of all the given maps. If a key is found in multiple given maps, that key's value in the resulting...
Read more >Understanding the Map Data Type in Dart - Section.io
Inserting new key-value pairs in a map can be implemented in two ways: Adding values to a Map Literal. The code below implements...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Proposal
We implement Insertion preserving map (called
'Map'
) where keys are a arbitraryserializable
values.We provides the following builtins (with expected builtins):
MAP_EMPTY : ∀ k v, 'Map' k v
Returns the empty map. O(1)
MAP_INSERT : ∀ k v. k → v → 'Map' k v → 'Map' k v
Inserts a new key and value in the map. If the key is already present in the map, the associated value is replaced with the supplied value.If the key is present do not change the key insertion order. O(log(n))
MAP_LOOKUP : ∀ k v. k → 'Map' k v → 'Optional' v
Lookups the value at a key in the map. O(log(n))
MAP_DELETE : ∀ k v. k → 'Map' k v → 'Map' k v
Deletes a key and its value from the map. When the key is not a member of the map, the original map is returned. o(log(n))
MAP_LIST : ∀ k v. 'Map' k v → 'List' ⟨ key: k, value: v ⟩
Converts to a list of key/value pairs. The output list is sorted in the ordered the key have been inserted. O(n * log n)
MAP_FROM_LIST: ∀ k v. 'List' ⟨ key: k, value: v ⟩ → 'Map' k v
Converts a list of key/value pairs into a map. The insertion order is from left o right. Throws an exception if a key is duplicated. O(n * log n)
MAP_SIZE : ∀ k v. 'Map' k v → 'Int64'
Return the number of elements in the map. O(1)
In the ledger and in the ledger API, the map are represented as lists of pairs order as the insertion order.
added in lf 1.11