Parma Polyhedra Library requirements
C++ coordinate maps: Partial_Function

C++ coordinate maps: Partial_Function

1. Public partial coordinate-map type and valid use
UID: PPL-SPEC-000001
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection, Review
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

The public C++ interface shall expose Partial_Function as a value type representing a finite injective partial map M from dimension indices to dimension indices. Each mapped source shall have exactly one image, and distinct mapped sources shall have distinct images. Neither a stored source nor a stored image shall equal the reserved value not_a_dimension(), the maximum value of dimension_type. An unmapped index shall have no image.

The map shall impose no implicit ambient dimension, contiguity of mapped indices, or requirement that its images cover a contiguous range. Limits on achievable storage shall remain distinct from the index type's value range and from the coordinate limits of numerical objects consuming a map. In particular, the insertion range shall not be narrowed to the smaller range accepted by Variable formatting.

Operations on existing objects shall require live, valid maps. Successful moves between distinct objects shall leave the source as a valid empty map, as defined by 🔗 9. Move construction and empty source and 🔗 10. Move assignment and empty source. Within the library's supported thread-use contexts, callers shall prevent unsynchronized mutation of an instance while another call observes, copies or prints it, and shall serialize mutations of that instance. No additional concurrent-use regime shall be inferred from the type being a value type.

RATIONALE:

A coordinate-map value has a meaning independent of its storage extent and of the domain that consumes it. Its index range, storage capacity, printing range and consumer limits are distinct.

COMMENT:

Map storage uses dimension indices independently of configured coefficient arithmetic and rounding modes. Diagnostic printing uses the formatter and thread state described by 🔗 8. Coordinate-map diagnostic printing and output failures.

INTERFACE:

Public header: <ppl.hh>. Public type declaration:

namespace Parma_Polyhedra_Library {
  class Partial_Function;
}

Member declarations in the following contracts belong to this class. Indices use the public dimension_type and not_a_dimension() names.

VERIFICATION_CRITERIA:

Compile representative C++20 clients against the configured installed public header and matching library. Review the generated public exposure and configuration-dependent assertion layout. Compare valid maps against an independent finite collection of distinct source/image pairs, including sparse domains, noncontiguous images and image zero. Review the covered-use, post-failure and synchronization conditions against the operation contracts. Do not infer an achievable allocation for every value of dimension_type or unrestricted concurrency from successful sequential tests.

SOURCE:

src/Partial_Function_defs.hh: public type and member declarations. src/globals_types.hh and src/globals_inlines.hh: dimension_type and reserved index. src/Makefile.am: Partial_Function headers in generated public ppl.hh. tests/partialfunction2.cc: direct finite-map query and copying scenarios. tests/partialfunction3.cc: installed-public-header C++20 client.

PPL-SPEC-000002
2. Empty partial-map construction
UID: PPL-SPEC-000002
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

Successful default construction shall create a valid Partial_Function whose domain and image are empty, with the meaning and use conditions of 🔗 1. Public partial coordinate-map type and valid use. No index shall initially be mapped. If construction fails through a supported C++ exception, resources acquired for the incomplete object shall be released and no constructed map shall be returned.

RATIONALE:

An empty initial map gives clients a defined starting point for incremental insertion and distinguishes an absent image from a maximum-image value.

COMMENT:

The constructor's private maximum-image bookkeeping is not an observable maximum for the empty map.

INTERFACE:

Public constructor declaration:

Partial_Function();
VERIFICATION_CRITERIA:

After construction, check empty-codomain reporting and unsuccessful lookups at zero, ordinary absent indices and the reserved sentinel, preserving each caller's output value. Check the defined empty maximum-query exception. Inspect construction and member cleanup; use fault injection only where the selected construction path actually acquires resources that can fail.

SOURCE:

src/Partial_Function_defs.hh and src/Partial_Function_inlines.hh: default constructor. tests/partialfunction2.cc: partial_function_empty_queries_preserve_output.

