pull/1/head
matthieugomez 2015-10-23 19:14:32 -04:00
parent a3a8d2daca
commit 5dc1a1d68f
1 changed files with 4 additions and 4 deletions

View File

@ -21,14 +21,14 @@ type Bag{Tv, Ti <: Integer}
end
function Base.push!{Tv, Ti}(bag::Bag{Tv, Ti}, x::Tv)
bag.dict[x] = get(bag.dict, x, 0) + 1
bag.dict[x] = get(bag.dict, x, zero(UInt)) + one(UInt)
return bag
end
function Base.delete!{Tv, Ti}(bag::Bag{Tv, Ti}, x::Tv)
v = get(bag.dict, x, 0)
if v > 0
bag.dict[x] = v - 1
v = get(bag.dict, x, zero(UInt))
if v > zero(UInt)
bag.dict[x] = v - one(UInt)
end
return x
end