Parma Polyhedra Library requirements
Internal indirect sorting and ownership-preserving swaps

Internal indirect sorting and ownership-preserving swaps

UID:
VERSION:
CLASSIFICATION:
PREFIX:
Type
Level
MID
UID
REFS
Title
Statement
Rationale
Comment
BIBLIOGRAPHY
STATUS
COMPONENT
APPLICABILITY
VERIFICATION_METHODS
VERIFICATION_CRITERIA
SOURCE
LANGUAGE
VISIBILITY
INTERFACE
SW_SPEC
1
PPL-SPEC-000531
PPL-SPEC-000531
Borrowed offset adapter for ordering comparisons

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.

Index sorting must compare original row values at the intended offset while retaining their owners.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check default and nonzero offsets, supplied stateful comparators and default comparators, adapter copies and changed borrowed elements; ensure the container sequence is not reordered.

src/swapping_sort_templates.hh; tests/swappingsortspec1.cc.

CPP
Internal

Internal source header: swapping_sort_templates.hh, with the configured assertion macros from assertions.hh available. Names belong to Parma_Polyhedra_Library::Implementation.

template <typename RA_Container, typename Compare>
struct Indirect_Sort_Compare {
  typedef typename RA_Container::size_type size_type;
  Indirect_Sort_Compare(const RA_Container& cont,
                       size_type base = 0, Compare comp = Compare());
  bool operator()(size_type i, size_type j) const;
};
SW_SPEC
2
PPL-SPEC-000532
PPL-SPEC-000532
Borrowed offset adapter for equality comparisons

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.

Duplicate selection must use the row equality relation at the same coordinates as ordering.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check equal and unequal indexed values with default/nonzero bases, copied adapters and later owner changes, preserving all entries.

src/swapping_sort_templates.hh; tests/swappingsortspec1.cc.

CPP
Internal

Internal source header: swapping_sort_templates.hh, with the configured assertion macros from assertions.hh available. Names belong to Parma_Polyhedra_Library::Implementation.

template <typename RA_Container>
struct Indirect_Unique_Compare {
  typedef typename RA_Container::size_type size_type;
  Indirect_Unique_Compare(const RA_Container& cont, size_type base = 0);
  bool operator()(size_type i, size_type j) const;
};
SW_SPEC
3
PPL-SPEC-000533
PPL-SPEC-000533
Single-container indexed swapping

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.

Numerical rows can transfer ownership by swapping even when copying is expensive or unavailable.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Use element types with deleted copy and move operations and an ADL swap, verify complete value exchanges at nonzero offsets and guards, and check self-indices, copied adapters and standard scalar swaps.

src/swapping_sort_templates.hh; tests/swappingsortspec1.cc.

CPP
Internal

Internal source header: swapping_sort_templates.hh, with the configured assertion macros from assertions.hh available. Names belong to Parma_Polyhedra_Library::Implementation.

template <typename RA_Container>
struct Indirect_Swapper {
  typedef typename RA_Container::size_type size_type;
  Indirect_Swapper(RA_Container& cont, size_type base = 0);
  void operator()(size_type i, size_type j) const;
};
SW_SPEC
4
PPL-SPEC-000534
PPL-SPEC-000534
Paired indexed swaps preserve associations

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.

Rows and their saturation records must undergo the same permutation while generic adapters retain their actual sequential alias semantics.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Check distinct containers of different element types, noncopyable ADL-swapped owners, outside entries, equal indices and both borrows aliasing one container.

src/swapping_sort_templates.hh; tests/swappingsortspec1.cc.

CPP
Internal

Internal source header: swapping_sort_templates.hh, with the configured assertion macros from assertions.hh available. Names belong to Parma_Polyhedra_Library::Implementation.

template <typename RA_Container1, typename RA_Container2>
struct Indirect_Swapper2 {
  typedef typename RA_Container1::size_type size_type;
  Indirect_Swapper2(RA_Container1& cont1, RA_Container2& cont2);
  void operator()(size_type i, size_type j) const;
};
SW_SPEC
5
PPL-SPEC-000535
Indirect sorting establishes a distinct prefix without resizing

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.

Sorting an index vector avoids copying owned numerical rows and allows callers to remove the duplicate suffix themselves.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Compare complete prefixes, returned counts and full record permutations with independent models over exhaustive small key sequences, offsets, empty/full duplicate classes and large inputs; retain paired payload identities, guards and noncopyable ownership.

src/swapping_sort_templates.hh; tests/swappingsortspec1.cc.

CPP
Internal

Internal source header: swapping_sort_templates.hh, with the configured assertion macros from assertions.hh available. Names belong to Parma_Polyhedra_Library::Implementation.

template <typename Sort_Comparer, typename Unique_Comparer, typename Swapper>
typename Sort_Comparer::size_type
indirect_sort_and_unique(typename Sort_Comparer::size_type num_elems,
                         Sort_Comparer sort_cmp,
                         Unique_Comparer unique_cmp,
                         Swapper indirect_swap);
SW_SPEC
6
PPL-SPEC-000536
PPL-SPEC-000536
Indirect-sort failure and cooperative interruption states

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.

Cancellation and comparison failures must not lose owned rows or detach saturation records from them.

APPROVED
CORE_DATA_STRUCTURES
IF_CPP
Test, Analysis, Inspection

Inject an index-vector allocation failure and ordering-comparator exceptions before mutation; request cancellation at entry, during a long index sort and before a short sort commits; verify unchanged complete records and retained requests. Throw during uniqueness after sorting and check live paired permutations without assuming rollback.

src/swapping_sort_templates.hh; tests/swappingsortspec1.cc.

CPP
Internal

Internal source header: swapping_sort_templates.hh, with the configured assertion macros from assertions.hh available. Names belong to Parma_Polyhedra_Library::Implementation.

template <typename Sort_Comparer, typename Unique_Comparer, typename Swapper>
typename Sort_Comparer::size_type
indirect_sort_and_unique(typename Sort_Comparer::size_type num_elems,
                         Sort_Comparer sort_cmp,
                         Unique_Comparer unique_cmp,
                         Swapper indirect_swap);