adjustOrPutValue?

87 views
Skip to first unread message

bimargulies

unread,
May 2, 2011, 10:24:19 AM5/2/11
to fastutil
The colt collections that we mutated into mahout-collections has a
method on the numeric-value maps called 'adjustOrPutValue'. The idea
here is to save a hash lookup by having an atomic operation specified
as:

"if you have this key, change the value by x. If not, put y"

Would you all consider this?

Sebastiano Vigna

unread,
May 2, 2011, 10:43:25 AM5/2/11
to fast...@googlegroups.com

The current implementation (maybe not yet distributed) has an "add()" method for maps that adds something to a value. Since there are default return values, if you, for instance, want to use a hash map as a set of counters you can set up a map with default value 0 and call map.add( key, 1 ). If the key is their, the counter is incremented. If not, it is set to 1 (as the default return value is -1).

This is less generic than "adjuctOrPutValue", but I'm not in favour of excessively customized dictionary methods.

Ciao,

seba


Benson Margulies

unread,
May 2, 2011, 10:50:57 AM5/2/11
to fast...@googlegroups.com
That's enough for me, I don't need the increment to differ from the
'new value' value.

An ETA on distribution?

Sebastiano Vigna

unread,
May 2, 2011, 10:59:49 AM5/2/11
to fast...@googlegroups.com
On May 2, 2011, at 4:50 PM, Benson Margulies wrote:

> That's enough for me, I don't need the increment to differ from the
> 'new value' value.
>
> An ETA on distribution?


I was wrong, it's online since a while. Just use 6.2.2.

6.2.0 -> 6.2.2

- A new add() method makes the usage of maps as counters easier
and faster.


Ciao,

seba


Benson Margulies

unread,
May 2, 2011, 11:17:10 AM5/2/11
to fast...@googlegroups.com
Thanks. I missed it.

Dawid Weiss

unread,
May 2, 2011, 3:06:17 PM5/2/11
to fast...@googlegroups.com

Hi Benson. :) 

That release Sebastiano has mentioned is also in Maven Central:

and a mavenized snapshot of fastutil is at github if you need it:

Dawid
Reply all
Reply to author
Forward
0 new messages