Review Board 1.7.22


GIRAPH-112: Use elements() properly in LongDoubleFloatDoubleVertex

Review Request #3287 - Created Dec. 21, 2011 and updated

Avery Ching
trunk
GIRAPH-112
Reviewers
giraph
giraph
As pointed out by YuanYua, the array returned by elements() cannot have its length used since the array contains all the elements currently stored in the mahout collections, even including invalid elements between size and capacity.

Whenever possible I converted elements() into forEach(), forEachKey(), forEachPair().  Used size() in other cases.

Fixed some formatting violations as well in LongDoubleFloatDoubleVertex.java.
Local unittests and MR unittests.
Ship it!
Posted (Dec. 21, 2011, 7:58 a.m.)
I ran into the same issue yesterday and the solution presented here is correct. For reasons of efficiency, list.elements() returns the internal underlying array for the list, which might be bigger than the number of elements stored in the list. Therefore you should only iterate until list.size() or use the foreachKey() callback.
Ship it!
Posted (Dec. 22, 2011, 6:51 a.m.)
Good catch, this looks great, thanks!