Alternative API
See original GitHub issueAfter reading the other discussions about API design and backing implementation I decided to put some more work in to the tinkering I’ve been doing on persistent data structures. I think I now have enough done to start a discussion about the best approach.
https://github.com/amaranth/persistent-collections
There are interfaces for immutable collections, lists, sets, maps, sorted sets, and sorted maps. The implementation for lists is a bit-partitioned vector trie with O(log32n) scaling. The hash map is sort of halfway between the standard clojure style HAMT and the CHAMP design, I use separate arrays for child nodes and data. The tree map is using an AA tree, which apparently Scala uses as well. The hash set and tree set are just wrappers around the map implementations. There is also a (most likely broken) finger tree implementation which I plan to try to use for a priority queue and possibly ordered sets and maps.
The performance of the library is… okay. I’m sure more optimization work can be done but my main goal was to get something that works first. On that note the unit tests could certainly use some work, right now they’re mostly just ported from @andrewoma’s dexx library (and I’ve just noticed the license gradle plugin wiped his name from the copyright headers, oops) but they at least show things aren’t completely broken.
I’d love to see an API like this adopted, even if we decide to use UncleJim or dexx or pcollections for the backing implementation. The key design aspect mirrors the approach UncleJim uses in that the way to do mass updates to one of the collections in a performant way is to transform a Sequence
and then turn that in to a new collection. This lets us avoid exposing the transient versions to the API which should remove any chance to misuse them and accidentally lose immutability.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
I really expect lazy streams API add these powerful and convenient methods : repeat/cycle, repeatedly/generate, iterate, unfold, resource, reject, like in Elixir and Clojure: https://hexdocs.pm/elixir/Stream.html#unfold/2
@ilya-g Thanks, if provided by stdlib will be more convenient to every average programmer. I think, one of the programming trend is the Lazy Sequences . Is there the equivalence like Transducers in Clojure ? https://github.com/matthiasn/talk-transcripts/tree/master/Hickey_Rich