queue/IdTable: add `constexpr` (because we can)

This commit is contained in:
Max Kellermann 2023-11-26 08:43:48 +01:00
parent e7b9e8de14
commit 571b6f0cdb
1 changed files with 7 additions and 7 deletions

View File

@ -34,23 +34,23 @@ class IdTable {
int *const data = new int[size]; int *const data = new int[size];
public: public:
explicit IdTable(unsigned _size) noexcept explicit constexpr IdTable(unsigned _size) noexcept
:size(_size) {} :size(_size) {}
~IdTable() noexcept { constexpr ~IdTable() noexcept {
delete[] data; delete[] data;
} }
IdTable(const IdTable &) = delete; IdTable(const IdTable &) = delete;
IdTable &operator=(const IdTable &) = delete; IdTable &operator=(const IdTable &) = delete;
int IdToPosition(unsigned id) const noexcept { constexpr int IdToPosition(unsigned id) const noexcept {
return id < initialized return id < initialized
? data[id] ? data[id]
: -1; : -1;
} }
unsigned GenerateId() noexcept { constexpr unsigned GenerateId() noexcept {
assert(next > 0); assert(next > 0);
assert(next <= initialized); assert(next <= initialized);
@ -75,21 +75,21 @@ public:
} }
} }
unsigned Insert(unsigned position) noexcept { constexpr unsigned Insert(unsigned position) noexcept {
unsigned id = GenerateId(); unsigned id = GenerateId();
assert(id < initialized); assert(id < initialized);
data[id] = position; data[id] = position;
return id; return id;
} }
void Move(unsigned id, unsigned position) noexcept { constexpr void Move(unsigned id, unsigned position) noexcept {
assert(id < initialized); assert(id < initialized);
assert(data[id] >= 0); assert(data[id] >= 0);
data[id] = position; data[id] = position;
} }
void Erase(unsigned id) noexcept { constexpr void Erase(unsigned id) noexcept {
assert(id < initialized); assert(id < initialized);
assert(data[id] >= 0); assert(data[id] >= 0);