137 using value_type =
Attr;
138 using pointer =
const value_type *;
139 using reference =
const value_type &;
140 using difference_type = std::ptrdiff_t;
141 using iterator_category = std::forward_iterator_tag;
143 friend class Bindings;
146 struct BindingsCursor
164 pointer operator->()
const noexcept
169 reference
get()
const noexcept
174 bool empty()
const noexcept
176 return current == end;
179 void increment()
noexcept
184 void consume(
Symbol name)
noexcept
186 while (!empty() && current->name <= name)
190 GENERATE_CMP(BindingsCursor, me->current->name, me->priority)
193 using QueueStorageType = boost::container::static_vector<BindingsCursor, maxLayers>;
199 static constexpr auto comp = std::greater<BindingsCursor>();
204 QueueStorageType cursorHeap;
209 pointer current =
nullptr;
216 void push(BindingsCursor cursor)
noexcept
218 cursorHeap.push_back(cursor);
219 std::ranges::make_heap(cursorHeap, comp);
222 [[nodiscard]] BindingsCursor pop()
noexcept
224 std::ranges::pop_heap(cursorHeap, comp);
225 auto cursor = cursorHeap.back();
226 cursorHeap.pop_back();
230 iterator & finished()
noexcept
236 void next(BindingsCursor cursor)
noexcept
238 current = &cursor.get();
245 std::optional<BindingsCursor> consumeAllUntilCurrentName()
noexcept
248 Symbol lastHandledName = current->name;
250 while (cursor->name <= lastHandledName) {
251 cursor.consume(lastHandledName);
255 if (cursorHeap.empty())
264 explicit iterator(
const Bindings & attrs) noexcept
265 : doMerge(attrs.baseLayer)
267 auto pushBindings = [
this, priority =
unsigned{0}](
const Bindings & layer)
mutable {
268 auto first = layer.attrs;
272 .end = first + layer.numAttrs,
273 .priority = priority++,
281 current = attrs.attrs;
287 const Bindings * layer = &attrs;
289 if (layer->numAttrs != 0)
290 pushBindings(*layer);
291 layer = layer->baseLayer;
294 if (cursorHeap.empty())
301 iterator() =
default;
303 reference operator*()
const noexcept
308 pointer operator->()
const noexcept
313 iterator & operator++()
noexcept
317 if (current == cursorHeap.front().end)
322 if (cursorHeap.empty())
325 auto cursor = consumeAllUntilCurrentName();
333 iterator operator++(
int)
noexcept
335 iterator tmp = *
this;
340 bool operator==(
const iterator & rhs)
const noexcept
342 return current == rhs.current;
359 auto getInChunk = [key =
Attr{name,
nullptr}](
const Bindings & chunk) ->
const Attr * {
360 auto first = chunk.attrs;
361 auto last = first + chunk.numAttrs;
362 const Attr * i = std::lower_bound(first, last, key);
363 if (i != last && i->name == key.name)
368 const Bindings * currentChunk =
this;
369 while (currentChunk) {
370 const Attr * maybeAttr = getInChunk(*currentChunk);
373 currentChunk = currentChunk->baseLayer;
426 std::vector<const Attr *> res;
428 std::ranges::transform(*
this, std::back_inserter(res), [](
const Attr & a) {
return &a; });
429 std::ranges::sort(res, [&](
const Attr * a,
const Attr * b) {
430 std::string_view sa = symbols[a->name], sb = symbols[b->name];