Duh... my code was the correct idiom for a sentinel model, not a hasNext
model.

I am about to file a JIRA on this and post a patch with a test.


On Fri, Jun 11, 2010 at 11:28 AM, Sean Owen <[email protected]> wrote:

> This has the same problem as the original code. :) Try zhao's example.
>
> On Fri, Jun 11, 2010 at 7:23 PM, Ted Dunning <[email protected]>
> wrote:
> >     Iterator<Element> myIter = iterateNonZero();
> >     Iterator<Element> otherIter = x.iterateNonZero();
> >     double result = 0.0;
> >     if (myIter.hasNext() && otherIter.hasNext()) {
> >        Element myCurrent = myIter.next();
> >        Element otherCurrent = otherIter.next();
> >        while (myIter.hasNext() && otherIter.hasNext()) {
> >           int myIndex = myCurrent.index();
> >           int otherIndex = otherCurrent.index();
> >           if (myIndex == otherIndex) {
> >              result += myCurrent.get() * otherCurrent.get();
> >           }
> >           if (myIndex <= otherIndex) {
> >               myCurrent = myIter.next();
> >           }
> >           if (myIndex >= otherIndex) {
> >               otherCurrent = otherIter.next();
> >           }
> >         }
> >      }
> >      return result;
> >
>

Reply via email to