nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
ec74959
)
lib/counter: introduce Counter::dec
author
Alexandre Terrasa
<alexandre@moz-code.org>
Fri, 24 Apr 2015 02:00:03 +0000
(22:00 -0400)
committer
Alexandre Terrasa
<alexandre@moz-code.org>
Fri, 24 Apr 2015 02:01:43 +0000
(22:01 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
lib/counter.nit
patch
|
blob
|
history
diff --git
a/lib/counter.nit
b/lib/counter.nit
index
6545b73
..
6d5729d
100644
(file)
--- a/
lib/counter.nit
+++ b/
lib/counter.nit
@@
-93,6
+93,22
@@
class Counter[E]
for e in es do inc(e)
end
+ # Decrement the value of `e` by 1
+ fun dec(e: E) do
+ if not has_key(e) then
+ self.map[e] = 0
+ else
+ self.map[e] = self[e] - 1
+ sum += - 1
+ end
+ end
+
+ # Decrement the value for each element of `es`
+ fun dec_all(es: Collection[E])
+ do
+ for e in es do dec(e)
+ end
+
# A new Counter initialized with `inc_all`.
init from(es: Collection[E])
do