Skip to content

Commit a9cb858

Browse files
committed
add comments
1 parent 1b4d3d7 commit a9cb858

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

s2/cell_index.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ func (c *CellIndex) Build() {
529529
}
530530
}
531531

532+
// IntersectingLabels is a convenience function that returns
533+
// the labels of all indexed cells that intersect the given CellUnion "target".
532534
func (c *CellIndex) IntersectingLabels(target CellUnion) []int32 {
533535
var labels labels
534536
c.VisitIntersectingCells(target, func(cellID CellID, label int32) bool {
@@ -563,6 +565,10 @@ func (c *CellIndex) VisitIntersectingCells(target CellUnion, visitor cellVisitor
563565
}
564566
}
565567

568+
// Check whether the next target cell is also contained by the leaf cell
569+
// range that we just processed. If so, we can skip over all such cells
570+
// using binary search. This speeds up benchmarks by between 2x and 10x
571+
// when the average number of intersecting cells is small (< 1).
566572
pos++
567573
if pos != len(target) && target[pos].RangeMax() < rangeIter.StartID() {
568574
pos = target.lowerBound(pos+1, len(target), rangeIter.StartID())

0 commit comments

Comments
 (0)