Parma Polyhedra Library requirements
Internal coefficient-tree ownership, traversal and lookup
1. Ordered coefficient-map values and valid tree use PPL-SPEC-000601

CO_Tree shall own a finite map from distinct dimension_type keys to Coefficient values. Stored keys shall be strictly ordered and shall exclude not_a_dimension(). A stored zero coefficient shall remain a stored map entry. Physical array positions and holes shall not change the map's key/value associations.

Calls shall require live valid owners, admitted keys/counts and supported nonoverflowing capacity calculations, with sufficient resources. Selected coefficient values and operations shall satisfy the configured arithmetic profile's prerequisites. Library initialization shall be active where coefficient constants or scratch storage are used, and synchronization shall follow 🔗 3. Thread initialization, default state and finalization. Recoverable failures shall not be successful map results. Failed construction shall release resources of the incomplete owner; failure-state guarantees shall follow the selected member, without a universal rollback promise.

PPL-SPEC-000602
2. Empty construction, entry counts and supported count limit PPL-SPEC-000602

Default construction shall produce an empty map with zero managed storage and equal begin/end positions. empty() shall report exactly whether no entries are stored, and size() their number, including stored zeros. max_size() shall report the supported element-count limit accounting for complete-tree capacities, density calculations and representable backing allocations; it shall not limit key magnitude to that count or promise that allocating the maximum is feasible.

PPL-SPEC-000603
3. Independent copying, assignment and destruction PPL-SPEC-000603

Copy construction and assignment shall preserve the source map and produce independently owned coefficient objects and backing arrays. Copies shall remain usable after source mutation or destruction. Assignment shall admit self-assignment and return its target. Copying a const rvalue through these copy interfaces shall preserve its source. Destruction shall release all live coefficients and both backing arrays.

Recoverable copy-construction failure shall preserve the source and release the incomplete copy's resources. A recoverable assignment failure may discard the target's preceding contents, but shall leave a valid empty reusable target and preserve the source.

Transfer construction from a non-const rvalue shall acquire the complete owned storage without allocating or throwing and leave its source empty and reusable. Move assignment shall exchange complete storage owners without allocation or exceptions, return its target and leave its source holding the preceding target value. Self-move shall preserve both value and storage. References to elements shall follow their storage; distinct-owner transfers shall invalidate element iterators. References to cached ends shall remain bound to their original tree owners and shall be refreshed after transfer. Explicitly stored zeroes and physical layout metadata shall be transferred with their arrays.

PPL-SPEC-000604
4. Construction from a counted increasing-key input sequence PPL-SPEC-000604

For a count not exceeding max_size(), sequence construction shall consume exactly that many entries from the input position. The sequence shall provide coefficient values by dereference and their keys through index(); keys shall be valid and strictly increasing. The new map shall contain exactly those key/value pairs, including zero values, as independently owned coefficient copies. No following input position shall be dereferenced or have its key requested. Count zero shall produce an empty map without dereferencing or advancing the input.

If allocation, key access, dereference, coefficient construction or input advancement reports a recoverable exception, the incomplete tree shall release both backing arrays and every coefficient already constructed. The caller's input state shall follow its iterator's own copy and failure semantics; restoring a consumed input position shall not be promised.

PPL-SPEC-000605
5. Clearing and swapping complete tree owners PPL-SPEC-000605

Clearing shall destroy all entries and release backing storage, producing an empty reusable tree. Member and free swaps shall exchange complete maps and owned allocations and admit self-swap. Both resulting owners shall remain valid and independently usable. Their cached end-iterator objects shall retain their owner identities and be refreshed for their new maps; ordinary entry iterators and coefficient borrows shall be reacquired after an ownership exchange.

PPL-SPEC-000606
6. Iterator ownership, copying, const conversion and equality PPL-SPEC-000606

Tree iterators shall borrow positions in their owner. Copies and assignments shall preserve the borrowed position; assignment shall return its target and admit self-assignment. Mutable iterators shall convert or assign to const iterators without changing the position or entry. Member and free iterator swaps shall exchange their complete borrowed positions and admit self-swap, including positions in distinct live owners.

