-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae2f7dd
commit 2df3b1c
Showing
2 changed files
with
44 additions
and
172 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (C) 2022, 2023 by Mark Melton | ||
// | ||
|
||
#pragma once | ||
#include <algorithm> | ||
|
||
namespace core::sort { | ||
|
||
template<class T, size_t Size, size_t Align> | ||
class ArrayRing { | ||
public: | ||
auto size() const { return head_ - tail_; } | ||
auto& next() { return data_[head_ % Size]; } | ||
auto& front() { return data_[tail_ % Size]; } | ||
const auto& front() const { return data_[tail_ % Size]; } | ||
auto& back() { return data_[(head_ + Size - 1) % Size]; } | ||
const auto& back() const { return data_[(head_ + Size - 1) % Size]; } | ||
auto& head_index() { return head_; } | ||
const auto& head_index() const { return head_; } | ||
auto& tail_index() { return tail_; } | ||
const auto& tail_index() const { return tail_; } | ||
T pop_front() { return data_[tail_++ % Size]; } | ||
void push_back(const T& value) { data_[head_++ % Size] = value; } | ||
T pop_back() { return data_[--head_ % Size]; } | ||
private: | ||
alignas(Align) std::array<T, Size> data_; | ||
size_t head_{}, tail_{}; | ||
}; | ||
|
||
|
||
|
||
}; // core::sort |
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