-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HistoryBuffer<T> flipped push_back<->push_front naming
should (hopefully) simplify and provide a more intuitive the naming. ### Storage - Dynamic (`N == std::dynamic_extent`): uses `std::vector<T>` (size = 2 * capacity). - Fixed (`N != std::dynamic_extent`): uses `std::array<T, N * 2>`. ### Key Operations - `push_front(const T&)`: Add new item, drop oldest if full, index `[0]` is newest. - `push_back(const T&)`: Add new item, drop oldest if full, index `[0]` is oldest. - `pop_front()`, `pop_back()`: Remove from logical front/back of the ring. - `front()`, `back()`: Returns the first/last item in logical order. - `operator[](i)`, `at(i)`: Unchecked/checked access. - `resize(...)` (dynamic-only): Adjust capacity, preserving existing data. - `get_span(...)`: Obtain a contiguous view across wrap boundaries. ### Code Examples ```cpp gr::history_buffer<int, 5> hb_newest; // use push_front -> index[0] is newest hb_newest.push_front(1); // [1] hb_newest.push_front(2); // [2, 1] hb_newest.push_front(3); // [3, 2, 1] // => index[0] == 3, newest item gr::history_buffer<int, 5> hb_oldest; // use push_back -> index[0] is oldest hb_oldest.push_back(10); // [10] hb_oldest.push_back(20); // [10, 20] hb_oldest.push_back(30); // [10, 20, 30] // => index[0] == 10, oldest item hb_newest.pop_front(); // remove newest => now hb_newest: [2, 1] hb_oldest.pop_front(); // remove oldest => now hb_oldest: [20, 30] auto val = hb_newest.front(); // val == 2 auto last = hb_newest.back(); // last == 1 ``` Also added/extended te `HistoryBuffer<T>` performance benchmark Signed-off-by: rstein <r.steinhagen@gsi.de> Signed-off-by: Ralph J. Steinhagen <r.steinhagen@gsi.de> Signed-off-by: rstein <r.steinhagen@gsi.de>
- Loading branch information
1 parent
f5909b9
commit d777338
Showing
14 changed files
with
139 additions
and
121 deletions.
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
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
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
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.