3. Injective insertion and failure atomicity
UID: PPL-SPEC-000003
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection, Review
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For a valid map as defined by 🔗 1. Public partial coordinate-map type and valid use, insertion shall require both indices to differ from not_a_dimension(), the source index to be absent from the current domain, and the proposed image to be absent from the current image set. A successfully completed insertion of i and j shall add exactly the pair M(i) = j, preserve every existing pair and leave every other absent source unmapped. Gaps introduced by storage growth shall not become mappings. The operation shall permit image zero and noncontiguous source and image sets.

Storage-capacity or allocation failure shall be reported through the corresponding C++ exception, including std::length_error or std::bad_alloc where applicable. Such a failed insertion shall leave the represented map unchanged and valid for subsequent queries, insertion, assignment and destruction.

Violation of the insertion preconditions shall be outside the supported contract. Assertion diagnostics shall not be required in every configuration, and no defined success or failure outcome shall be promised for such a call.

RATIONALE:

Unique sources and unique images maintain injectivity. Failure atomicity allows callers to retain and reuse a map after a storage failure.

INTERFACE:

Public member declaration:

void insert(dimension_type i, dimension_type j);

Index values alone do not guarantee feasible storage growth. Insertion preconditions are independent of the assertion regime selected for the library.

VERIFICATION_CRITERIA:

Build independent finite-map histories with distinct sources and images, including holes across storage boundaries, decreasing and increasing images, and zero as an image. After every successful insertion compare all stored pairs, absent lookups, emptiness and the largest image against the oracle. For available assertion regimes, inject failures at each actual allocation stage and verify exception propagation, preservation of the original pairs, absence of the proposed source, emptiness and maximum before retrying the same insertion. Check storage-capacity rejection with std::length_error using a source whose required extent exceeds the configured container's maximum size, without attempting a huge allocation; verify unchanged state and subsequent valid insertion. Inspect rollback and owned-resource cleanup. Review precondition enforcement separately without requiring release-build rejection of duplicate or reserved indices or attempting infeasible huge allocations.

SOURCE:

src/Partial_Function_defs.hh: insertion preconditions and invalid-call scope. src/Partial_Function_inlines.hh: insertion and rollback of codomain bookkeeping. tests/partialfunction2.cc: partial_function_sparse_growth_preserves_holes_and_maximum. tests/partialfunction1.cc: allocation-failure preservation and retry. tests/partialfunction1.cc: capacity_rejection_preserves_and_reuses_the_map. doc/definitions.dox: general public exception-safety description.

PPL-SPEC-000004
4. Exact partial-map lookup and unchanged absent output
UID: PPL-SPEC-000004
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For a valid map under 🔗 1. Public partial coordinate-map type and valid use, lookup of i shall return true exactly when i ∈ dom(M). On true, it shall assign M(i) to j. On false, it shall leave j unchanged. The represented map shall remain unchanged. Every dimension_type value shall be admissible as a lookup index; in particular, lookup of not_a_dimension() shall return false without changing j. The same caller variable may supply the index value and receive the image; the index used for lookup shall be its value on entry to the call.

RATIONALE:

Absence must be distinguishable from a mapping to zero, and an unsuccessful lookup must not corrupt a caller's previously held value.

COMMENT:

Lookup is a complete membership-and-image query. It performs no numerical coefficient conversion and is independent of configured coefficient arithmetic and rounding modes.

INTERFACE:

Public const member declaration:

bool maps(dimension_type i, dimension_type& j) const;

The output reference shall designate a live writable dimension_type object.

VERIFICATION_CRITERIA:

Check mapped indices, holes below the largest stored source, indices beyond the stored extent, empty maps and the reserved sentinel. Initialize outputs to distinct known values and verify preservation on every false result. Check mapping to zero and calls using one variable for both arguments. Compare the map before and after queries using an independent pair collection.

SOURCE:

src/Partial_Function_defs.hh and src/Partial_Function_inlines.hh: maps. tests/partialfunction2.cc: partial_function_empty_queries_preserve_output and partial_function_sparse_growth_preserves_holes_and_maximum. tests/partialfunction2.cc: partial_function_aliased_lookup_and_zero_image.

