multithreaded update
This commit is contained in:
parent
fdc783b87c
commit
2496741ec7
1 changed files with 23 additions and 14 deletions
19
src/lib.rs
19
src/lib.rs
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue