Skip to content

Commit 9658145

Browse files
authored
Merge pull request #634 from eulerkochy/swissdict
SwissDict
2 parents 0b06c5a + 12582d0 commit 9658145

File tree

10 files changed

+1050
-1
lines changed

10 files changed

+1050
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This package implements a variety of data structures, including
2323
- Mutable Binary Heap
2424
- Ordered Dicts and Sets
2525
- RobinDict (implemented with [Robin Hood Hashing](https://cs.uwaterloo.ca/research/tr/1986/CS-86-14.pdf))
26+
- SwissDict (inspired from [SwissTables](https://abseil.io/blog/20180927-swisstables))
2627
- Dictionaries with Defaults
2728
- Trie
2829
- Linked List and Mutable Linked List

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ makedocs(
1919
"ordered_containers.md",
2020
"default_dict.md",
2121
"robin_dict.md",
22+
"swiss_dict.md",
2223
"trie.md",
2324
"linked_list.md",
2425
"mutable_linked_list.md",

docs/src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This package implements a variety of data structures, including
1515
- Mutable Binary Heap
1616
- Ordered Dicts and Sets
1717
- RobinDict and OrderedRobinDict (implemented with [Robin Hood Hashing](https://cs.uwaterloo.ca/research/tr/1986/CS-86-14.pdf))
18+
- SwissDict (inspired from [SwissTables](https://abseil.io/blog/20180927-swisstables))
1819
- Dictionaries with Defaults
1920
- Trie
2021
- Linked List and Mutable Linked List

docs/src/swiss_dict.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
```@meta
2+
DocTestSetup = :(using DataStructures)
3+
```
4+
5+
# SwissDict
6+
7+
`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.
8+
9+
The interface of `SwissDict` replicates that of `Dict`.
10+
11+
Examples:
12+
13+
```jldoctest
14+
julia> d = RobinDict{Int, Char}(1 => 'a', 2 => 'b')
15+
SwissDict{Int64,Char} with 2 entries:
16+
1 => 'a'
17+
2 => 'b'
18+
19+
julia> d[3] = 'c';
20+
21+
julia> collect(d)
22+
3-element Array{Pair{Int64,Char},1}:
23+
1 => 'a'
24+
2 => 'b'
25+
3 => 'c'
26+
27+
julia> delete!(d, 2);
28+
29+
julia> d[1]
30+
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
31+
32+
julia> d
33+
SwissDict{Int64,Char} with 2 entries:
34+
1 => 'a'
35+
3 => 'c'
36+
37+
julia> pop!(d)
38+
1 => 'a'
39+
```
40+
41+
```@meta
42+
DocTestSetup = nothing
43+
```

src/DataStructures.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module DataStructures
4646
export MultiDict, enumerateall
4747
export RobinDict
4848
export OrderedRobinDict, isordered
49+
export SwissDict
4950

5051
export DiBitVector
5152

@@ -87,6 +88,7 @@ module DataStructures
8788
include("container_loops.jl")
8889
include("robin_dict.jl")
8990
include("ordered_robin_dict.jl")
91+
include("swiss_dict.jl")
9092
export
9193
CircularBuffer,
9294
capacity,

src/ordered_robin_dict.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ end
230230
function Base.get!(default::Base.Callable, h::OrderedRobinDict{K,V}, key0) where {K,V}
231231
index = get(h.dict, key0, -2)
232232
index > 0 && return @inbounds h.vals[index]
233+
233234
v = convert(V, default())
234235
setindex!(h, v, key0)
235236
return v

0 commit comments

Comments
 (0)