https://github.com/kowainik/typerep-map
⚡️Efficient implementation of Map with types as keys
https://github.com/kowainik/typerep-map
arrays binary-search cache dependent-map dmap hacktoberfest haskell typerep-map
Last synced: about 2 months ago
JSON representation
⚡️Efficient implementation of Map with types as keys
- Host: GitHub
- URL: https://github.com/kowainik/typerep-map
- Owner: kowainik
- License: mpl-2.0
- Created: 2017-12-15T23:16:22.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-01-18T06:59:21.000Z (over 1 year ago)
- Last Synced: 2024-11-07T02:42:36.129Z (8 months ago)
- Topics: arrays, binary-search, cache, dependent-map, dmap, hacktoberfest, haskell, typerep-map
- Language: Haskell
- Homepage: https://kowainik.github.io/projects/typerep-map
- Size: 188 KB
- Stars: 100
- Watchers: 7
- Forks: 18
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# typerep-map

[](https://github.com/kowainik/typerep-map/actions)
[](https://hackage.haskell.org/package/typerep-map)
[](LICENSE)`typerep-map` introduces `TMap` and `TypeRepMap` — data structures like [`Map`](http://hackage.haskell.org/package/containers-0.6.0.1/docs/Data-Map-Lazy.html#t:Map), but where types serve as keys, and values have the types specified in the corresponding key spots.
For the more details on the implementation see the following blog post:
* [typerep-map step by step](https://kowainik.github.io/posts/2018-07-11-typerep-map-step-by-step)
## Usage example
```haskell
ghci> import Data.TMapghci> tm = insert True $ one (42 :: Int)
ghci> size tm
2ghci> res = lookup tm
ghci> res :: Maybe Int
Just 42ghci> res :: Maybe Bool
Just Trueghci> res :: Maybe String
Nothingghci> lookup (insert "hello" tm) :: Maybe String
Just "hello"ghci> member @Int tm
Trueghci> tm' = delete @Int tm
ghci> member @Int tm'
False
```## Benchmarks
Tables below contain comparision with `DMap TypeRep` of ten `lookup` operations
on structure with size `10^4`:| | ghc-8.2.2 | ghc-8.4.3 | ghc-8.8.3 | ghc-8.10.1 |
|----------------|-----------|-----------|-----------|------------|
| `DMap TypeRep` | 517.5 ns | 779.9 ns | 1.559 μs | 1.786 μs |
| `typerep-map` | 205.3 ns | 187.2 ns | 190.1 ns | 169.1 ns |ghc-8.2.2 | ghc-8.4.3
:---------:|:-----------:
 | 
 | 