multithreaded update

This commit is contained in:
Joe 2025-10-17 17:21:35 -07:00
parent fdc783b87c
commit 2496741ec7

View file

@ -104,21 +104,30 @@ impl Spindex2d {
/// when constructing this index. May panic if the updated points argument is longer than the
/// original points.
pub fn update(&self, points: &[Point2d]) {
{
thread::scope(|s| {
s.spawn(|| {
let mut xs = self.xs.write().unwrap();
let mut ys = self.ys.write().unwrap();
let xpoints = self.xpoints.read().unwrap();
let ypoints = self.ypoints.read().unwrap();
for (i, point) in points.iter().enumerate() {
let xi = xpoints[i];
let yi = ypoints[i];
let x = PVal::new(i, point.x);
xs[xi] = x;
}
});
s.spawn(|| {
let mut ys = self.ys.write().unwrap();
let ypoints = self.ypoints.read().unwrap();
for (i, point) in points.iter().enumerate() {
let yi = ypoints[i];
let y = PVal::new(i, point.y);
ys[yi] = y;
}
}
});
});
self.sort();
}