Go to the documentation of this file.
15 #ifndef ABSL_STRINGS_INTERNAL_CORD_REP_BTREE_H_
16 #define ABSL_STRINGS_INTERNAL_CORD_REP_BTREE_H_
22 #include "absl/base/config.h"
23 #include "absl/base/internal/raw_logging.h"
24 #include "absl/base/optimization.h"
26 #include "absl/strings/internal/cord_internal.h"
27 #include "absl/strings/internal/cord_rep_flat.h"
28 #include "absl/strings/string_view.h"
29 #include "absl/types/span.h"
33 namespace cord_internal {
35 class CordRepBtreeNavigator;
280 size_t extra_capacity = 1);
289 size_t back()
const {
return static_cast<size_t>(
storage[2]) - 1; }
290 size_t end()
const {
return static_cast<size_t>(
storage[2]); }
332 bool shallow =
true);
340 bool include_contents, std::ostream&
stream);
350 template <EdgeType edge_type>
359 template <EdgeType edge_type>
445 template <EdgeType edge_type>
508 template <EdgeType edge_type>
514 template <EdgeType edge_type>
525 template <EdgeType edge_type>
530 template <EdgeType edge_type>
540 CopyResult
CopyPrefix(
size_t n,
bool allow_folding =
true);
556 template <EdgeType edge_type>
561 template <EdgeType edge_type>
568 template <EdgeType edge_type>
624 assert(end <= this->
end());
642 int height =
rep->IsBtree() ?
rep->btree()->height() + 1 : 0;
682 size_t new_length)
const {
684 assert(begin <= this->
end());
686 tree->
length = new_length;
693 size_t new_length)
const {
697 tree->
length = new_length;
709 const size_t delta =
begin();
711 const size_t new_end =
end() - delta;
723 for (
size_t i = 0;
i < new_end; ++
i) {
733 const size_t new_begin =
begin() + delta;
734 const size_t new_end =
end() + delta;
741 for (
size_t i = new_end - 1;
i >= new_begin; --
i) {
748 inline void CordRepBtree::Add<CordRepBtree::kBack>(
CordRep*
rep) {
750 edges_[fetch_add_end(1)] =
rep;
754 inline void CordRepBtree::Add<CordRepBtree::kBack>(
757 size_t new_end =
end();
758 for (
CordRep* edge : edges) edges_[new_end++] = edge;
763 inline void CordRepBtree::Add<CordRepBtree::kFront>(
CordRep*
rep) {
765 edges_[sub_fetch_begin(1)] =
rep;
769 inline void CordRepBtree::Add<CordRepBtree::kFront>(
772 size_t new_begin =
begin() - edges.
size();
773 set_begin(new_begin);
774 for (
CordRep* edge : edges) edges_[new_begin++] = edge;
777 template <CordRepBtree::EdgeType edge_type>
820 const size_t offset)
const {
861 if (edge->
tag <
FLAT)
return {};
863 if (avail == 0)
return {};
886 extern template CordRepBtree* CordRepBtree::AddCordRep<CordRepBtree::kBack>(
889 extern template CordRepBtree* CordRepBtree::AddCordRep<CordRepBtree::kFront>(
894 return CordRepBtree::AddCordRep<kBack>(tree,
rep);
901 return CordRepBtree::AddCordRep<kFront>(tree,
rep);
924 #endif // ABSL_STRINGS_INTERNAL_CORD_REP_BTREE_H_
#define ABSL_PREDICT_FALSE(x)
static constexpr size_t kMaxCapacity
constexpr bool IsBtree() const
CordRepBtree * CopyBeginTo(size_t end, size_t new_length) const
absl::string_view EdgeData(const CordRep *edge)
CordRep * edges_[kMaxCapacity]
static CordRepBtree * PrependSlow(CordRepBtree *, CordRep *rep)
static void Unref(CordRep *rep)
Position IndexBefore(size_t offset) const
void set_begin(size_t begin)
CordRepBtree * Copy() const
CordRepBtree * CopyToEndFrom(size_t begin, size_t new_length) const
Position IndexOf(size_t offset) const
absl::string_view Data(size_t index) const
#define ABSL_NAMESPACE_END
static constexpr int kMaxHeight
static CordRepBtree * Prepend(CordRepBtree *tree, CordRep *rep)
absl::string_view AddData(absl::string_view data, size_t extra)
static CordRep * RemoveSuffix(CordRepBtree *tree, size_t n)
CopyResult CopyPrefix(size_t n, bool allow_folding=true)
static CordRepBtree * New(int height=0)
static constexpr EdgeType kFront
static void Delete(CordRepBtree *tree)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static constexpr int kMaxDepth
char GetCharacter(size_t offset) const
#define ABSL_NAMESPACE_BEGIN
static void Dump(const CordRep *rep, std::ostream &stream)
static void Destroy(CordRepBtree *tree)
void InitInstance(int height, size_t begin=0, size_t end=0)
RefcountAndFlags refcount
OpResult SetEdge(bool owned, CordRep *edge, size_t delta)
constexpr bool IsFlat() const
static CordRepBtree * Merge(CordRepBtree *dst, CordRepBtree *src)
Position IndexBeyond(size_t offset) const
static CordRepBtree * Create(CordRep *rep)
size_t index(EdgeType edge) const
CordRepBtree * CopyRaw() const
Position IndexOfLength(size_t n) const
static CordRepBtree * AppendSlow(CordRepBtree *, CordRep *rep)
static ExtractResult ExtractAppendBuffer(CordRepBtree *tree, size_t extra_capacity=1)
static CordRepBtree * Append(CordRepBtree *tree, CordRep *rep)
#define ABSL_PREDICT_TRUE(x)
static CordRepBtree * AddCordRep(CordRepBtree *tree, CordRep *rep)
CopyResult CopySuffix(size_t offset)
Span< char > GetAppendBuffer(size_t size)
static void Destroy(CordRep *rep)
static CordRepBtree * MergeTrees(CordRepBtree *left, CordRepBtree *right)
CordRep * SubTree(size_t offset, size_t n)
static bool IsValid(const CordRepBtree *tree, bool shallow=false)
#define ABSL_ASSUME(cond)
OpResult AddEdge(bool owned, CordRep *edge, size_t delta)
static CordRepBtree * Rebuild(CordRepBtree *tree)
constexpr size_type size() const noexcept
static CordRepBtree * NewLeaf(absl::string_view data, size_t extra)
CordRep * Edge(size_t index) const
absl::Span< CordRep *const > Edges() const
static CordRep * Ref(CordRep *rep)
static CordRep * ExtractFront(CordRepBtree *tree)
static CordRepBtree * AssertValid(CordRepBtree *tree, bool shallow=true)
static CordRepBtree * ConsumeBeginTo(CordRepBtree *tree, size_t end, size_t new_length)
size_t sub_fetch_begin(size_t n)
bool IsDataEdge(const CordRep *edge)
static constexpr EdgeType kBack
#define ABSL_FALLTHROUGH_INTENDED
static void Unref(absl::Span< CordRep *const > edges)
size_t fetch_add_end(size_t n)
static CordRepBtree * CreateSlow(CordRep *rep)
Span< char > GetAppendBufferSlow(size_t size)
OpResult ToOpResult(bool owned)
grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:56