5. Exact empty-codomain query
UID: PPL-SPEC-000005
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For a valid map under 🔗 1. Public partial coordinate-map type and valid use, has_empty_codomain shall return true exactly when the represented partial map has no pairs, and shall leave the map unchanged. A nonempty map whose largest image is zero shall return false. Stored capacity or unused source positions shall not determine the mathematical answer.

RATIONALE:

The image is empty exactly when a partial function is nowhere defined; zero is an ordinary mapped value rather than an emptiness sentinel.

INTERFACE:

Public const member declaration:

bool has_empty_codomain() const;
VERIFICATION_CRITERIA:

Check new and copied empty maps, maps containing a single image zero, and sparse nonempty maps. Compare with the independent pair collection before and after successful insertions and copy assignments. Check reporting after failed insertions and copy assignments.

SOURCE:

src/Partial_Function_defs.hh and src/Partial_Function_inlines.hh: has_empty_codomain. tests/partialfunction2.cc: partial_function_empty_queries_preserve_output and partial_function_sparse_growth_preserves_holes_and_maximum.

6. Largest image and defined empty-map failure
UID: PPL-SPEC-000006
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For a nonempty valid map under 🔗 1. Public partial coordinate-map type and valid use, max_in_codomain shall return the largest image value, independently of insertion order and of the largest source index. If the valid map is empty, the call shall throw std::runtime_error rather than return a maximum value. The map shall remain unchanged on either outcome. The empty call shall be a defined failure case, not an excluded precondition. Exact exception-message text is not prescribed; ordinary C++ runtime/resource conditions for reporting the exception apply.

RATIONALE:

A maximum is meaningful only for a nonempty finite image, and callers must not mistake the private empty-state bookkeeping for an observable result.

COMMENT:

The empty-query exception and the absence outcome of maps are distinct outcomes, both of which preserve the map.

INTERFACE:

Public const member declaration:

dimension_type max_in_codomain() const;
VERIFICATION_CRITERIA:

Compare with independently computed maxima after increasing, decreasing and sparse insertions, including a sole image zero and image values unrelated to the source ordering. Check std::runtime_error on an empty map, without an exact-message assertion, and verify subsequent permitted use of that map. Include a large permitted image with a small source so that testing the image range does not require an infeasible storage allocation.

SOURCE:

src/Partial_Function_defs.hh and src/Partial_Function_inlines.hh: max_in_codomain. tests/partialfunction2.cc: partial_function_empty_queries_preserve_output and partial_function_sparse_growth_preserves_holes_and_maximum.

PPL-SPEC-000007
7. Independent copies, assignment and owned-storage cleanup
UID: PPL-SPEC-000007
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection, Review
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

Copy construction shall require a live, valid source map under 🔗 1. Public partial coordinate-map type and valid use. Successful copy construction shall create a distinct value with exactly the source's mapping. Copy assignment shall require live, valid source and target maps and, on success, shall replace the target's old map with exactly the source's mapping. Subsequent valid insertion into either distinct value shall not change the other's mapping. Successful self-copy-assignment shall preserve the map. Successful copy assignment shall return a reference to its target, including self-copy-assignment.

Failed copy construction shall release resources acquired for the incomplete target and shall leave the source unchanged. Failed copy assignment shall leave both source and target unchanged and valid for subsequent use. Destruction of a live map shall release its owned storage without releasing another map's storage. The caller shall not access an object after its lifetime ends.

RATIONALE:

Independent values support reuse of a coordinate map without hidden changes to a consumer's other maps. Completing the copy before replacing the target preserves the target if acquisition of the copy's storage fails.

INTERFACE:

Public copy members and the callable form of the implicit destructor:

Partial_Function(const Partial_Function& source) = default;
Partial_Function& operator=(const Partial_Function& source);
~Partial_Function();
VERIFICATION_CRITERIA:

Copy empty and sparse nonempty maps by construction and assignment. Compare both values with independent pair collections, mutate each separately using valid insertions, and check self-copy-assignment. Use actual copy overloads rather than treating an assignment from a temporary as a copy test. Check returned-reference identity for ordinary and self-copy-assignment, and check chained copy assignments. Inspect member ownership and construction cleanup. Inject failures at actual copy-allocation stages, checking source and target preservation before retry. After failed assignment, check the target over the union of the old target's and source's positions, including absence at positions that belonged only to the source. Check successful retry after failed assignment.

SOURCE:

src/Partial_Function_defs.hh: copy members, implicit destructor and owned containers. src/Partial_Function_inlines.hh: copy assignment and representation exchange. tests/partialfunction2.cc: copy-construction, lvalue-assignment and self-copy-assignment portions of partial_function_copies_and_assignment_have_independent_storage. tests/partialfunction2.cc: partial_function_copy_assignment_returns_its_target. tests/partialfunction1.cc: copy construction and assignment under allocation failure. doc/definitions.dox: general public exception-safety description.

8. Coordinate-map diagnostic printing and output failures
UID: PPL-SPEC-000008
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection, Review
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

Printing shall observe a valid map under 🔗 1. Public partial coordinate-map type and valid use without changing its represented mapping. Calls shall require the library and calling thread's applicable initialization protocol to have established a valid active Variable output function under 🔗 7. Active Variable formatter and initialized thread state and 🔗 3. Thread initialization, default state and finalization. Callers shall obey the supported thread regime and synchronize changes to the active formatter and access to a shared stream; the formatter shall not mutate the printed map during the call.

When the map is empty and output succeeds, print shall write the literal text "empty", a newline and a flush. For a nonempty map whose source and image indices are all constructible as Variable objects, successful output shall process pairs in increasing source order. For each pair it shall write the source Variable using the Variable formatter active for that write, the literal separator " --> ", the image Variable using the formatter active for its write, and a trailing newline. Each Variable write shall use the formatter then active in the calling thread where formatting state is thread-specific; names shall not be fixed independently of it. A callback's permitted change to that formatting state may therefore affect subsequent Variable writes. Text insertions shall honor the stream's current formatting state. Specified literals identify the inserted character sequences, not a canonical byte layout independent of that state. Printing shall not promise restoration of formatting state changed by a formatter.

A map index outside Variable's accepted identifier range shall be permitted to cause std::length_error during printing, without changing the map. Stream, formatter and resource failures may also propagate their C++ exceptions. Stream failure without an enabled exception shall be observable through the stream state; a normal void return shall not alone establish complete output. After any such failure the output may be partial, but the map shall remain valid and unchanged. Exact diagnostic messages are not prescribed.

RATIONALE:

Diagnostic printing depends on the map and active naming convention. Storage-valid map indices can exceed the printable Variable range. Stream failure can occur after earlier output, leaving partial output.

COMMENT:

Diagnostic output has no reloadability or cross-version stability guarantee. Formatting depends on the active output function and its thread context.

INTERFACE:

Public const member declaration:

void print(std::ostream& s) const;

The stream shall be live and usable under its own C++ contract. Complete output requires the stream to continue accepting output and the formatter to complete its writes. A Variable identifier shall be strictly smaller than Variable::max_space_dimension(); this additional print limit shall not change the valid insertion range in 🔗 3. Injective insertion and failure atomicity.

VERIFICATION_CRITERIA:

Check empty output including flush, and independently derive the ordered pair sequence for sparse maps. Check default formatting and configured field width and fill for both empty and nonempty maps, and integer formatting for nonempty maps, without assuming format-independent bytes. Exercise the default and a custom Variable formatter under the applicable initialization/thread protocol, including a callback that changes the formatter for subsequent writes. With a small source index, insert image not_a_dimension()-1 and check the admitted std::length_error without changing the map. Use failing streams with and without enabled exceptions and a throwing formatter; check stream state, allowed partial output and continued map validity. Review synchronization and restore any formatter/thread state used by verification activities.

SOURCE:

src/Partial_Function.cc: print ordering, separator, empty flush and Variable construction. src/Variable_inlines.hh and src/Variable.cc: accepted Variable identifiers and active output function. src/Init.cc and src/Init_inlines.hh: initialization of applicable Variable formatting state. tests/partialfunction2.cc: empty and default-name output checks in the direct Partial_Function scenarios. tests/partialfunction2.cc: partial_function_empty_print_flushes, partial_function_print_uses_current_variable_formatter, partial_function_print_honors_stream_formatting, partial_function_print_failures_preserve_map_and_formatter_state and partial_function_print_keeps_thread_formatters_independent.

