dfinity / motoko

Simple high-level language for writing Internet Computer canisters
Apache License 2.0
503 stars 98 forks source link

Collection library wish list #812

Open rossberg opened 4 years ago

rossberg commented 4 years ago

The current Trie and Set provide fairly low-level interfaces whose use is not safe, e.g., because the user might accidentally mix multiple hash or eq functions. For a more complete picture, we should provide the following:

These should come with:

matthewhammer commented 4 years ago

@rossberg thanks for this list; LGTM.

I'll prioritize items from here during this month and next.

matthewhammer commented 4 years ago

Some things above (functional unordered maps) have been implemented, but not yet wrapped with a higher-level interface that avoids the programmer providing the hash function for each call.

Many things above are not implemented, though. None of them should be tricky, since they are all well-understood things (just not yet expressed in Motoko).

I have a rough dependency order in mind:

Imperative hash table:

Based on these ingredients, a simple hash table should be routine to implement in Motoko.

Red-black trees:

For the purely-functional version, I would follow my notes of the Okaski treatment of these. I taught them at some point recently (to undergrads, in Elm), so it shouldn't be hard to reproduce in Motoko.

Wrappers / Iterators

I think I can envision the wrappers and iterators mentioned above, though I need to work each out to be sure of the details.

kritzcreek commented 3 years ago

I think we've got all those data structures in base now. Can we close this @matthewhammer?