multithread the creation of the index
This commit is contained in:
parent
dec3ea0e60
commit
fdc783b87c
1 changed files with 22 additions and 12 deletions
20
src/lib.rs
20
src/lib.rs
|
@ -65,22 +65,32 @@ pub struct Spindex2d {
|
||||||
impl Spindex2d {
|
impl Spindex2d {
|
||||||
pub fn new(points: &[Point2d]) -> Self {
|
pub fn new(points: &[Point2d]) -> Self {
|
||||||
let mut xpoints = Vec::with_capacity(points.len());
|
let mut xpoints = Vec::with_capacity(points.len());
|
||||||
let mut ypoints = Vec::with_capacity(points.len());
|
|
||||||
let mut xs = Vec::with_capacity(points.len());
|
let mut xs = Vec::with_capacity(points.len());
|
||||||
|
|
||||||
|
let mut ypoints = Vec::with_capacity(points.len());
|
||||||
let mut ys = Vec::with_capacity(points.len());
|
let mut ys = Vec::with_capacity(points.len());
|
||||||
|
|
||||||
|
thread::scope(|s| {
|
||||||
|
s.spawn(|| {
|
||||||
for (i, point) in points.iter().enumerate() {
|
for (i, point) in points.iter().enumerate() {
|
||||||
let x = PVal::new(i, point.x);
|
let x = PVal::new(i, point.x);
|
||||||
xs.push(x);
|
xs.push(x);
|
||||||
|
xpoints.push(i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
s.spawn(|| {
|
||||||
|
for (i, point) in points.iter().enumerate() {
|
||||||
let y = PVal::new(i, point.y);
|
let y = PVal::new(i, point.y);
|
||||||
ys.push(y);
|
ys.push(y);
|
||||||
|
|
||||||
xpoints.push(i);
|
|
||||||
ypoints.push(i);
|
ypoints.push(i);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
let index = Self {
|
let index = Self {
|
||||||
xpoints: Arc::new(xpoints.into()),
|
xpoints: Arc::new(RwLock::new(xpoints)),
|
||||||
ypoints: Arc::new(ypoints.into()),
|
ypoints: Arc::new(RwLock::new(ypoints)),
|
||||||
xs: Arc::new(RwLock::new(xs)),
|
xs: Arc::new(RwLock::new(xs)),
|
||||||
ys: Arc::new(RwLock::new(ys)),
|
ys: Arc::new(RwLock::new(ys)),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue