Compare commits
2 Commits
49f4462b36
...
bac9d395ff
| Author | SHA1 | Date | |
|---|---|---|---|
| bac9d395ff | |||
| ad9339f53d |
@@ -24,9 +24,6 @@ where
|
||||
T: Table<R>,
|
||||
R: Record<K> + Debug,
|
||||
{
|
||||
// Do not forget to initialise cells[0]
|
||||
let mut cells: Vec<Cell<V>> = vec![vec![]];
|
||||
|
||||
// 1. Retrieve a list of distinct values for the coordinate `dimension`
|
||||
let mut distinct = vec![];
|
||||
let records = table.get_table();
|
||||
@@ -57,13 +54,16 @@ where
|
||||
// result as this is the max number of elements per bucket.
|
||||
let max_offset = (distinct.len() / (1 << cell_bits)) + 1;
|
||||
|
||||
// Do not forget to initialise cells[0]
|
||||
let mut cells: Vec<Cell<V>> = Vec::with_capacity(1 << cell_bits);
|
||||
|
||||
for coordinate in distinct {
|
||||
//trace!("{:?} {:?} {:?} {:?}", dimension, coordinate, cell, count);
|
||||
|
||||
if count == max_offset {
|
||||
count = 0;
|
||||
cell += 1;
|
||||
cells.push(vec![]);
|
||||
cells.push(Vec::with_capacity(max_offset));
|
||||
}
|
||||
|
||||
cells[cell].push(coordinate);
|
||||
@@ -176,8 +176,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn value(&self, cell_id: usize, offset: usize) -> V {
|
||||
self.table[cell_id][offset].clone()
|
||||
fn value(&self, cell_id: usize, offset: usize) -> &V {
|
||||
&self.table[cell_id][offset]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ where
|
||||
Ok((cells, offsets))
|
||||
}
|
||||
|
||||
pub fn value(&self, cells_id: Vec<usize>, offsets: Vec<usize>) -> Result<Vec<V>, String> {
|
||||
pub fn value(&self, cells_id: Vec<usize>, offsets: Vec<usize>) -> Result<Vec<&V>, String> {
|
||||
//TODO: Should we check inside each objects, or just assume it is correct and/or rely on the bound checks?
|
||||
if self.dimensions != cells_id.len() {
|
||||
return Err(format!(
|
||||
|
||||
14
src/sfc.rs
14
src/sfc.rs
@@ -34,9 +34,9 @@ struct Limit<V> {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Limits<V> {
|
||||
start: Limit<V>,
|
||||
end: Limit<V>,
|
||||
struct Limits<'a, V> {
|
||||
start: Limit<&'a V>,
|
||||
end: Limit<&'a V>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
@@ -187,9 +187,9 @@ where
|
||||
|
||||
// Rebuild a specific record
|
||||
fn get_record(&self, code: SFCCode, entry: &SFCRecord<F>) -> Result<R, String> {
|
||||
let position = self.position(code, &entry.offsets)?;
|
||||
let position = &self.position(code, &entry.offsets)?;
|
||||
|
||||
Ok(R::build(&position, &entry.fields))
|
||||
Ok(R::build(position, &entry.fields))
|
||||
}
|
||||
|
||||
fn limits(&self, start: &K, end: &K) -> Result<Limits<V>, String> {
|
||||
@@ -290,8 +290,8 @@ where
|
||||
// FIXME: Reduce number of comparison by using the cells boundaries.
|
||||
for k in 0..self.dimensions {
|
||||
select = select
|
||||
&& limits.start.position[k] <= pos[k]
|
||||
&& limits.end.position[k] >= pos[k];
|
||||
&& *limits.start.position[k] <= pos[k]
|
||||
&& *limits.end.position[k] >= pos[k];
|
||||
}
|
||||
if select {
|
||||
match self.get_record(code, &record) {
|
||||
|
||||
Reference in New Issue
Block a user