Parma Polyhedra Library requirements
Internal indirect sorting and ownership-preserving swaps
PPL-SPEC-000531
1. Borrowed offset adapter for ordering comparisons PPL-SPEC-000531

Indirect_Sort_Compare shall borrow its container and store the specified base index and a copy of its comparison object. Its call with indices i, j shall return exactly the stored comparator's result for container entries b + i, b + j, where b is the stored base. The default base shall be zero; omission of the comparator shall value-initialize its configured type. Adapter copying shall retain the same borrowed container and stored base and copy the comparison object.

Calls shall require the borrowed container to remain live, both computed indices to be valid without arithmetic overflow, and the comparison object's own preconditions. The adapter shall not copy or reorder container elements. Later valid element changes shall be observed by later calls.

PPL-SPEC-000532
2. Borrowed offset adapter for equality comparisons PPL-SPEC-000532

Indirect_Unique_Compare shall borrow its container and retain the specified base, defaulting to zero. Calling it with i, j shall return the result of equality comparison between entries b + i, b + j. The live-container, valid computed-index and underlying equality preconditions shall apply. Adapter copying shall retain the same borrowing and base. Calls shall observe current entry values and shall not copy or reorder container elements.

PPL-SPEC-000533
3. Single-container indexed swapping PPL-SPEC-000533

Indirect_Swapper shall borrow a mutable container and store its base, defaulting to zero. A call with i, j shall invoke an unqualified swap with the standard overloads available on entries b + i, b + j. For entries with ordinary swap semantics this shall exchange exactly those two owned values. It shall support types whose valid swap is provided by argument-dependent lookup, without requiring element copying or assignment. The container shall remain live and computed indices valid. Self-index calls shall follow the element type's self-swap semantics. Adapter copies shall continue to act on the same container.

PPL-SPEC-000534
4. Paired indexed swaps preserve associations PPL-SPEC-000534

Indirect_Swapper2 shall borrow its two mutable containers. Calling it with i, j shall first swap those positions in the first container and then swap them in the second, using the lookup convention of 🔗 3. Single-container indexed swapping. Both index pairs shall be valid and both containers live. With nonoverlapping storage and nonthrowing ordinary swaps, this shall apply one common transposition to complete paired records, preserving their associations and all other entries.

The two borrows may designate the same container: in that case the two successive ordinary transpositions shall restore its initial values. Other overlapping storage shall follow the same sequential-swap semantics; association preservation for independent records shall not be inferred from overlapping storage.

5. Indirect sorting establishes a distinct prefix without resizing PPL-SPEC-000535

indirect_sort_and_unique shall require at least two indexed entries. Its comparison and swap functors shall address the same initial indexed collection. Ordering shall be a consistent strict weak ordering over its values, and the uniqueness relation shall agree with that ordering's equivalence. The supplied swap shall realize an ordinary, nonthrowing indexed transposition of the complete values and every required associated record. Containers shall remain live and indices and index storage within supported nonoverflowing limits, with sufficient resources. Conflicting concurrent access shall be prevented.

On successful return of d, the first n − d entries shall be sorted and contain exactly one representative of each equivalence class of the initial n entries. The remaining d entries shall contain the surplus representatives, in an unspecified order. The entire indexed collection shall remain a permutation of its initial complete values, and every associated collection shall undergo that same permutation. The function shall not resize these collections or change entries outside its indexed range. No stable choice among equivalent representatives shall be required. No library or thread initialization object or coefficient-constant stage shall be required.

PPL-SPEC-000536
6. Indirect-sort failure and cooperative interruption states PPL-SPEC-000536

Under 🔗 5. Indirect sorting establishes a distinct prefix without resizing, failures while preparing or sorting the private index sequence shall preserve every indexed value and associated record. This shall include recoverable index-storage allocation failure and exceptions from the ordering comparator. Temporary index storage shall be released on every exceptional return.

Outside library assertion evaluation, cooperative abandonment shall be checked before index preparation, at intervals of at most 1024 ordering comparisons, and again before the first indexed-value mutation. A reported cooperative interruption shall therefore preserve every indexed value and associated record. A caller-owned abandonment request shall remain set until the caller clears it; this comparison-count interval shall not imply an elapsed-time bound.

An exception from the uniqueness comparator may occur after the indexed values have been sorted. It need not preserve their former order or establish a compact distinct prefix, but shall retain live owners and the complete value permutation and paired associations. A throwing swap shall be outside the algorithm's admitted swap precondition.