Skip to content

Commit

Permalink
Merge pull request #275 from oxinabox/equalityforaccumulatorsnow
Browse files Browse the repository at this point in the history
EqualityForAccumulators
  • Loading branch information
kmsquire authored Mar 10, 2017
2 parents 8c114f0 + 8ccd860 commit 93301f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/accumulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ length(a::Accumulator) = length(a.map)

## retrieval

get{T,V}(ct::Accumulator{T,V}, x::T, default) = get(ct.map, x, default)
# need to allow user specified default in order to
# correctly implement "informal" Associative interface

getindex{T,V}(ct::Accumulator{T,V}, x::T) = get(ct.map, x, zero(V))

haskey{T,V}(ct::Accumulator{T,V}, x::T) = haskey(ct.map, x)
Expand Down
4 changes: 4 additions & 0 deletions test/test_accumulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ ct4 = counter(Pair{Int,Int})
@test isa(ct4, Accumulator{Pair{Int,Int}})
@test push!(ct4, 1=>2) == 1
@test push!(ct4, 1=>2) == 2


@test counter([2,3,4,4]) == counter([4,2,3,4])
@test counter([2,3,4,4]) != counter([4,2,3,4,4])

0 comments on commit 93301f6

Please sign in to comment.