You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Nigel Tao <nt...@panscient.com> on 2004/05/20 04:26:15 UTC

TermInfosReader.getIndexOffset javadoc and code inconsistent?

This is a minor quibble, but are the javadocs and the code for
TermInfosReader.getIndexOffset(Term) inconsistent?  The javadocs say
"less than" but the code says "less than or equal to" (if the "return
mid" route is taken, which requires that term.compareTo(indexTerms[mid])
== 0).

But more importantly - does this impact any consumers of this method -
if, for example, they actually presume "less than" rather than "less
than or equal to"?

Also, this may be a strictly academic point, but should it be documented
that this method may return -1 if no index entry is <= term?  In
practice this is impossible since indexTerms[0] is always the empty Term
with "" field and "" text, which is less than (or equal to :-) any other
Term.

cheers,
Nigel.


-----------------------------------
/**
 * Returns the offset of the greatest index entry which is
 * less than term.
 */
private final int getIndexOffset(Term term) throws IOException
{
	// binary search indexTerms[]
	int lo = 0;
	int hi = indexTerms.length - 1;

	while (hi >= lo)
	{
		int mid = (lo + hi) >> 1;
		int delta = term.compareTo(indexTerms[mid]);
		if (delta < 0)
			hi = mid - 1;
		else if (delta > 0)
			lo = mid + 1;
		else
			return mid;
	}
	return hi;
}
-----------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Re: TermInfosReader.getIndexOffset javadoc and code inconsistent?

Posted by Christoph Goller <go...@detego-software.de>.
Nigel Tao wrote:
> This is a minor quibble, but are the javadocs and the code for
> TermInfosReader.getIndexOffset(Term) inconsistent?  The javadocs say
> "less than" but the code says "less than or equal to" (if the "return
> mid" route is taken, which requires that term.compareTo(indexTerms[mid])
> == 0).

You are right. I have fixed the Javadoc.

> 
> But more importantly - does this impact any consumers of this method -
> if, for example, they actually presume "less than" rather than "less
> than or equal to"?

Not as far as I know. I fact it was the reason for a recent bug in the
skipTo implementation that I fixed some weeks ago.

> 
> Also, this may be a strictly academic point, but should it be documented
> that this method may return -1 if no index entry is <= term?  In
> practice this is impossible since indexTerms[0] is always the empty Term
> with "" field and "" text, which is less than (or equal to :-) any other
> Term.

Propose an improved Javadoc and I will commit it.

You already dived quite deep into the code.
There is a lot to learn from Doug :-)

regards,
Christoph



---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org