@@ -33,9 +33,8 @@ function counter(seq)
3333end
3434
3535eltype_for_accumulator (seq:: T ) where T = eltype (T)
36- function eltype_for_accumulator (seq:: Base.Generator )
37- Base. @default_eltype (seq)
38- end
36+ eltype_for_accumulator (seq:: Base.Generator ) = Base. @default_eltype (seq)
37+
3938
4039
4140Base. copy (ct:: Accumulator ) = Accumulator (copy (ct. map))
@@ -44,9 +43,9 @@ Base.length(a::Accumulator) = length(a.map)
4443
4544# # retrieval
4645
47- Base. get (ct:: Accumulator , x, default) = get (ct. map, x, default)
4846# need to allow user specified default in order to
4947# correctly implement "informal" AbstractDict interface
48+ Base. get (ct:: Accumulator , x, default) = get (ct. map, x, default)
5049
5150Base. getindex (ct:: Accumulator{T,V} , x) where {T,V} = get (ct. map, x, zero (V))
5251
@@ -76,12 +75,11 @@ inc!(ct::Accumulator, x, v::Number) = (ct[x] += v)
7675inc! (ct:: Accumulator{T, V} , x) where {T, V} = inc! (ct, x, one (V))
7776
7877# inc! is preferred over push!, but we need to provide push! for the Bag interpreation
79- # which is used by classified_collections.jl
8078Base. push! (ct:: Accumulator , x) = inc! (ct, x)
8179Base. push! (ct:: Accumulator , x, a:: Number ) = inc! (ct, x, a)
8280
8381# To remove ambiguities related to Accumulator now being a subtype of AbstractDict
84- Base. push! (ct:: Accumulator , x:: Pair ) = inc! (ct, x)
82+ Base. push! (ct:: Accumulator{P} , x:: P ) where P <: Pair = inc! (ct, x)
8583
8684
8785"""
@@ -92,7 +90,9 @@ Decrements the count for `x` by `v` (defaulting to one)
9290dec! (ct:: Accumulator , x, v:: Number ) = (ct[x] -= v)
9391dec! (ct:: Accumulator{T,V} , x) where {T,V} = dec! (ct, x, one (V))
9492
95- # TODO : once we are done deprecating `pop!` for `reset!` then add `pop!` as an alias for `dec!`
93+ Base. pop! (ct:: Accumulator , x) = dec! (ct, x)
94+ Base. pop! (ct:: Accumulator , x, default) = haskey (ct, x) ? dec! (ct, x) : default
95+
9696
9797"""
9898 merge!(ct1::Accumulator, others...)
@@ -183,6 +183,11 @@ nsmallest(acc::Accumulator, n) = partialsort!(collect(acc), 1:n, by=last, rev=fa
183183# ##########################################################
184184# # Multiset operations
185185
186+ """
187+ MultiplicityException{K,V} <: Exception
188+
189+ For errors related to havign a negetive count when using an Accumulator as a multiset.
190+ """
186191struct MultiplicityException{K, V} <: Exception
187192 k:: K
188193 v:: V
0 commit comments