lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nigel Tao <n...@panscient.com>
Subject TermInfosReader.getIndexOffset javadoc and code inconsistent?
Date Thu, 20 May 2004 02:26:15 GMT
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


Mime
View raw message