https://github.com/arkoniak/compresshashdisplace.jl
Compress hash displace algorithm for faster Julia dictionaries
https://github.com/arkoniak/compresshashdisplace.jl
chd hashtable
Last synced: 4 months ago
JSON representation
Compress hash displace algorithm for faster Julia dictionaries
- Host: GitHub
- URL: https://github.com/arkoniak/compresshashdisplace.jl
- Owner: Arkoniak
- License: mit
- Created: 2020-02-02T20:36:19.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-19T11:18:21.000Z (about 4 years ago)
- Last Synced: 2025-03-10T22:43:02.081Z (4 months ago)
- Topics: chd, hashtable
- Language: Julia
- Homepage:
- Size: 468 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CompressHashDisplace
| **Documentation** | **Build Status** |
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| [](https://Arkoniak.github.io/CompressHashDisplace.jl/stable)[](https://Arkoniak.github.io/CompressHashDisplace.jl/dev) | [](https://github.com/Arkoniak/CompressHashDisplace.jl/actions)[](https://codecov.io/gh/Arkoniak/CompressHashDisplace.jl) |This package creates read-only dictionaries with fast access speed.
## Installation
```julia
julia> ] add CompressHashDisplace
```## Usage
```julia
using BenchmarkTools
using CompressHashDisplaceDICTIONARY = "/usr/share/dict/words"
dict = Dict{String, Int}()for (line, word) in enumerate(readlines(DICTIONARY))
dict[word] = line
endfrozen_dict = FrozenDict(dict)
frozen_dict["hello"] # 50196frozen_unsafe_dict = FrozenUnsafeDict(dict)
frozen_unsafe_dict["hello"] # 50196word = "hello"
@btime $dict[$word] # 76.615 ns (0 allocations: 0 bytes)
@btime $frozen_dict[$word] # 60.028 ns (0 allocations: 0 bytes)
@btime $frozen_unsafe_dict[$word] # 22.124 ns (0 allocations: 0 bytes)
```Main difference between `FrozenDict` and `FrozenUnsafeDict` is that `FrozenUnsafeDict`
do not validate input key```julia
frozen_dict["foo"] # KeyError: key "foo" not found
frozen_unsafe_dice["foo"] # 59716, i.e. some random value
```