mirror of https://github.com/apache/lucene.git
LUCENE-3037: calculate log with integer math
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1095147 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8906ff3cc2
commit
4a20fa5782
|
@ -184,10 +184,19 @@ public abstract class MultiLevelSkipListReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** returns x == 0 ? 0 : Math.floor(Math.log(x) / Math.log(base)) */
|
||||||
|
static int log(int x, int base) {
|
||||||
|
int ret = 0;
|
||||||
|
while (x >= base) {
|
||||||
|
x /= base;
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/** Loads the skip levels */
|
/** Loads the skip levels */
|
||||||
private void loadSkipLevels() throws IOException {
|
private void loadSkipLevels() throws IOException {
|
||||||
// TODO: would be preferable to use integer math here instead.
|
numberOfSkipLevels = log(docCount, skipInterval[0]);
|
||||||
numberOfSkipLevels = docCount == 0 ? 0 : (int) Math.floor(StrictMath.log(docCount) / StrictMath.log(skipInterval[0]));
|
|
||||||
if (numberOfSkipLevels > maxNumberOfSkipLevels) {
|
if (numberOfSkipLevels > maxNumberOfSkipLevels) {
|
||||||
numberOfSkipLevels = maxNumberOfSkipLevels;
|
numberOfSkipLevels = maxNumberOfSkipLevels;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,7 @@ public abstract class MultiLevelSkipListWriter {
|
||||||
this.skipInterval = skipInterval;
|
this.skipInterval = skipInterval;
|
||||||
|
|
||||||
// calculate the maximum number of skip levels for this document frequency
|
// calculate the maximum number of skip levels for this document frequency
|
||||||
// TODO: would be preferable to use integer math here instead.
|
numberOfSkipLevels = MultiLevelSkipListReader.log(df, skipInterval);
|
||||||
numberOfSkipLevels = df == 0 ? 0 : (int) Math.floor(StrictMath.log(df) / StrictMath.log(skipInterval));
|
|
||||||
|
|
||||||
// make sure it does not exceed maxSkipLevels
|
// make sure it does not exceed maxSkipLevels
|
||||||
if (numberOfSkipLevels > maxSkipLevels) {
|
if (numberOfSkipLevels > maxSkipLevels) {
|
||||||
|
|
Loading…
Reference in New Issue