Within one owner, equality shall report the same position and inequality its negation. Comparisons shall require live compatible positions; copied end values shall remain subject to ordinary structural invalidation. Default construction shall create an unbound iterator usable for copying, assignment, swapping and destruction, but not entry access or navigation before a live position is assigned. Iterators and coefficient references shall not outlive their owner or be used after a structural operation that invalidates them.

PPL-SPEC-000607
7. Iterator key and coefficient access PPL-SPEC-000607

At a dereferenceable occupied position, index() shall return the stored key and dereference shall return its associated coefficient value. A mutable iterator shall provide a mutable coefficient reference even when the cursor object itself is const; constness shall constrain the position rather than the referenced coefficient. Read-only access shall use const_iterator and Coefficient_traits::const_reference. Both iterator types shall meet C++20 bidirectional iterator requirements. These operations shall require an occupied entry, rather than an end or unbound iterator.

Changing the coefficient through a live mutable reference shall update exactly that key's mapped value without changing keys, count, other entries or iterator positions. Assigning zero shall retain the entry. The new coefficient shall satisfy the configured profile's value and arithmetic prerequisites.

PPL-SPEC-000608
8. Bidirectional iterator movement follows stored-key order PPL-SPEC-000608

Increment of a dereferenceable iterator shall reach the next greater stored key or the owner's end after the last entry. Decrement shall require a preceding occupied entry and reach the next smaller stored key; decrementing end shall be admitted exactly for a nonempty owner. Physical holes shall be skipped. Prefix forms shall return the updated iterator by reference; postfix forms shall return its preceding value while advancing the original. These rules shall apply to mutable and const iterators, with no increment of end or decrement before begin.

9. Begin positions and owner-stable cached end references PPL-SPEC-000609

Mutable and const begin construction and access shall point to the least stored key, or the corresponding end for an empty map. cbegin() shall equal const begin(). End access shall return references to owner-resident cached end objects; const end() and cend() shall refer to the same const cached object.

References to these cached end objects shall remain valid throughout the owner's lifetime and observe updated end positions after structural changes, assignment, clearing and member/free owner swaps. This special reference guarantee shall not extend to copies of an end iterator or to ordinary entry iterators.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive. Direct iterator construction shall also reject a temporary tree owner.

10. Whole-tree bisection returns an exact key or an adjacent entry PPL-SPEC-000610

Whole-tree bisection shall return end for an empty map. For a nonempty map it shall return the exact requested key when present. For an absent key it shall return either the immediate stored predecessor or the immediate stored successor, choosing the available extreme when the query lies outside stored keys. It shall not return end for a nonempty map or promise the lower_bound choice. Every dimension_type query shall be admitted, including the reserved value as an absent query. Mutable and const overloads shall preserve all entries and return positions with the corresponding mutability.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive.

PPL-SPEC-000611
11. Closed-window bisection confines its candidate to that window PPL-SPEC-000611

Window bisection shall require an ordered nonempty closed iterator range [first, last] in the same live tree, with both endpoints occupied. It shall search only that window. A present key in the window shall be returned exactly; an absent key shall yield an immediate predecessor or successor within that window, using its available endpoint when the query lies outside the window's key interval. A singleton window shall always return its sole entry. The map and both endpoints shall be preserved.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive.

PPL-SPEC-000612
12. Hinted bisection retains whole-tree lookup meaning PPL-SPEC-000612

Hinted bisection shall admit any current valid iterator of its tree as hint, including end. It shall satisfy the exact-key, adjacent-absent-key and empty-map guarantees of 🔗 10. Whole-tree bisection returns an exact key or an adjacent entry over the whole tree, regardless of the hint's location. It shall preserve the map and hint. The hint may affect search strategy and the permitted choice between two adjacent absent-key candidates; it shall not restrict the search window.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive.

