Skip to content

Commit

Permalink
Merge pull request #634 from eulerkochy/swissdict
Browse files Browse the repository at this point in the history
SwissDict
  • Loading branch information
eulerkochy committed Aug 30, 2020
2 parents 0b06c5a + 12582d0 commit 9658145
Show file tree
Hide file tree
Showing 10 changed files with 1,050 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -23,6 +23,7 @@ This package implements a variety of data structures, including
- Mutable Binary Heap
- Ordered Dicts and Sets
- RobinDict (implemented with [Robin Hood Hashing](https://cs.uwaterloo.ca/research/tr/1986/CS-86-14.pdf))
- SwissDict (inspired from [SwissTables](https://abseil.io/blog/20180927-swisstables))
- Dictionaries with Defaults
- Trie
- Linked List and Mutable Linked List
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Expand Up @@ -19,6 +19,7 @@ makedocs(
"ordered_containers.md",
"default_dict.md",
"robin_dict.md",
"swiss_dict.md",
"trie.md",
"linked_list.md",
"mutable_linked_list.md",
Expand Down
1 change: 1 addition & 0 deletions docs/src/index.md
Expand Up @@ -15,6 +15,7 @@ This package implements a variety of data structures, including
- Mutable Binary Heap
- Ordered Dicts and Sets
- RobinDict and OrderedRobinDict (implemented with [Robin Hood Hashing](https://cs.uwaterloo.ca/research/tr/1986/CS-86-14.pdf))
- SwissDict (inspired from [SwissTables](https://abseil.io/blog/20180927-swisstables))
- Dictionaries with Defaults
- Trie
- Linked List and Mutable Linked List
Expand Down
43 changes: 43 additions & 0 deletions docs/src/swiss_dict.md
@@ -0,0 +1,43 @@
```@meta
DocTestSetup = :(using DataStructures)
```

# SwissDict

`SwissDict` provides a standard dictionary, conforming to the AbstractDict protocol, which is inspired from SwissTable developed by Google. This provides improved performance over Dict at extremely high Load Factor.

The interface of `SwissDict` replicates that of `Dict`.

Examples:

```jldoctest
julia> d = RobinDict{Int, Char}(1 => 'a', 2 => 'b')
SwissDict{Int64,Char} with 2 entries:
1 => 'a'
2 => 'b'
julia> d[3] = 'c';
julia> collect(d)
3-element Array{Pair{Int64,Char},1}:
1 => 'a'
2 => 'b'
3 => 'c'
julia> delete!(d, 2);
julia> d[1]
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
julia> d
SwissDict{Int64,Char} with 2 entries:
1 => 'a'
3 => 'c'
julia> pop!(d)
1 => 'a'
```

```@meta
DocTestSetup = nothing
```
2 changes: 2 additions & 0 deletions src/DataStructures.jl
Expand Up @@ -46,6 +46,7 @@ module DataStructures
export MultiDict, enumerateall
export RobinDict
export OrderedRobinDict, isordered
export SwissDict

export DiBitVector

Expand Down Expand Up @@ -87,6 +88,7 @@ module DataStructures
include("container_loops.jl")
include("robin_dict.jl")
include("ordered_robin_dict.jl")
include("swiss_dict.jl")
export
CircularBuffer,
capacity,
Expand Down
1 change: 1 addition & 0 deletions src/ordered_robin_dict.jl
Expand Up @@ -230,6 +230,7 @@ end
function Base.get!(default::Base.Callable, h::OrderedRobinDict{K,V}, key0) where {K,V}
index = get(h.dict, key0, -2)
index > 0 && return @inbounds h.vals[index]

v = convert(V, default())
setindex!(h, v, key0)
return v
Expand Down

0 comments on commit 9658145

Please sign in to comment.