Tesseract 0.28.4
Loading...
Searching...
No Matches
tesseract::common::OrderedIdPair< Tag > Struct Template Reference

Canonically ordered pair of ids with cached combined hash — the key type for pair-keyed maps (ACM, collision margins, collision coefficients). More...

#include <types.h>

Public Member Functions

 OrderedIdPair (const NameId< Tag > &a, const NameId< Tag > &b)
void assign (const NameId< Tag > &a, const NameId< Tag > &b)
 In-place equivalent of *this = OrderedIdPair(a, b): re-canonicalizes and reuses the existing ids' string capacity, so reassigning a long-lived pair performs no allocation once capacity suffices.
const NameId< Tag > & first () const noexcept
const NameId< Tag > & second () const noexcept
std::size_t hash () const noexcept
std::pair< const std::string &, const std::string & > orderedNameView () const &noexcept
 References to the two names, lexicographically smaller first.
std::pair< const std::string &, const std::string & > orderedNameView () const &&=delete
bool operator== (const OrderedIdPair &other) const noexcept
 Hybrid equality: both values are compared first, the names confirm on matches.
bool operator!= (const OrderedIdPair &other) const noexcept
bool operator< (const OrderedIdPair &other) const noexcept
 Lexicographic by (first, second) under NameId ordering; consistent with operator==.

Detailed Description

template<typename Tag>
struct tesseract::common::OrderedIdPair< Tag >

Canonically ordered pair of ids with cached combined hash — the key type for pair-keyed maps (ACM, collision margins, collision coefficients).

Stores the two full NameIds (values AND names) so pair equality can confirm names whenever the hash values match — the same hybrid scheme as NameId::operator==. This makes every pair-keyed container watertight against hash collisions: colliding pairs compare unequal and coexist as distinct keys, exactly as in a string-keyed hash map.

Canonicalization orders by (value, then name on value ties), so OrderedIdPair(a, b) == OrderedIdPair(b, a) holds even when a and b collide on the hash value.

Member Function Documentation

◆ orderedNameView()

template<typename Tag>
std::pair< const std::string &, const std::string & > tesseract::common::OrderedIdPair< Tag >::orderedNameView ( ) const &
inlinenodiscardnoexcept

References to the two names, lexicographically smaller first.

first() and second() order by hash value, which is a runtime property and not alphabetical. Anything writing the pair somewhere its order is observable — an archive, a document, a file — must use this instead, or the output depends on the hashing implementation.

The result references this pair's names and does not own them. Besides the usual rule that it must not outlive the pair, assign() re-canonicalizes in place and reuses the ids' string capacity, so a result taken before an assign() is invalidated by it even though the pair itself is still alive. Copy the names if either applies.