-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic app resampling and better performance measurements. #6595
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
64c8dd3
Implementing time measurements
wdanilo 83956d9
Refactoring
wdanilo b674866
Adding to perf monitor option to display missing values
wdanilo ca3dbe0
Refactoring
wdanilo fda368d
Refactoring
wdanilo 203c84d
fmt
wdanilo 5de2746
Merge branch 'develop' into wip/wd/dynamic-app-resampling
wdanilo cc55b76
Fixing time measurements
wdanilo bc0cefb
Merge branch 'develop' into wip/wd/dynamic-app-resampling
wdanilo 453c194
Refactoring
wdanilo 25691b4
Fixing typos
wdanilo d7b5a6a
Minor fixes
wdanilo a180496
bump size limit
wdanilo 25f61aa
Lint
wdanilo f04f6c8
Merge branch 'develop' into wip/wd/dynamic-app-resampling
wdanilo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,96 @@ | ||||||
//! Definition of a circular vector, a vector with a constant max size, that if full, keeps its | ||||||
//! element in a loop. | ||||||
|
||||||
use std::collections::VecDeque; | ||||||
|
||||||
|
||||||
|
||||||
/// A vector with a constant max size, that if full, keeps its element in a loop. | ||||||
#[derive(Clone, Debug)] | ||||||
pub struct CircularVecDeque<T> { | ||||||
capacity: usize, | ||||||
vec: VecDeque<T>, | ||||||
} | ||||||
|
||||||
impl<T> CircularVecDeque<T> { | ||||||
/// Constructor. | ||||||
pub fn new(capacity: usize) -> Self { | ||||||
let vec = VecDeque::with_capacity(capacity); | ||||||
Self { capacity, vec } | ||||||
} | ||||||
|
||||||
/// Check whether the vector is empty. | ||||||
pub fn is_empty(&self) -> bool { | ||||||
self.vec.is_empty() | ||||||
} | ||||||
|
||||||
/// The capacity of the vector. | ||||||
pub fn len(&self) -> usize { | ||||||
self.vec.len() | ||||||
} | ||||||
|
||||||
/// Check whether the vector is full. | ||||||
pub fn is_full(&self) -> bool { | ||||||
self.len() == self.capacity | ||||||
} | ||||||
|
||||||
/// Push a new element at the beginning of the vector. if the vector is full, the last element | ||||||
/// will be dropped. | ||||||
pub fn push_front(&mut self, value: T) { | ||||||
if self.is_full() { | ||||||
self.vec.pop_back(); | ||||||
} | ||||||
self.vec.push_front(value); | ||||||
} | ||||||
|
||||||
/// Push a new element at the end of the vector. if the vector is full, the first element will | ||||||
/// be dropped. | ||||||
pub fn push_back(&mut self, value: T) { | ||||||
if self.is_full() { | ||||||
self.vec.pop_front(); | ||||||
} | ||||||
self.vec.push_back(value); | ||||||
} | ||||||
|
||||||
/// Pop the first element of the vector. | ||||||
pub fn pop_front(&mut self) -> Option<T> { | ||||||
self.vec.pop_front() | ||||||
} | ||||||
|
||||||
/// Pop the last element of the vector. | ||||||
pub fn pop_back(&mut self) -> Option<T> { | ||||||
self.vec.pop_back() | ||||||
} | ||||||
|
||||||
/// Get the element at the given index. | ||||||
pub fn get(&self, index: usize) -> Option<&T> { | ||||||
self.vec.get(index) | ||||||
} | ||||||
|
||||||
/// Get a mutable reference to the element at the given index. | ||||||
pub fn get_mut(&mut self, index: usize) -> Option<&mut T> { | ||||||
self.vec.get_mut(index) | ||||||
} | ||||||
|
||||||
/// get the last element of the vector, if any. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
pub fn last(&self) -> Option<&T> { | ||||||
self.vec.back() | ||||||
} | ||||||
|
||||||
/// Run the provided function on the last `n` elements of the vector. | ||||||
pub fn with_last_n_elems(&mut self, n: usize, mut f: impl FnMut(&mut T)) { | ||||||
let len = self.len(); | ||||||
let start = len.saturating_sub(n); | ||||||
for i in start..len { | ||||||
f(self.vec.get_mut(i).unwrap()); | ||||||
} | ||||||
} | ||||||
|
||||||
/// Run the provided function on the `n`-th element of the vector counted from back. | ||||||
pub fn with_last_nth_elem(&mut self, n: usize, f: impl FnOnce(&mut T)) { | ||||||
let len = self.len(); | ||||||
if len > n { | ||||||
f(self.vec.get_mut(len - n - 1).unwrap()); | ||||||
} | ||||||
} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this line. It does not
keep
elements, but rather drops the old ones when the capacity is full, doesn't it?