-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces a generic, fixed-size `Bucket` type in place of the inner vector. This does add size generics but I think it's a very good tradeoff considering how performance-sensitive this codepath is.
- Loading branch information
1 parent
91589b1
commit 65fdeb9
Showing
3 changed files
with
97 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include <optional> | ||
|
||
template<class T, size_t N> | ||
class Bucket { | ||
std::array<T, N> buf; | ||
size_t sz; | ||
public: | ||
Bucket() { | ||
sz = 0; | ||
} | ||
|
||
void add(const T& item) { | ||
if (sz < N) { | ||
buf[sz++] = item; | ||
} | ||
} | ||
|
||
std::optional<T> get(size_t idx) const { | ||
if (idx < sz) { | ||
return buf[idx]; | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
size_t size() const { | ||
return sz; | ||
} | ||
|
||
bool isFull() const { | ||
return sz == N; | ||
} | ||
|
||
void clear() { | ||
sz = 0; | ||
} | ||
}; |
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