Skip to content

Commit

Permalink
Issue 429: Optimize ItemsPerSecond based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alecsmrekar committed Jan 10, 2024
1 parent 186de67 commit 3ccbbbc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,40 @@ impl ItemsPerSecond {
ItemsPerSecond(Default::default())
}

#[inline(always)]
fn initialize_or_increment(&mut self, key: &str, second: usize, value: u32) -> u32 {
if !self.0.contains_key(key) {
self.0.insert(key.to_string(), TimeSeries::new());
if !self.contains_key(key) {
self.insert(key, TimeSeries::new());
}
let data = self.0.get_mut(key).unwrap();
data.increase_value(second, value);
data.get(second)
}

#[inline(always)]
fn contains_key(&mut self, key: &str) -> bool {
self.0.contains_key(key)
}

#[inline(always)]
#[allow(dead_code)]
fn insert(&mut self, key: &str, time_series: TimeSeries<u32, u32>) {
self.0.insert(key.to_string(), time_series);
}

#[inline(always)]
#[allow(dead_code)]
fn len(&self) -> usize {
self.0.len()
}

#[inline(always)]
#[allow(dead_code)]
fn get(&self, key: &str) -> Option<TimeSeries<u32, u32>> {
self.0.get(key).cloned()
}

#[inline(always)]
fn get_map(&self) -> HashMap<String, TimeSeries<u32, u32>> {
self.0.clone()
}
Expand Down

0 comments on commit 3ccbbbc

Please sign in to comment.