Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zwilias/elm-avl-dict-exploration
Alternative Dict implementation backed by an AVL tree
https://github.com/zwilias/elm-avl-dict-exploration
avl-tree dict elm
Last synced: about 2 months ago
JSON representation
Alternative Dict implementation backed by an AVL tree
- Host: GitHub
- URL: https://github.com/zwilias/elm-avl-dict-exploration
- Owner: zwilias
- License: bsd-3-clause
- Created: 2017-02-26T09:03:12.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-30T12:19:21.000Z (almost 8 years ago)
- Last Synced: 2024-10-13T02:21:45.869Z (3 months ago)
- Topics: avl-tree, dict, elm
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/zwilias/elm-avl-dict-exploration/1.0.0
- Size: 355 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Alternative Dict implementation backed by AVL tree [![Build Status](https://travis-ci.org/zwilias/elm-avl-dict-exploration.svg?branch=master)](https://travis-ci.org/zwilias/elm-avl-dict-exploration)
## Elevator pitch
Red-black trees as used in core's Dict require quite a few modifications for
rebalancing. Worse; they require quite a few comparisons to do the correct
modifications, which is notoriously slow in Elm. AVL trees offer similar
worst-case performance characteristics, but in this case, much better insertion
performance.## Performance
You can find a little write up on the benchmarks and the methodology on [this page](http://elm-avl-dict-bench.surge.sh).
## Using Dict.AVL
`Dict.AVL` has the exact same API as core Dict, so using it can be accomplished
by simply doing something like this:```elm
import Dict.AVL as Dict
```There is one exception - checking for equality. Since core's Dict is special
cased in elm ecosystem for equality checks, and we can't use this same special
case due to a different internal structure, you'll need to use the
`Dict.AVL.eq` function.```elm
import Dict.AVL as Dictleft = Dict.fromList [(0, ()), (1, ())]
right = Dict.fromList [(1, ()), (0, ())]-- This will return False
left == right-- This works as expected and returns True
Dict.eq left right
```