From d314f33de39fd3b32d093c2fc2d59c0aeb92c655 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 2 Jul 2020 22:03:43 -0400 Subject: Preallocate the heap for k_nearest*() --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') 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 { } impl HeapNeighborhood { - /// 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 HeapNeighborhood { 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> { self.heap .into_sorted_vec() -- cgit v1.2.3