Repository: JuliaCollections/DataStructures.jl
Pull request #553 (2019-11-21 19:19:19)

Allow accumulators to take an AbstractDict

oxinabox: LGTM.
please bump versiom number so i can tag release
codecov[bot]: # [Codecov](https://codecov.io/gh/JuliaCollections/DataStructures.jl/pull/553?src=pr&el=h1) Report
> Merging [#553](https://codecov.io/gh/JuliaCollections/DataStructures.jl/pull/553?src=pr&el=desc) into [master](https://codecov.io/gh/JuliaCollections/DataStructures.jl/commit/3d68cd3af77f327e828c976139e4996471804f3e?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/JuliaCollections/DataStructures.jl/pull/553/graphs/tree.svg?width=650&token=7FHvoCSQ7k&height=150&src=pr)](https://codecov.io/gh/JuliaCollections/DataStructures.jl/pull/553?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #553      +/-   ##
==========================================
+ Coverage   87.82%   87.82%   +<.01%     
==========================================
  Files          32       32              
  Lines        2086     2087       +1     
==========================================
+ Hits         1832     1833       +1     
  Misses        254      254
```


| [Impacted Files](https://codecov.io/gh/JuliaCollections/DataStructures.jl/pull/553?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/accumulator.jl](https://codecov.io/gh/JuliaCollections/DataStructures.jl/pull/553/diff?src=pr&el=tree#diff-c3JjL2FjY3VtdWxhdG9yLmps) | `90.76% <100%> (+0.14%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/JuliaCollections/DataStructures.jl/pull/553?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/JuliaCollections/DataStructures.jl/pull/553?src=pr&el=footer). Last update [3d68cd3...272f0bf](https://codecov.io/gh/JuliaCollections/DataStructures.jl/pull/553?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/Project.toml b/Project.toml
index e6875c9..79f4203 100644
--- a/Project.toml
+++ b/Project.toml
@@ -1,6 +1,6 @@
 name = "DataStructures"
 uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
-version = "0.17.5"
+version = "0.17.6"
 
 [deps]
 InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
diff --git a/src/accumulator.jl b/src/accumulator.jl
index d414c0e..ba34101 100644
--- a/src/accumulator.jl
+++ b/src/accumulator.jl
@@ -7,9 +7,10 @@ end
 ## constructors
 
 Accumulator{T, V}() where {T,V<:Number} = Accumulator{T,V}(Dict{T,V}())
+Accumulator(map::AbstractDict) = Accumulator(Dict(map))
 
 counter(T::Type) = Accumulator{T,Int}()
-counter(dct::Dict{T,V}) where {T,V<:Integer} = Accumulator{T,V}(copy(dct))
+counter(dct::AbstractDict{T, V}) where {T, V<:Integer} = Accumulator{T, V}(Dict(dct))
 
 """
     counter(seq)


Test patch:
diff --git a/test/test_accumulator.jl b/test/test_accumulator.jl
index 119efac..861052d 100644
--- a/test/test_accumulator.jl
+++ b/test/test_accumulator.jl
@@ -90,6 +90,16 @@
         @test ctm["b"] == 0
     end
 
+    @testset "From AbstractDict" begin
+        kv = (:a => 1, :b => 2)
+        for f in (Accumulator, counter)
+            ct_odict = f(OrderedDict(kv))
+            ct_dict = f(Dict(kv))
+            @test ct_odict isa Accumulator{Symbol, Int}
+            @test ct_odict == ct_dict
+        end
+    end
+
     @testset "From Pair" begin
         ct4 = counter(Pair{Int,Int})
         @test isa(ct4, Accumulator{Pair{Int,Int}})