summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-07-02 22:03:43 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-07-02 22:05:36 -0400
commitd314f33de39fd3b32d093c2fc2d59c0aeb92c655 (patch)
tree814ab6da90a8628123cdef442231ee4ed6e81c23
parent061c1973ad72bf37f72f1a7ca77ee2bc2ae08313 (diff)
downloadacap-d314f33de39fd3b32d093c2fc2d59c0aeb92c655.tar.xz
Preallocate the heap for k_nearest*()
-rw-r--r--src/lib.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 8041d28..4792dbb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -274,7 +274,7 @@ struct HeapNeighborhood<K, V, D> {
}
impl<K, V, D: PartialOrd> HeapNeighborhood<K, V, D> {
- /// Create a new singleton neighborhood.
+ /// Create a new HeapNeighborhood.
///
/// * `target`: The search target.
/// * `k`: The number of nearest neighbors to find.
@@ -284,11 +284,11 @@ impl<K, V, D: PartialOrd> HeapNeighborhood<K, V, D> {
target,
k,
threshold,
- heap: BinaryHeap::new(),
+ heap: BinaryHeap::with_capacity(k),
}
}
- /// Convert this result into an optional neighbor.
+ /// Extract the results from this neighborhood.
fn into_vec(self) -> Vec<Neighbor<V, D>> {
self.heap
.into_sorted_vec()