Lower Layer impls to slice impls to fix clippy suggestion

This commit is contained in:
Dirkjan Ochtman 2021-01-20 18:25:29 +01:00
parent 2ab15e0c66
commit de38b64358
3 changed files with 9 additions and 9 deletions

View File

@ -10,7 +10,7 @@ benchmark_group!(benches, build_heuristic);
fn build_heuristic(bench: &mut Bencher) { fn build_heuristic(bench: &mut Bencher) {
let seed = ThreadRng::default().gen::<u64>(); let seed = ThreadRng::default().gen::<u64>();
let mut rng = StdRng::seed_from_u64(seed); let mut rng = StdRng::seed_from_u64(seed);
let points = (0..16384) let points = (0..1024)
.into_iter() .into_iter()
.map(|_| Point(rng.gen(), rng.gen())) .map(|_| Point(rng.gen(), rng.gen()))
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View File

@ -260,11 +260,11 @@ where
search.ef = if cur <= layer { ef_construction } else { 1 }; search.ef = if cur <= layer { ef_construction } else { 1 };
match cur > layer { match cur > layer {
true => { true => {
search.search(point, &layers[cur.0 - 1], &points, num); search.search(point, layers[cur.0 - 1].as_slice(), &points, num);
search.cull(); search.cull();
} }
false => { false => {
search.search(point, &zero, &points, num); search.search(point, zero.as_slice(), &points, num);
break; break;
} }
} }
@ -343,8 +343,8 @@ where
search.ef = ef; search.ef = ef;
match cur.0 { match cur.0 {
0 => search.search(point, &self.zero, &self.points, num), 0 => search.search(point, self.zero.as_slice(), &self.points, num),
l => search.search(point, &self.layers[l - 1], &self.points, num), l => search.search(point, self.layers[l - 1].as_slice(), &self.points, num),
} }
if !cur.is_zero() { if !cur.is_zero() {
@ -406,7 +406,7 @@ fn insert<P: Point>(
insertion.reset(); insertion.reset();
let candidate_point = &points[pid]; let candidate_point = &points[pid];
insertion.push(new, candidate_point, points); insertion.push(new, candidate_point, points);
for hop in (&*layer).nearest_iter(pid) { for hop in layer.as_slice().nearest_iter(pid) {
insertion.push(hop, candidate_point, points); insertion.push(hop, candidate_point, points);
} }
@ -537,7 +537,7 @@ impl Search {
fn select_heuristic<P: Point>( fn select_heuristic<P: Point>(
&mut self, &mut self,
layer: &Vec<ZeroNode>, layer: &[ZeroNode],
num: usize, num: usize,
point: &P, point: &P,
points: &[P], points: &[P],

View File

@ -69,7 +69,7 @@ impl UpperNode {
} }
} }
impl Layer for &Vec<UpperNode> { impl Layer for &[UpperNode] {
fn nearest_iter(&self, pid: PointId) -> NearestIter<'_> { fn nearest_iter(&self, pid: PointId) -> NearestIter<'_> {
NearestIter { NearestIter {
nearest: &self[pid.0 as usize].0, nearest: &self[pid.0 as usize].0,
@ -128,7 +128,7 @@ impl Deref for ZeroNode {
} }
} }
impl Layer for &Vec<ZeroNode> { impl Layer for &[ZeroNode] {
fn nearest_iter(&self, pid: PointId) -> NearestIter<'_> { fn nearest_iter(&self, pid: PointId) -> NearestIter<'_> {
NearestIter { NearestIter {
nearest: &self[pid.0 as usize].0, nearest: &self[pid.0 as usize].0,