PPL-SPEC-000613
13. Managed storage counts backing arrays and live coefficient payloads PPL-SPEC-000613

External-memory accounting shall return zero for a tree with no backing arrays. Otherwise it shall count the complete reserved key-array payload, including its two sentinel slots, the coefficient-array payload, including its unused leading slot, and the external storage of every live coefficient. Unoccupied coefficient slots shall not add coefficient payload. This shall describe owned allocated payload, excluding allocator bookkeeping, and preserve the map and all current iterators.

PPL-SPEC-000614
14. Diagnostic tree output reflects current stored pairs PPL-SPEC-000614

dump_tree() shall write a diagnostic representation to std::cout without changing the tree. For an empty map it shall emit (empty tree) followed by a newline. For a nonempty tree the output shall identify all current stored key/coefficient pairs and may include physical-layout information and holes. A removed key/value pair shall not be reported as a live entry. This diagnostic representation shall not establish a reloadable serialization format.

PPL-SPEC-000615
15. Physical-slot iterator construction preserves the selected live position PPL-SPEC-000615

Iterator construction from a tree and physical slot shall require a currently occupied slot or that tree's designated past-the-end slot. The argument shall denote a physical array slot, not a map key or an ordinal in the logical traversal. The resulting iterator shall borrow that same live position, with mutable/const access as selected.

The tree's internal conversion from its live private node iterator to an ordinary mutable iterator, by construction or assignment, shall preserve the occupied node's key/value position. Such conversions shall require a valid occupied private node and shall not extend private node-layout access to clients without the corresponding access rights.

Borrowing iterator constructors shall reject temporary backing owners. Copying temporary iterator values shall remain admitted when their backing storage remains alive.

PPL-SPEC-001629
16. Complete-tree cursor positions, topology and occupied-node search PPL-SPEC-001629

The internal tree_iterator shall borrow one allocated complete-tree layout of 🔗 1. Ordered coefficient-map values and valid tree use. Let R = 2h − 1 > 0 be its reserved slot count and r = (R + 1) ⁄ 2 its root slot. A valid cursor shall store a physical slot 1 ≤ i ≤ R and its offset o = 2v2(i). Physical slots may be unoccupied. The source tree shall outlive the cursor; structural replacement shall invalidate it.

Root construction and get_root() shall select (r, r). Physical-slot construction shall select the admitted slot and its offset. Construction or assignment from a live same-tree logical iterator shall select that occupied slot. Copies shall retain owner and position; assignment between cursors shall require the same owner and return the target. Equality and inequality shall compare physical positions within the same owner.

For o > 1, left and right movement shall select (i − o ⁄ 2, o ⁄ 2) and (i + o ⁄ 2, o ⁄ 2). Parent movement shall require a non-root position and select its complete-tree parent. is_root() shall hold at r; is_leaf() shall hold exactly when o = 1. is_right_child() shall be false at the root and otherwise identify the parent's right child. dfs_index() shall return i and get_offset() shall return o. depth() shall return log2((R + 1) ⁄ o), counting the root as depth one.

index() shall access the key at the selected slot, including the unused_index marker for an unoccupied slot. Const access shall return the key value; mutable access shall borrow the stored key. Dereference shall require an occupied slot and access its coefficient, borrowing a mutable or const value as declared. Direct key updates shall satisfy the tree's staging and ordering conditions before the tree is again used as a valid map.

For an occupied current node, follow_left_children_with_value() and follow_right_children_with_value() shall select the occupied minimum-key and maximum-key nodes in that node's complete subtree, respectively. go_down_searching_key(k) shall require an occupied starting node and k != unused_index. It shall search that subtree, stopping at the key if present or at its prospective parent if absent. Navigation shall preserve the tree's keys and coefficients. The local OK() check shall accept exactly the admitted physical range with the matching stored offset; it shall not establish map ordering or coefficient validity.

Borrowing iterator constructors shall reject temporary backing owners. Copying temporary iterator values shall remain admitted when their backing storage remains alive.