Reduce reallocation of vectors.
This commit is contained in:
@@ -24,9 +24,6 @@ where
|
|||||||
T: Table<R>,
|
T: Table<R>,
|
||||||
R: Record<K> + Debug,
|
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`
|
// 1. Retrieve a list of distinct values for the coordinate `dimension`
|
||||||
let mut distinct = vec![];
|
let mut distinct = vec![];
|
||||||
let records = table.get_table();
|
let records = table.get_table();
|
||||||
@@ -57,13 +54,16 @@ where
|
|||||||
// result as this is the max number of elements per bucket.
|
// result as this is the max number of elements per bucket.
|
||||||
let max_offset = (distinct.len() / (1 << cell_bits)) + 1;
|
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 {
|
for coordinate in distinct {
|
||||||
//trace!("{:?} {:?} {:?} {:?}", dimension, coordinate, cell, count);
|
//trace!("{:?} {:?} {:?} {:?}", dimension, coordinate, cell, count);
|
||||||
|
|
||||||
if count == max_offset {
|
if count == max_offset {
|
||||||
count = 0;
|
count = 0;
|
||||||
cell += 1;
|
cell += 1;
|
||||||
cells.push(vec![]);
|
cells.push(Vec::with_capacity(max_offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
cells[cell].push(coordinate);
|
cells[cell].push(coordinate);
|
||||||
|
|||||||
Reference in New Issue
Block a user