PPL-SPEC-000009
9. Move construction and empty source
UID: PPL-SPEC-000009
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

Move construction from a valid map under 🔗 1. Public partial coordinate-map type and valid use shall create a distinct valid map with exactly the source's mapping on entry and shall leave the source as a valid empty map. The source shall support the same queries, insertions, assignments and destruction as any other empty map. Subsequent valid changes to either object shall not change the other's map.

If construction of the destination's empty storage fails, resources acquired for the incomplete destination shall be released and the source shall remain unchanged and valid. After the empty storage has been constructed, transferring the represented map shall not allocate storage or throw.

The move constructor's exception specification shall be nonthrowing exactly when default construction of its configured storage containers is nonthrowing, as expressed by the declaration below. The debug codomain container shall contribute to that condition only when present.

RATIONALE:

Transferring a coordinate map avoids copying its stored pairs. An empty, reusable source preserves the value-type invariants after transfer. The exception specification accounts for the containers' actual construction guarantees instead of requiring every standard-library implementation to construct an empty container without throwing.

INTERFACE:

Public move constructor declaration:

Partial_Function(Partial_Function&& source)
  noexcept(noexcept(std::vector<dimension_type>())
#ifndef NDEBUG
           && noexcept(std::set<dimension_type>())
#endif
           );
VERIFICATION_CRITERIA:

Move-construct empty and sparse nonempty maps, including image zero. Compare the destination with an independent pair collection and check source emptiness, absent-output preservation and the defined empty maximum-query exception. Insert into the source after transfer and check independence from the destination. Inspect member construction and representation exchange, including cleanup and source preservation if an actual empty-storage allocation fails. Compare allocation observations during move construction with those for default construction of the same configured empty storage, and check both empty and nonempty sources. Inject failures at any observed empty-storage allocation stage and check source preservation. Check the exception specification in configurations with and without the debug codomain container, against the configured containers' construction traits.

SOURCE:

src/Partial_Function_defs.hh and src/Partial_Function_inlines.hh: move constructor and representation exchange. tests/partialfunction2.cc: partial_function_move_construction_transfers_and_empties_source. tests/partialfunction1.cc: move_construction_allocates_only_for_empty_storage.

PPL-SPEC-000010
10. Move assignment and empty source
UID: PPL-SPEC-000010
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

Move assignment between distinct valid maps under 🔗 1. Public partial coordinate-map type and valid use shall replace the target's mapping with exactly the source's mapping on entry and leave the source as a valid empty map. Both maps shall support subsequent queries, insertions, assignments and destruction. Subsequent changes to either map shall not change the other's represented value.

Self-move-assignment shall leave the map unchanged. Move assignment shall return a reference to its target, including self-move-assignment. It shall not allocate storage or throw. Storage retained by an empty map shall remain owned by that map and shall not imply the presence of any mapped pair.

RATIONALE:

Move assignment permits reuse of an existing target without copying pairs. Defined empty-source and self-assignment behavior preserves map validity and allows continued use of both objects without inspecting storage internals.

INTERFACE:

Public move assignment declaration:

Partial_Function& operator=(Partial_Function&& source) noexcept;
VERIFICATION_CRITERIA:

Move-assign empty and sparse maps into empty and nonempty targets. Check exact target replacement, source emptiness and returned-reference identity. Reuse both objects with valid insertions and queries, including a source that receives storage previously owned by the target. Check self-move-assignment through a reference alias and chained assignments whose selected overloads are move assignments. Check the nonthrowing exception specification and arm allocation failure during assignment to check absence of allocation, including self-assignment and empty and nonempty source/target combinations. Inspect clearing and representation exchange.

SOURCE:

src/Partial_Function_defs.hh and src/Partial_Function_inlines.hh: move assignment and representation exchange. tests/partialfunction2.cc: partial_function_move_assignment_replaces_and_empties_source. tests/partialfunction1.cc: move_assignment_does_not_allocate.