From d66a84eaf7d7eb4485d65884be5531c36315bfb5 Mon Sep 17 00:00:00 2001 From: Lionel Sambuc Date: Wed, 13 Nov 2019 16:28:49 +0100 Subject: [PATCH] Remove size optimisation for values indices. --- src/database/db_core.rs | 8 +++----- src/database/space_index.rs | 18 +++++++++--------- src/json/model.rs | 6 +++--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/database/db_core.rs b/src/database/db_core.rs index 0079e73..4a15d35 100644 --- a/src/database/db_core.rs +++ b/src/database/db_core.rs @@ -199,7 +199,7 @@ impl Core { let mut r = s .get_by_positions(&p, parameters)? .into_iter() - .map(|(position, fields)| (position, &self.properties[fields.value().as_usize()])) + .map(|(position, fields)| (position, &self.properties[fields.value()])) .collect::>(); Self::decode_positions(r.as_mut_slice(), to, db, output_space)?; @@ -239,7 +239,7 @@ impl Core { let mut r = s .get_by_shape(¤t_shape, parameters)? .into_iter() - .map(|(position, fields)| (position, &self.properties[fields.value().as_usize()])) + .map(|(position, fields)| (position, &self.properties[fields.value()])) .collect::>(); Self::decode_positions(r.as_mut_slice(), current_space, db, output_space)?; @@ -374,9 +374,7 @@ impl Core { let mut r = s .get_by_positions(&p, parameters)? .into_iter() - .map(|(position, fields)| { - (position, &self.properties[fields.value().as_usize()]) - }) + .map(|(position, fields)| (position, &self.properties[fields.value()])) .collect::>(); Self::decode_positions(r.as_mut_slice(), to, db, output_space)?; diff --git a/src/database/space_index.rs b/src/database/space_index.rs index 2f6bc6b..7c921b6 100644 --- a/src/database/space_index.rs +++ b/src/database/space_index.rs @@ -10,11 +10,11 @@ use super::space::Shape; pub struct SpaceSetObject { space_id: String, position: Position, - value: Coordinate, // Efficiently store the offset within the SpaceDB values vector + value: usize, } impl SpaceSetObject { - pub fn new(reference_space: &str, position: Position, value: Coordinate) -> Self { + pub fn new(reference_space: &str, position: Position, value: usize) -> Self { SpaceSetObject { space_id: reference_space.into(), position, @@ -34,11 +34,11 @@ impl SpaceSetObject { self.position = pos; } - pub fn value(&self) -> &Coordinate { - &self.value + pub fn value(&self) -> usize { + self.value } - pub fn set_value(&mut self, value: Coordinate) { + pub fn set_value(&mut self, value: usize) { self.value = value; } } @@ -46,7 +46,7 @@ impl SpaceSetObject { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SpaceFields { space_id: String, - value: Coordinate, + value: usize, } impl SpaceFields { @@ -57,11 +57,11 @@ impl SpaceFields { } } - pub fn value(&self) -> &Coordinate { - &self.value + pub fn value(&self) -> usize { + self.value } - pub fn set_value(&mut self, value: Coordinate) { + pub fn set_value(&mut self, value: usize) { self.value = value; } } diff --git a/src/json/model.rs b/src/json/model.rs index 658bd9a..7a43cca 100644 --- a/src/json/model.rs +++ b/src/json/model.rs @@ -198,7 +198,7 @@ pub fn build_index( &point.reference_space, // Use a reference to prevent an allocation (&point.vertices[0]).into(), - value.into(), + value, )) } } @@ -209,9 +209,9 @@ pub fn build_index( properties.sort_unstable_by(|a, b| a.id().cmp(b.id())); space_set_objects.iter_mut().for_each(|object| { - let id = properties_ref[object.value().u64() as usize]; + let id = properties_ref[object.value()]; let value = properties.binary_search_by_key(&id, |p| p.id()).unwrap(); - object.set_value(value.into()); + object.set_value(value); }); Core::new(