entttree 0.1.0
Hierarchical entity management for EnTT
Loading...
Searching...
No Matches
entttree::Position Struct Reference

A fractional index with strong ordering, used for sibling positioning. More...

#include <position.h>

Public Types

using symbol_t = uint8_t
 

Public Member Functions

 Position ()
 Construct a Position at the midpoint (0.5).
 
 Position (const Position &other)
 
 Position (Position &&other)
 
Positionoperator= (const Position &other)
 
Positionoperator= (Position &&other)
 
std::strong_ordering operator<=> (const Position &other) const
 Lexicographic three-way comparison.
 
bool operator== (const Position &other) const
 
Position before () const
 Return a position immediately before this one.
 
Position between (const Position &other) const
 Return a position midway between this position and other.
 
Position after () const
 Return a position immediately after this one.
 
size_t byte_count () const
 Number of symbols in the fractional-index representation.
 
const symbol_t * bytes () const
 Read-only pointer to the raw symbol bytes (big-endian, high-order first).
 

Static Public Member Functions

static Position from_bytes (const symbol_t *data, size_t count)
 Construct a Position from raw symbol bytes.
 

Protected Member Functions

symbol_t * _data ()
 
const symbol_t * _data () const
 
symbol_t operator[] (size_t i) const
 

Friends

template<typename T , typename H >
struct geom::Digest
 

Detailed Description

A fractional index with strong ordering, used for sibling positioning.

This is an infinite-precision number between 0 and 1 exclusive, represented as a base-256 value with unlimited digits right of the decimal point. The leading zero is not stored.

Chunking into 8-bit symbols balances two growth pressures: large symbols reduce growth from sequential before()/after() calls (~128 steps before a new symbol is needed), while the between() operation grows the number only when the last symbols of the two positions are within 1 of each other.

Up to 14 symbols (112 bits) are stored inline; beyond that, heap storage is used. Default-constructed positions start at the midpoint (0.5).

Definition at line 27 of file position.h.

Member Typedef Documentation

◆ symbol_t

Definition at line 28 of file position.h.

Constructor & Destructor Documentation

◆ Position() [1/3]

entttree::Position::Position ( )

Construct a Position at the midpoint (0.5).

Definition at line 49 of file position.cpp.

Referenced by from_bytes().

◆ Position() [2/3]

entttree::Position::Position ( const Position other)

Definition at line 53 of file position.cpp.

◆ Position() [3/3]

entttree::Position::Position ( Position &&  other)

Definition at line 67 of file position.cpp.

◆ ~Position()

entttree::Position::~Position ( )

Definition at line 79 of file position.cpp.

Member Function Documentation

◆ _data() [1/2]

Position::symbol_t * entttree::Position::_data ( )
protected

Definition at line 10 of file position.cpp.

◆ _data() [2/2]

const Position::symbol_t * entttree::Position::_data ( ) const
protected

Definition at line 14 of file position.cpp.

◆ after()

Position entttree::Position::after ( ) const

Return a position immediately after this one.

Definition at line 140 of file position.cpp.

References entttree::and.

◆ before()

Position entttree::Position::before ( ) const

Return a position immediately before this one.

Definition at line 160 of file position.cpp.

References entttree::and.

◆ between()

Position entttree::Position::between ( const Position other) const

Return a position midway between this position and other.

The result is always strictly between the two operands regardless of their ordering. The representation may grow by one symbol when the two positions are adjacent.

Definition at line 178 of file position.cpp.

◆ byte_count()

size_t entttree::Position::byte_count ( ) const
inline

Number of symbols in the fractional-index representation.

Definition at line 94 of file position.h.

◆ bytes()

const symbol_t * entttree::Position::bytes ( ) const
inline

Read-only pointer to the raw symbol bytes (big-endian, high-order first).

Definition at line 97 of file position.h.

◆ from_bytes()

Position entttree::Position::from_bytes ( const symbol_t *  data,
size_t  count 
)
static

Construct a Position from raw symbol bytes.

Parameters
dataPointer to symbol bytes (big-endian, high-order first).
countNumber of symbols. Must be >= 1.

Definition at line 208 of file position.cpp.

References Position().

◆ operator<=>()

std::strong_ordering entttree::Position::operator<=> ( const Position other) const

Lexicographic three-way comparison.

Definition at line 123 of file position.cpp.

◆ operator=() [1/2]

Position & entttree::Position::operator= ( const Position other)

Definition at line 88 of file position.cpp.

◆ operator=() [2/2]

Position & entttree::Position::operator= ( Position &&  other)

Definition at line 104 of file position.cpp.

◆ operator==()

bool entttree::Position::operator== ( const Position other) const
inline

Definition at line 74 of file position.h.

◆ operator[]()

Position::symbol_t entttree::Position::operator[] ( size_t  i) const
protected

Definition at line 18 of file position.cpp.

Friends And Related Symbol Documentation

◆ geom::Digest

template<typename T , typename H >
friend struct geom::Digest
friend

Definition at line 41 of file position.h.

Member Data Documentation

◆ _symbol_ptr

symbol_t* entttree::Position::_symbol_ptr

Heap pointer when size exceeds K.

Definition at line 46 of file position.h.

◆ _symbols

symbol_t entttree::Position::_symbols[K]

Inline storage for small positions.

Definition at line 45 of file position.h.


The documentation for this struct was generated from the following files: