func nearestNeighbours(target uint64, items []Item, k int) (coords []Item, distances []float64) {
	pq := &priorityQueue{}

	// Push all items onto a heap
	for _, v := range items {
		d := hamming(v.Sig, target)
		heap.Push(pq, &heapItem{v, d})
	}

	// Pop all but the k smallest items
	for pq.Len() > k {
		heap.Pop(pq)
	}

	// Extract the k smallest items and distances
	for pq.Len() > 0 {
		hi := heap.Pop(pq)
		coords = append(coords, hi.(*heapItem).Item)
		distances = append(distances, hi.(*heapItem).Dist)
	}

	// Reverse coords and distances, because we popped them from the heap
	// in large-to-small order
	for i, j := 0, len(coords)-1; i < j; i, j = i+1, j-1 {
		coords[i], coords[j] = coords[j], coords[i]
		distances[i], distances[j] = distances[j], distances[i]
	}

	return
}
// This helper function finds the k nearest neighbours of target in items. It's
// slower than the VPTree, but its correctness is easy to verify, so we can
// test the VPTree against it.
This helper function finds the k nearest neighbours of target in items. It's
slower than the VPTree, but its correctness is easy to verify, so we can
test the VPTree against it.
// This helper function finds the k nearest neighbours of target in items . It ' s // slower than the VPTree but its correctness is easy to verify so we can // test the VPTree against it .
func nearestNeighbours(target uint64, items []Item, k int) (coords []Item, distances []float64) {
	pq := &priorityQueue{}
	for _, v := range items {
		d := hamming(v.Sig, target)
		heap.Push(pq, &heapItem{v, d})
	}
	for pq.Len() > k {
		heap.Pop(pq)
	}
	for pq.Len() > 0 {
		hi := heap.Pop(pq)
		coords = append(coords, hi.(*heapItem).Item)
		distances = append(distances, hi.(*heapItem).Dist)
	}
	for i, j := 0, len(coords)-1; i < j; i, j = i+1, j-1 {
		coords[i], coords[j] = coords[j], coords[i]
		distances[i], distances[j] = distances[j], distances[i]
	}
	return
}
func nearestNeighbours ( target uint64 , items [ ] Item , k int ) ( coords [ ] Item , distances [ ] float64 ) { pq := & priorityQueue { } for _ , v := range items { d := hamming ( v . Sig , target ) heap . Push ( pq , & heapItem { v , d } ) } for pq . Len ( ) > k { heap . Pop ( pq ) } for pq . Len ( ) > 0 { hi := heap . Pop ( pq ) coords = append ( coords , hi . ( * heapItem ) . Item ) distances = append ( distances , hi . ( * heapItem ) . Dist ) } for i , j := 0 , len ( coords ) - 1 ; i < j ; i , j = i + 1 , j - 1 { coords [ i ] , coords [ j ] = coords [ j ] , coords [ i ] distances [ i ] , distances [ j ] = distances [ j ] , distances [ i ] } return }
This helper function finds the k nearest neighbours of target in items.
This helper function finds the k nearest neighbours of target in items .
// Push all items onto a heap // Pop all but the k smallest items // Extract the k smallest items and distances // Reverse coords and distances, because we popped them from the heap // in large-to-small order