[ 
https://issues.apache.org/jira/browse/SOLR-11093?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16100480#comment-16100480
 ] 

David Smiley commented on SOLR-11093:
-------------------------------------

Why is zeroCount an integer instead of simply a hasZero boolean?

Here's my first iteration (subsequently changed futher below).  All I did was 
rename {{hasNext}} to {{positioned}} (which I feel is more clear), added some 
inline comments for what the fields mean, and I added a leading check inside 
next(). So this was simpler than I thought.
{code:java}
/** Returns an iterator over the values in the set. */
  public LongIterator iterator() {
    return new LongIterator() {
      // if this set contains zero, this iterator's initial state is already 
positioned
      private boolean positioned = zeroCount > 0;
      private int i = -1; // current index into vals[]
      private long value = 0; // if positioned, this is our current value

      @Override
      public boolean hasNext() {
        if (positioned) {
          return true;
        }
        while (++i < vals.length) {
          value = vals[i];
          if (value != 0) {
            return positioned = true;
          }
        }
        return false;
      }

      @Override
      public long next() {
        if (!positioned) {
          if (!hasNext()) {
            throw new NoSuchElementException();
          }
        }
        positioned = false;
        return value;
      }

    };
  }
{code}

And here's what I think is the most clear approach using a countdown integer:
{code:java}

  /** Returns an iterator over the values in the set. */
  public LongIterator iterator() {
    return new LongIterator() {
      private int remainingValues = cardinality();
      private int valsIdx = 0;

      @Override
      public boolean hasNext() {
        return remainingValues > 0;
      }

      @Override
      public long next() {
        if (!hasNext()) {
          throw new NoSuchElementException();
        }
        remainingValues--;

        if (remainingValues == 0 && zeroCount > 0) {
          return 0;
        }
        
        while (true) { // guaranteed to find another value if we get here
          long value = vals[valsIdx++];
          if (value != 0) {
            return value;
          }
        }
      }

    };
{code}
This has the benefit that we don't loop past the last value of the array.  It 
also has fewer state variables. Also, you don't "pay" any advancement cost in 
hasNext(); it's only next() where the value is going to actually be consumed.

> implement Points/Numeric support for graph query
> ------------------------------------------------
>
>                 Key: SOLR-11093
>                 URL: https://issues.apache.org/jira/browse/SOLR-11093
>             Project: Solr
>          Issue Type: Bug
>      Security Level: Public(Default Security Level. Issues are Public) 
>            Reporter: Yonik Seeley
>            Assignee: Yonik Seeley
>             Fix For: 7.0
>
>         Attachments: SOLR-11093.patch, SOLR-11093.patch, SOLR-11093.patch
>
>
> It looks like GraphQueryTest only has tests for strings.  We should add tests 
> for numeric fields and then enable points randomization.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to