Skip to content

Commit

Permalink
lsh: only stop early for 1-NN
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Oct 10, 2024
1 parent e728441 commit ed9b0db
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lsh/nearest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func Nearest(data []uint64, bucketIDs []uint64, buckets map[uint64]slice.IndexRa
numExamined := exactBucket.Length
nearestInBucket(data, exactBucket, k, x, &distances[0], &dataHeap)

// if the exact bucket already contains k neighbors, stop and return them
if dataHeap.Len() == k {
// stop early for 1-NN
if k == 1 && dataHeap.Len() == k {
return k, exactBucket.Length
}

Expand Down
1 change: 1 addition & 0 deletions lsh/nearest_wide.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func NearestWide(data [][]uint64, bucketIDs []uint64, buckets map[uint64]slice.I
exactBucket := buckets[xh]
numExamined := exactBucket.Length
nearestWideInBucket(data, exactBucket, k, x, &distances[0], &dataHeap)

// stop early for 1-NN
if k == 1 && dataHeap.Len() == k {
return k, exactBucket.Length
Expand Down

0 comments on commit ed9b0db

Please sign in to comment.