Skip to content

Commit

Permalink
Removed parallel bulk loading for better maintainability.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stoeoef committed Apr 7, 2019
1 parent 746f1de commit eae7354
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 236 deletions.
1 change: 0 additions & 1 deletion rstar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ maintenance = { status = "actively-developed" }
[dependencies]
num-traits = "0.2"
pdqselect = "0.1"
threadpool = { version = "1.7", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }

[features]
Expand Down
104 changes: 0 additions & 104 deletions rstar/src/algorithm/bulk_load/bulk_load_parallel.rs

This file was deleted.

54 changes: 53 additions & 1 deletion rstar/src/algorithm/bulk_load/bulk_load_sequential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::object::RTreeObject;
use crate::params::RTreeParams;
use crate::point::Point;

use super::bulk_load_common::{calculate_number_of_clusters_on_axis, ClusterGroupIterator};
use super::cluster_group_iterator::{calculate_number_of_clusters_on_axis, ClusterGroupIterator};

fn bulk_load_recursive<T, Params>(elements: Vec<T>, depth: usize) -> ParentNodeData<T>
where
Expand Down Expand Up @@ -94,3 +94,55 @@ where
let depth = (elements.len() as f32).log(m as f32).ceil() as usize;
bulk_load_recursive::<_, Params>(elements, depth)
}

#[cfg(test)]
mod test {
use crate::test_utilities::*;
use crate::{Point, RTree, RTreeObject};
use std::collections::HashSet;
use std::fmt::Debug;
use std::hash::Hash;

#[test]
fn test_bulk_load_small() {
let random_points = create_random_integers::<[i32; 2]>(50, SEED_1);
create_and_check_bulk_loading_with_points(&random_points);
}

#[test]
fn test_bulk_load_large() {
let random_points = create_random_integers::<[i32; 2]>(3000, SEED_1);
create_and_check_bulk_loading_with_points(&random_points);
}

#[test]
fn test_bulk_load_with_different_sizes() {
for size in (0..100).map(|i| i * 7) {
test_bulk_load_with_size_and_dimension::<[i32; 2]>(size);
test_bulk_load_with_size_and_dimension::<[i32; 3]>(size);
test_bulk_load_with_size_and_dimension::<[i32; 4]>(size);
}
}

fn test_bulk_load_with_size_and_dimension<P>(size: usize)
where
P: Point<Scalar = i32> + RTreeObject + Send + Sync + Eq + Clone + Debug + Hash + 'static,
P::Envelope: Send + Sync,
{
let random_points = create_random_integers::<P>(size, SEED_1);
create_and_check_bulk_loading_with_points(&random_points);
}

fn create_and_check_bulk_loading_with_points<P>(points: &[P])
where
P: RTreeObject + Send + Sync + Eq + Clone + Debug + Hash + 'static,
P::Envelope: Send + Sync,
{
let tree = RTree::bulk_load(points.into());
let set1: HashSet<_> = tree.iter().collect();
let set2: HashSet<_> = points.iter().collect();
assert_eq!(set1, set2);
assert_eq!(tree.size(), points.len());
}

}
69 changes: 0 additions & 69 deletions rstar/src/algorithm/bulk_load/bulk_load_tests.rs

This file was deleted.

9 changes: 1 addition & 8 deletions rstar/src/algorithm/bulk_load/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
mod bulk_load_common;
#[cfg(feature = "threadpool")]
mod bulk_load_parallel;
mod bulk_load_sequential;
mod cluster_group_iterator;

#[cfg(test)]
mod bulk_load_tests;

#[cfg(feature = "threadpool")]
pub use self::bulk_load_parallel::bulk_load_parallel;
pub use self::bulk_load_sequential::bulk_load_sequential;
1 change: 1 addition & 0 deletions rstar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//! Enable the `serde` feature for [Serde](https://crates.io/crates/serde) support.
//!
#![deny(missing_docs)]
#![deny(unsafe_code)]

mod aabb;
mod algorithm;
Expand Down
54 changes: 1 addition & 53 deletions rstar/src/rtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ where
/// This method implements the overlap minimizing top down bulk loading algorithm
/// as described in [this paper](http://ceur-ws.org/Vol-74/files/FORUM_18.pdf).
///
/// There is also a [multi threaded variant](#method.bulk_load_parallel)
/// of this method if the `threadpool`
/// feature is enabled.
///
/// # Runtime
/// Bulk loading runs in `O(n * log(n))`, where `n` is the number of loaded
/// elements.
Expand All @@ -229,52 +225,6 @@ where
}
}

#[cfg(feature = "threadpool")]
impl<T> RTree<T>
where
T: RTreeObject + Send + Sync + 'static,
T::Envelope: Send + Sync,
{
/// Creates a new r-tree with some elements already inserted.
///
/// See [bulk_load](#method.bulk_load) for general information.
/// This method performs the loading on multiple threads in parallel.
/// However, as there is some synchronization overhead, this method may
/// perform slower for only a few objects. The break even point may be around
/// 40000 elements but will vary depending on the number of available cores.
///
/// # Runtime
/// Bulk loading runs in `O(n * log(n))`, where `n` is the number of loaded
/// elements.
pub fn bulk_load_parallel(elements: Vec<T>) -> Self {
Self::bulk_load_with_params_parallel(elements)
}
}

#[cfg(feature = "threadpool")]
impl<T, Params> RTree<T, Params>
where
Params: RTreeParams,
T: RTreeObject + Send + Sync + 'static,
T::Envelope: Send + Sync,
{
/// Creates a new r-tree with some elements already inserted and configurable parameters.
///
/// See [bulk_load_with_params](#method.bulk_load_with_params) for general information.
/// This method performs the loading on multiple threads in parallel.
/// However, as there is some synchronization overhead, this method may
/// perform slower for only a few objects. The break even point may be around
/// 40000 elements but will vary depending on the number of available cores
/// and the used rtree parameters.
///
/// # Runtime
/// Bulk loading runs in `O(n * log(n))`, where `n` is the number of loaded
/// elements.
pub fn bulk_load_with_params_parallel(elements: Vec<T>) -> Self {
Self::new_from_bulk_loading(elements, bulk_load::bulk_load_parallel::<_, Params>)
}
}

impl<T, Params> RTree<T, Params>
where
Params: RTreeParams,
Expand All @@ -296,9 +246,7 @@ where
/// Creates a new r-tree with some given elements and configurable parameters.
///
/// For more information refer to [bulk_load](#method.bulk_load)
/// and [RTreeParameters](traits.RTreeParameters.html). There is also a [multi threaded
/// variant](#method.bulk_load_with_params_parallel) of this method if the `threadpool`
/// feature is enabled.
/// and [RTreeParameters](traits.RTreeParameters.html).
pub fn bulk_load_with_params(elements: Vec<T>) -> Self {
Self::new_from_bulk_loading(elements, bulk_load::bulk_load_sequential::<_, Params>)
}
Expand Down

0 comments on commit eae7354

Please sign in to comment.