JuliaCollections / DataStructures.jl

Julia implementation of Data structures
https://juliacollections.github.io/DataStructures.jl/latest/
MIT License
689 stars 243 forks source link

add normalize(::Accumulator, p) #259

Open tpapp opened 7 years ago

tpapp commented 7 years ago

Sometimes when I count things, I am more interested in percentages than absolute values. I wonder if you would consider a PR along the lines of

function Base.normalize{T,V}(acc::Accumulator{T,V}, p=1)
    _norm = norm(collect(values(acc)), p)
    Accumulator(Dict(key => value/_norm for (key,value) in acc.map))
end

(obviously with documentation, tests, etc).

kmsquire commented 7 years ago

I think the idea is reasonable, although I think the output should be something other than Accumulator. I don't have any bright ideas about exactly what that should be, though.

tpapp commented 7 years ago

Perhaps a Dict?

kmsquire commented 7 years ago

Sure, that would work.