18#include "pw_allocator/bucket/base.h"
19#include "pw_containers/intrusive_multimap.h"
20#include "pw_function/function.h"
22namespace pw::allocator {
31template <
typename BlockType>
36 const auto* block = BlockType::FromUsableSpace(
this);
37 return block->InnerSize();
59template <
typename BlockType>
63 FastSortedItem<BlockType>> {
73 using Compare =
Function<bool(
size_t,
size_t)>;
82 : items_(std::move(compare)) {}
85 void DoAdd(BlockType& block) {
91 BlockType* DoRemoveAny() {
92 auto iter = items_.begin();
95 return BlockType::FromUsableSpace(&item);
99 bool DoRemove(BlockType& block) {
101 auto iters = items_.equal_range(block.InnerSize());
103 std::find_if(iters.first,
106 return &item_to_remove == &item;
108 if (iter == items_.end()) {
116 BlockType* DoRemoveCompatible(
Layout layout) {
117 auto iter = items_.lower_bound(layout.size());
118 return RemoveImpl(iter, layout);
121 template <
typename Iterator>
122 BlockType* RemoveImpl(Iterator iter,
Layout layout) {
126 if (block !=
nullptr) {
138template <
typename BlockType>
142 FastSortedItem<BlockType>> {
151 : impl_(std::greater<>()), items_(impl_.items_) {}
155 void DoAdd(BlockType& block) { impl_.DoAdd(block); }
158 BlockType* DoRemoveAny() {
159 auto iter = items_.begin();
162 return BlockType::FromUsableSpace(&item);
166 bool DoRemove(BlockType& block) {
return impl_.DoRemove(block); }
169 BlockType* DoRemoveCompatible(
Layout layout) {
170 return impl_.RemoveImpl(impl_.items_.begin(), layout);
Definition: intrusive_multimap.h:60
Definition: fast_sorted.h:63
Definition: fast_sorted.h:33
Definition: fast_sorted.h:142
constexpr BlockType * GetBlockFromIterator(Iterator iter, Iterator last)
Definition: base.h:167
static auto MakeCanAllocPredicate(Layout layout)
Definition: base.h:157
void Clear()
Removes all blocks from this bucket.
Definition: base.h:124
static ItemType & GetItemFrom(BlockType &block)
Definition: base.h:185
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:74
Definition: fast_sorted.h:51