10Position::symbol_t* Position::_data() {
14const Position::symbol_t* Position::_data()
const {
18Position::symbol_t Position::operator[](
size_t i)
const {
19 if (i >= _size)
return 0;
23void Position::_push_back(symbol_t s) {
24 if (_size < K) [[likely]] {
27 symbol_t* cur_data = _data();
28 symbol_t* new_ptr =
new symbol_t[_size + 1];
29 std::copy(cur_data, cur_data + _size, new_ptr);
45 _symbol_ptr =
new symbol_t[n];
50 _data()[1] = HIGH_BIT;
63 const symbol_t* other_data = other._data();
64 std::copy(other_data, other_data + _size, data);
74 const symbol_t* other_data = other._data();
75 std::copy(other_data, other_data + _size,
_symbols);
79Position::~Position() {
88Position& Position::operator=(
const Position& other) {
89 if (
this == &other)
return *
this;
94 const symbol_t* other_data = other._data();
100 std::copy(other_data, other_data + _size, data);
104Position& Position::operator=(Position&& other) {
105 if (
this == &other)
return *
this;
114 const symbol_t* other_data = other._symbols;
115 std::copy(other_data, other_data + _size,
_symbols);
124 size_t n = std::min(_size,
other._size);
125 const symbol_t*
data_a = _data();
127 for (
size_t i = 0;
i <
n; ++
i) {
129 return std::strong_ordering::less;
131 return std::strong_ordering::greater;
145 const symbol_t*
data = _data();
146 for (
int i =
int(_size) - 1;
i >= 0; --
i) {
152 for (
size_t i = 0;
i < _size; ++
i) {
155 result._push_back(HIGH_BIT);
163 const symbol_t*
data = _data();
167 for (
int i =
int(_size) - 1;
i >= 0; --
i) {
173 result._push_back(HIGH_BIT);
179 const symbol_t*
data_a = _data();
187 static_assert(std::is_unsigned_v<symbol_t>,
"assumption: symbol_t nonnegative");
193 for (
int i =
int(
result._size) - 1;
i >= 0; --
i) {
197 if (
i <= (
int)
sz_a)
a |= (
data_a[
i - 1] & 1) << (SYMBOL_BITS - 1);
198 if (
i <= (
int)
sz_b)
b |= (
data_b[
i - 1] & 1) << (SYMBOL_BITS - 1);
218size_t std::hash<entttree::Position>::operator()(
const entttree::Position& pos)
const {
219 return geom::hash<entttree::Position,size_t>(pos);
Fractional-index type for ordering siblings in a hierarchy.
A system for maintaining parent-child relationships on entities.
A fractional index with strong ordering, used for sibling positioning.
symbol_t _symbols[K]
Inline storage for small positions.
static Position from_bytes(const symbol_t *data, size_t count)
Construct a Position from raw symbol bytes.
symbol_t * _symbol_ptr
Heap pointer when size exceeds K.
Position()
Construct a Position at the midpoint (0.5).
Position after() const
Return a position immediately after this one.
Position before() const
Return a position immediately before this one.
std::strong_ordering operator<=>(const Position &other) const
Lexicographic three-way comparison.
Position between(const Position &other) const
Return a position midway between this position and other.
and
Transform a traversal inductively, threading parent context through successors.