Skip to content

Commit

Permalink
Merge pull request #224 from JuliaLang/kms/remove_hash_dict
Browse files Browse the repository at this point in the history
RFC: Remove HashDict
  • Loading branch information
kmsquire committed Dec 3, 2016
2 parents 658bd8a + 1681e24 commit 64b6631
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 551 deletions.
1 change: 0 additions & 1 deletion src/DataStructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ module DataStructures
include("heaps.jl")

include("dict_support.jl")
include("hash_dict.jl")
include("ordered_dict.jl")
include("ordered_set.jl")
include("default_dict.jl")
Expand Down
17 changes: 9 additions & 8 deletions src/default_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# DefaultDictBase is the main class used to in Default*Dicts.
#
# Each related (immutable) Default*Dict class contains a single
# DefautlDictBase object as a member, and delegates almost all
# DefaultDictBase object as a member, and delegates almost all
# functions to this object.
#
# The main rationale for doing this instead of using type aliases is
Expand Down Expand Up @@ -63,16 +63,17 @@ getindex(d::DefaultDictBase, key) = get!(d.d, key, d.default)
# wrappers around a DefaultDictBase object, and delegate all functions
# to that object

for (DefaultDict,O) in [(:DefaultDict, :Unordered), (:DefaultOrderedDict, :Ordered)]
for _Dict in [:Dict, :OrderedDict]
DefaultDict = Symbol("Default"*string(_Dict))
@eval begin
immutable $DefaultDict{K,V,F} <: Associative{K,V}
d::DefaultDictBase{K,V,F,HashDict{K,V,$O}}
d::DefaultDictBase{K,V,F,$_Dict{K,V}}

$DefaultDict(x, ps::Pair{K,V}...) = new(DefaultDictBase{K,V,F,HashDict{K,V,$O}}(x, ps...))
$DefaultDict(x, kv::AbstractArray{Tuple{K,V}}) = new(DefaultDictBase{K,V,F,HashDict{K,V,$O}}(x, kv))
$DefaultDict(x, ps::Pair{K,V}...) = new(DefaultDictBase{K,V,F,$_Dict{K,V}}(x, ps...))
$DefaultDict(x, kv::AbstractArray{Tuple{K,V}}) = new(DefaultDictBase{K,V,F,$_Dict{K,V}}(x, kv))
$DefaultDict(x, d::$DefaultDict) = $DefaultDict(x, d.d)
$DefaultDict(x, d::HashDict) = new(DefaultDictBase{K,V,F,HashDict{K,V,$O}}(x, d))
$DefaultDict(x) = new(DefaultDictBase{K,V,F,HashDict{K,V,$O}}(x))
$DefaultDict(x, d::$_Dict) = new(DefaultDictBase{K,V,F,$_Dict{K,V}}(x, d))
$DefaultDict(x) = new(DefaultDictBase{K,V,F,$_Dict{K,V}}(x))
end

## Constructors
Expand All @@ -85,7 +86,7 @@ for (DefaultDict,O) in [(:DefaultDict, :Unordered), (:DefaultOrderedDict, :Order
$DefaultDict{K,V,F}(default::F, kv::AbstractArray{Tuple{K,V}}) = $DefaultDict{K,V,F}(default, kv)
$DefaultDict{K,V,F}(default::F, ps::Pair{K,V}...) = $DefaultDict{K,V,F}(default, ps...)

$DefaultDict{F}(default::F, d::Associative) = ((K,V)= (Base.keytype(d), Base.valtype(d)); $DefaultDict{K,V,F}(default, HashDict(d)))
$DefaultDict{F}(default::F, d::Associative) = ((K,V)= (Base.keytype(d), Base.valtype(d)); $DefaultDict{K,V,F}(default, $_Dict(d)))

# Constructor syntax: DefaultDictBase{Int,Float64}(default)
@compat (::Type{$DefaultDict{K,V}}){K,V}() = throw(ArgumentError("$DefaultDict: no default specified"))
Expand Down
8 changes: 4 additions & 4 deletions src/dict_support.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# support function
# support functions

# This is defined in Base, but probably not meant for external consumption,
# so it's redefined here.
# These functions are defined in Base, but are not exported,
# so they are redefined here.
_tablesz(x::Integer) = x < 16 ? 16 : one(x)<<((sizeof(x)<<3)-leading_zeros(x-1))

hashindex(key, sz) = (reinterpret(Int,(hash(key))) & (sz-1)) + 1

0 comments on commit 64b6631

Please sign in to comment.