dictstore.patch
1 diff --git a/src/Storage/dictstore.jl b/src/Storage/dictstore.jl 2 index 7815ed2..97938ed 100644 3 --- a/src/Storage/dictstore.jl 4 +++ b/src/Storage/dictstore.jl 5 @@ -1,54 +1,63 @@ 6 # Stores data in a simple dict in memory 7 -struct DictStore <: AbstractStore 8 - a::Dict{String,Vector{UInt8}} 9 +abstract type AbstractDictStore <: AbstractStore end 10 + 11 +struct DictStore <: AbstractDictStore 12 + a::Dict{String,Vector{UInt8}} 13 end 14 DictStore() = DictStore(Dict{String,Vector{UInt8}}()) 15 16 -Base.show(io::IO,d::DictStore) = print(io,"Dictionary Storage") 17 -function _pdict(d::DictStore,p) 18 - p = (isempty(p) || endswith(p,'/')) ? p : p*'/' 19 - filter(((k,v),)->startswith(k,p),d.a) 20 +Base.show(io::IO, d::AbstractDictStore) = print(io, "Dictionary Storage") 21 +function _pdict(d::AbstractDictStore, p) 22 + p = (isempty(p) || endswith(p, '/')) ? p : p * '/' 23 + filter(((k, v),) -> startswith(k, p), d.a) 24 +end 25 +function _pkeys(d::AbstractDictStore, p) 26 + p = (isempty(p) || endswith(p, '/')) ? p : p * '/' 27 + filter((k) -> startswith(k, p), keys(d.a)) 28 end 29 -function storagesize(d::DictStore,p) 30 - sum(i->last(split(i[1],'/')) ∉ (".zattrs",".zarray") ? sizeof(i[2]) : zero(sizeof(i[2])), _pdict(d,p)) 31 +function storagesize(d::AbstractDictStore, p) 32 + sum(i -> if last(split(i[1], '/')) ∉ (".zattrs", ".zarray") 33 + sizeof(i[2]) 34 + else 35 + zero(sizeof(i[2])) 36 + end, _pdict(d, p)) 37 end 38 39 -function Base.getindex(d::DictStore,i::AbstractString) 40 - get(d.a,i,nothing) 41 +function Base.getindex(d::AbstractDictStore, i::AbstractString) 42 + get(d.a, i, nothing) 43 end 44 -function Base.setindex!(d::DictStore,v,i::AbstractString) 45 - d.a[i] = v 46 +function Base.setindex!(d::AbstractDictStore, v, i::AbstractString) 47 + d.a[i] = v 48 end 49 -Base.delete!(d::DictStore, i::AbstractString) = delete!(d.a,i) 50 +Base.delete!(d::AbstractDictStore, i::AbstractString) = delete!(d.a, i) 51 52 -function subdirs(d::DictStore,p) 53 - d2 = _pdict(d,p) 54 - _searchsubdict(d2,p,(sp,lp)->length(sp) > lp+1) 55 +function subdirs(d::AbstractDictStore, p) 56 + d2 = _pkeys(d, p) 57 + _searchsubdict(d2, p, (sp, lp) -> length(sp) > lp + 1) 58 end 59 60 -function subkeys(d::DictStore,p) 61 - d2 = _pdict(d,p) 62 - _searchsubdict(d2,p,(sp,lp)->length(sp) == lp+1) 63 +function subkeys(d::AbstractDictStore, p) 64 + d2 = _pkeys(d, p) 65 + _searchsubdict(d2, p, (sp, lp) -> length(sp) == lp + 1) 66 end 67 68 -function _searchsubdict(d2,p,condition) 69 - o = Set{String}() 70 - pspl = split(rstrip(p,'/'),'/') 71 - lp = if length(pspl) == 1 && isempty(pspl[1]) 72 - 0 73 - else 74 - length(pspl) 75 - end 76 - for k in keys(d2) 77 - sp = split(k,'/') 78 - if condition(sp,lp) 79 - push!(o,sp[lp+1]) 80 +function _searchsubdict(d2, p, condition) 81 + o = Set{String}() 82 + pspl = split(rstrip(p, '/'), '/') 83 + lp = if length(pspl) == 1 && isempty(pspl[1]) 84 + 0 85 + else 86 + length(pspl) 87 end 88 - end 89 - collect(o) 90 + for k in d2 91 + sp = split(k, '/') 92 + if condition(sp, lp) 93 + push!(o, sp[lp + 1]) 94 + end 95 + end 96 + collect(o) 97 end 98 99 +#getsub(d::AbstractDictStore, p, n) = _substore(d,p).subdirs[n] 100 101 -#getsub(d::DictStore, p, n) = _substore(d,p).subdirs[n] 102 - 103 -#path(d::DictStore) = "" 104 +#path(d::AbstractDictStore) = ""