rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
c4::yml::TagCache Struct Reference

Accelerator structure to reduce memory requirements by enabling reuse of resolved tags. More...

#include <tag.hpp>

Classes

struct  Entry
struct  LookupResult

Public Types

using Entries = detail::stack<Entry>
using const_iterator = id_type

Public Member Functions

 TagCache () noexcept
LookupResult find (csubstr tag, id_type doc_id, id_type linear_threshold=Entries::sso_size) const noexcept
void add (csubstr tag, csubstr resolved, id_type doc_id, const_iterator pos) RYML_NOEXCEPT
void clear () noexcept

Detailed Description

Accelerator structure to reduce memory requirements by enabling reuse of resolved tags.

Definition at line 70 of file tag.hpp.

Member Typedef Documentation

◆ Entries

using c4::yml::TagCache::Entries = detail::stack<Entry>

Definition at line 78 of file tag.hpp.

◆ const_iterator

Definition at line 79 of file tag.hpp.

Constructor & Destructor Documentation

◆ TagCache()

c4::yml::TagCache::TagCache ( )
inlinenoexcept

Definition at line 89 of file tag.hpp.

89: m_entries() {}

Member Function Documentation

◆ find()

TagCache::LookupResult c4::yml::TagCache::find ( csubstr tag,
id_type doc_id,
id_type linear_threshold = Entries::sso_size ) const
noexcept

Definition at line 539 of file tag.cpp.

540{
541 LookupResult ret = {};
542 id_type sz = m_entries.size();
543 if(sz < linear_threshold) // do a linear search on small size
544 {
545 for(size_t i = 0; i < sz; ++i)
546 {
547 Entry const& C4_RESTRICT e = m_entries[i];
548 if(e.tag == tag && e.doc_id == doc_id)
549 {
550 ret.resolved = e.resolved;
551 ret.pos = i;
552 return ret;
553 }
554 else if(e.tag > tag || ((e.tag == tag) && e.doc_id > doc_id))
555 {
556 ret.pos = i;
557 return ret;
558 }
559 }
560 ret.pos = sz;
561 }
562 else // do a binary search on larger size
563 {
564 id_type first = 0;
565 id_type count = sz;
566 while(count)
567 {
568 id_type halfsz = count / id_type(2); // NOLINT(*avoid-c-style-cast)
569 id_type mid = first + halfsz;
570 RYML_ASSERT_BASIC_CB_(m_entries.m_callbacks, mid < sz);
571 Entry const& C4_RESTRICT e = m_entries[mid];
572 if(e.tag < tag || (e.tag == tag && e.doc_id < doc_id))
573 {
574 first = mid + 1;
575 RYML_ASSERT_BASIC_CB_(m_entries.m_callbacks, count >= halfsz + 1);
576 count -= halfsz + 1;
577 }
578 else
579 {
580 count = halfsz;
581 }
582 }
583 ret.pos = first;
584 if(first < sz)
585 {
586 Entry const& C4_RESTRICT e = m_entries[first];
587 if(e.tag == tag && e.doc_id == doc_id)
588 {
589 ret.resolved = m_entries[first].resolved;
590 }
591 }
592 }
593 return ret;
594}
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition common.hpp:124

◆ add()

void c4::yml::TagCache::add ( csubstr tag,
csubstr resolved,
id_type doc_id,
const_iterator pos )

Definition at line 596 of file tag.cpp.

597{
598 const id_type sz = m_entries.size();
599 RYML_ASSERT_BASIC_CB_(m_entries.m_callbacks, pos <= sz);
600 RYML_ASSERT_BASIC_CB_(m_entries.m_callbacks, pos == sz || tag < m_entries[pos].tag || (tag == m_entries[pos].tag && doc_id < m_entries[pos].doc_id));
601 m_entries.resize(sz + 1);
602 if(pos < sz)
603 memmove(m_entries.m_stack + pos + 1, m_entries.m_stack + pos, (sz - pos) * sizeof(Entry));
604 m_entries.m_stack[pos].tag = tag;
605 m_entries.m_stack[pos].resolved = resolved;
606 m_entries.m_stack[pos].doc_id = doc_id;
607 _c4dbgpf("tagcache: add entry @pos={}: docid={} {} -> {}", pos, doc_id, tag, maybe_null_str_(resolved));
608}

◆ clear()

void c4::yml::TagCache::clear ( )
inlinenoexcept

Definition at line 93 of file tag.hpp.

93{ m_entries.clear(); }

Referenced by c4::yml::EventHandlerTree::reset(), and c4::yml::extra::EventHandlerInts::reset().


The documentation for this struct was generated from the following files:
  • /home/docs/checkouts/readthedocs.org/user_builds/rapidyaml/checkouts/latest/src/c4/yml/tag.hpp
  • /home/docs/checkouts/readthedocs.org/user_builds/rapidyaml/checkouts/latest/src/c4/yml/tag.cpp