Created
November 16, 2014 22:38
-
-
Save SimonDanisch/c01235254451f8234e29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Version 1, if you really need to access the counters via a name | |
type CountersDict | |
counters::Dict{Symbol, Array{Int64}} | |
end | |
function CountersDict() | |
CountersDict([ | |
:counter1 => zeros(Int64, 100000), | |
:counter2 => zeros(Int64, 100000), | |
:counter3 => zeros(Int64, 100000), | |
:counter4 => zeros(Int64, 500), | |
:counter5 => zeros(Int64, 500, 1000) | |
]) | |
end | |
function +(c1::CountersDict, c2::CountersDict) | |
c = Dict{Symbol, Array{Int64}}() | |
for (name, value) in c1.counters | |
c[name] = value + c2.counters[name] | |
end | |
return CountersDict(c) | |
end | |
#Version 2 | |
type CountersArray | |
counters::Vector{Array{Int64}} | |
end | |
function CountersArray() | |
CountersArray(Array{Int64}[ | |
zeros(Int64, 100000), | |
zeros(Int64, 100000), | |
zeros(Int64, 100000), | |
zeros(Int64, 500), | |
zeros(Int64, 500, 1000) | |
]) | |
end | |
function +(c1::CountersArray, c2::CountersArray) | |
return CountersArray(map(+, c1.counters, c2.counters)) | |
end | |
CountersDict() + CountersDict() | |
CountersArray() + CountersArray() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment