mikemccand commented on code in PR #12653:
URL: https://github.com/apache/lucene/pull/12653#discussion_r1365692736


##########
lucene/core/src/java/org/apache/lucene/codecs/MultiLevelSkipListWriter.java:
##########
@@ -63,24 +63,23 @@ public abstract class MultiLevelSkipListWriter {
   /** for every skip level a different buffer is used */
   private ByteBuffersDataOutput[] skipBuffer;
 
+  /** Length of the window at which the skips are placed on skip level 1 */
+  private final long windowLength;
+
   /** Creates a {@code MultiLevelSkipListWriter}. */
   protected MultiLevelSkipListWriter(
       int skipInterval, int skipMultiplier, int maxSkipLevels, int df) {
     this.skipInterval = skipInterval;
     this.skipMultiplier = skipMultiplier;
 
-    int numberOfSkipLevels;
+    int numberOfSkipLevels = 1;
     // calculate the maximum number of skip levels for this document frequency
-    if (df <= skipInterval) {
-      numberOfSkipLevels = 1;
-    } else {
-      numberOfSkipLevels = 1 + MathUtil.log(df / skipInterval, skipMultiplier);
-    }
-
-    // make sure it does not exceed maxSkipLevels
-    if (numberOfSkipLevels > maxSkipLevels) {
-      numberOfSkipLevels = maxSkipLevels;
+    if (df > skipInterval) {
+      // also make sure it does not exceed maxSkipLevels
+      numberOfSkipLevels =
+          Math.min(1 + MathUtil.log(df / skipInterval, skipMultiplier), 
maxSkipLevels);
     }

Review Comment:
   Well, there is no hard standard in Lucene or anything (that I am aware of).  
I just generally prefer "write once" to variables like this (write in the if, 
write in the else) instead of always writing a value, and then sometimes 
overwriting it.  I do feel it's more readable?  In the first way, when I glance 
at the code, it looks at first like `numberOfSkipLevels` is always set to `1`, 
and I might miss (on first glance) the `if` that then overwrites it with a new 
values?  It also makes `final` possible.  (Hmm in your previous approach this 
instance variable was also final?  And `javac` did not complain that it was 
being assigned twice?  Curious...).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to