iverase commented on pull request #7:
URL: https://github.com/apache/lucene/pull/7#issuecomment-935900865


   > Would it be easy/cheap to know the accurate count?
   
   Actually I think we can do it pretty cheap taking into account that now we 
always build an unbalance tree and we can assume that all leaf nodes contain 
`maxPointsInLeafNode` except the last one that contains `pointCount % 
config.maxPointsInLeafNode`. 
   
   So if we consider:
   ``
   int  lastLeafNodeID = (1 << treeDepth - 1) - 1;
   int lastLeafNodePointCount = pointCount % config.maxPointsInLeafNode
   ``
   
   We can change how we compute size:
   
   ```
    public long size() {
         int leftMostLeafNode = nodeID;
         while (leftMostLeafNode < leafNodeOffset) {
           leftMostLeafNode = leftMostLeafNode * 2;
         }
         int rightMostLeafNode = nodeID;
         while (rightMostLeafNode < leafNodeOffset) {
           rightMostLeafNode = rightMostLeafNode * 2 + 1;
         }
         final int numLeaves;
         if (rightMostLeafNode >= leftMostLeafNode) {
           // both are on the same level
           numLeaves = rightMostLeafNode - leftMostLeafNode + 1;
         } else {
           // left is one level deeper than right
           numLeaves = rightMostLeafNode - leftMostLeafNode + 1 + 
leafNodeOffset;
         }
         assert numLeaves == getNumLeavesSlow(nodeID) : numLeaves + " " + 
getNumLeavesSlow(nodeID);
         return rightMostLeafNode == lastLeafNodeID
             ? (long) (numLeaves - 1) * config.maxPointsInLeafNode + 
lastLeafNodePointCount
             : (long) numLeaves * config.maxPointsInLeafNode;
       }
   ```
   


-- 
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