On Tue, Dec 15, 2009 at 5:26 AM, Benson Margulies <[email protected]>wrote:
> As to float and double, they may need to be special cases. Ask
> yourself: "What should get(k) return when containsKey(k) is false and
> the payload is double?"
>
> Answer 1: NaN.
> Answer 2: zero, like with the int types.
>
I actually feel that Answer 2 is more correct, if only for the fact that we
currently use
an IntDoubleMap to back our SparseVector impl, and for SparseVectors, we
definitely
want zero as the default.
For general collections, yes, I can see not doing this, but at least in
Mahout, we use
zero-default vectors and matrices.
I guess we could have both, in which case we could autogenerate the zero
case with
the others.
Of course, you could also just have the {X}{Y}Map take a default value in
the constructor,
and return this value whenever contains(k) == false. The default default
value could be
zero for integral types, and NaN for floating points.
This is maximally flexible at the cost of one additional primitive stored
and no cpu.
Also, what about other primitives? boolean, short? Seems like we should
really have
the full complement of all 64 classes, right?
{boolean}{byte}{char}{short}{int}{long}{float}{double}^2
-jake