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