Skip to content

Commit

Permalink
Remove HashDict
Browse files Browse the repository at this point in the history
* This was originally copied from Base and used as a basis for both
  Ordered and Unordered dictionaries.  However, Jeff Bezanson's
  OrderedDict is implemented differently and is committed here, so
  there's no need for this type anymore
  • Loading branch information
kmsquire committed Nov 14, 2016
1 parent 52615e8 commit ff9a671
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 552 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
19 changes: 10 additions & 9 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 @@ -67,17 +67,18 @@ 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, ks, vs) = new(DefaultDictBase{K,V,F,HashDict{K,V,$O}}(x,ks,vs))
$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))
$DefaultDict(x, ks, vs) = new(DefaultDictBase{K,V,F,$dict{K,V}}(x,ks,vs))
end

## Constructors
Expand All @@ -95,7 +96,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)))

## Functions

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
Loading

0 comments on commit ff9a671

Please sign in to comment.