Commit 93ab6b66 authored by Marco Perronet's avatar Marco Perronet
Browse files

Fix overflow on raspberry, remove update function

parent 8a9a17da
......@@ -20,9 +20,9 @@ impl Point {
#[derive(Debug, Clone)]
pub struct SparseMap {
pub buckets : Vec<LinkedList<Point>>,
pub count : usize,
pub capacity : usize,
pub bucket_size: usize,
pub bucket_size: u64,
pub count : u64,
}
impl SparseMap {
......@@ -36,7 +36,7 @@ impl SparseMap {
}
fn update_map(&mut self, p : Point, keep_monotonicity: bool) {
while p.delta as usize >= self.capacity*self.bucket_size {
while p.delta >= self.bucket_size * (self.capacity as u64) {
self.double_buckets();
}
......@@ -115,7 +115,7 @@ impl SparseMap {
}
pub fn get(&self, delta: Duration) -> Cost {
let max = (self.capacity * self.bucket_size) as u64;
let max = self.bucket_size * (self.capacity as u64);
if max <= delta { return 0; }
let mut bi = self.bucket_index_of(delta); // start with biggest bucket index that could contain the cost
......@@ -130,27 +130,8 @@ impl SparseMap {
}
}
pub fn update_cost(&mut self, delta: Duration, new_cost: Cost) -> Result<(), ()> {
let max = (self.capacity * self.bucket_size) as u64;
if max <= delta { return Err(()); }
let mut bi = self.bucket_index_of(delta); // start with biggest bucket index that could contain the cost
loop {
let b = &mut self.buckets[bi];
for el in b.iter_mut().rev() {
if el.delta == delta { // found
el.cost = new_cost;
return Ok(());
}
}
if bi == 0 { return Err(()); } // not found
bi -= 1;
}
}
pub fn bucket_index_of(&self, cost : Duration) -> usize {
return (cost as usize / self.bucket_size) as usize;
return (cost / self.bucket_size) as usize;
}
// Used when a new element cannot fit
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment