Of course - if you don't plan to push this DISI into "uncontrolled land",
you can use the previous solution as well. I.e., if you never rely on docId
to know whether to start the iteration, and don't pass this DISI to Lucene
somehow etc., there's no need to use act or "adhere completely" to the API.

Otherwise, I agree, this looks to be the best solution.

Maybe ... just maybe ... I'd change the 'if (++act > last) act =
NO_MORE_DOCS' to 'if (++act < last) return doc = NO_MORE_DOCS' to avoid the
'act' assignment .. but since it will only happen once, I don't think it's
worth it.

On Thu, Jul 16, 2009 at 6:43 PM, Yonik Seeley <yo...@lucidimagination.com>wrote:

> Agreed - that looks like the optimal solution.
>
> -Yonik
> http://www.lucidimagination.com
>
> On Thu, Jul 16, 2009 at 11:40 AM, Uwe Schindler<u...@thetaphi.de> wrote:
> > OK, that makes sense: So the example of Yonik should be interpreted like
> > this (I think this is the optimal solution as it does not use an
> additional
> > if-clause to check if the iteration has already started):
> >
> >
> >
> > class SliceDocIdSetIterator extends DocIdSetIterator {
> >
> >  private int doc=-1,act,last;
> >
> >
> >
> >  public SliceDocIdSetIterator(int first, int last) {
> >
> >    this.act=first-1; this.last=last;
> >
> >  }
> >
> >
> >
> >  public int docID() {
> >
> >    return doc;
> >
> >  }
> >
> >
> >
> >  public int nextDoc() throws IOException {
> >
> >    if (++act>last) act=NO_MORE_DOCS;
> >
> >    return doc = act;
> >
> >  }
> >
> >
> >
> >  public int advance(int target) throws IOException {
> >
> >    act=target;
> >
> >    if (act>last) act=NO_MORE_DOCS;
> >
> >    return doc = act;
> >
> >  }
> >
> > }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-dev-h...@lucene.apache.org
>
>

Reply via email to