libsemigroups  v3.3.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
WtLexCompare

Defined in order.hpp.

A stateful struct with binary call operator using wt_lex_compare or wt_lex_compare_no_checks, depending on the value of the constructor parameter should_check. This struct stores a copy of a weights vector and can be used as a template parameter for standard library containers or algorithms that require a comparison functor.

Warning
When the constructor parameter should_check is false, the call operator does not check that letters are valid indices into the weights vector. Use the constructor with should_check set to true (checks) to enable argument checking in the call operator.
See also

Static Public Attributes

static constexpr bool checks = true
 Constant to enable validity checks.
 
static constexpr bool no_checks = false
 Constant to disable validity checks.
 

Public Member Functions

 WtLexCompare (std::vector< size_t > &&weights, bool should_check)
 Construct from weights vector rvalue reference and specify whether or not the call operator should check its arguments.
 
 WtLexCompare (std::vector< size_t > const &weights, bool should_check)
 Construct from weights vector reference and specify whether or not the call operator should check its arguments.
 
template<typename Thing>
bool call_no_checks (Thing const &x, Thing const &y) const
 Call operator that does no checks.
 
WtLexCompareinit (std::vector< size_t > &&weights, bool should_check)
 Reinitialize an existing WtLexCompare object.
 
WtLexCompareinit (std::vector< size_t > const &weights, bool should_check)
 Reinitialize an existing WtLexCompare object.
 
template<typename Thing>
bool operator() (Thing const &x, Thing const &y) const
 Call operator that compares x and y using either wt_lex_compare or wt_lex_compare_no_checks.
 
bool should_check () const noexcept
 Returns the value of the constructor parameter should_check.
 
WtLexCompareshould_check (bool val) noexcept
 Set the value of the constructor parameter should_check.
 
std::vector< size_t > const & weights () const noexcept
 Returns the weights.
 
WtLexCompareweights (std::vector< size_t > const &val)
 Set the weights.
 

Constructor & Destructor Documentation

◆ WtLexCompare() [1/2]

WtLexCompare ( std::vector< size_t > const & weights,
bool should_check )
inline

Constructs a comparison object that stores a copy of the provided weights vector, where the ith index corresponds to the weight of the ith letter in the alphabet. The should_check parameter determines whether the call operator will validate that letters are valid indices.

Parameters
weightsthe weights vector.
should_checkif true (checks), the call operator will check validity; if false (no_checks), it will not.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ WtLexCompare() [2/2]

WtLexCompare ( std::vector< size_t > && weights,
bool should_check )
inline

Constructs a comparison object that takes ownership of the provided weights vector, where the ith index corresponds to the weight of the ith letter in the alphabet. The should_check parameter determines whether the call operator will validate that letters are valid indices.

Parameters
weightsthe weights vector.
should_checkif true (checks), the call operator will check validity; if false (no_checks), it will not.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

Member Function Documentation

◆ call_no_checks()

template<typename Thing>
bool call_no_checks ( Thing const & x,
Thing const & y ) const
inlinenodiscard

This member function always uses wt_lex_compare_no_checks to compare x and y, regardless of the value of the constructor parameter should_check. Use this when you want to ensure validation is not performed.

Template Parameters
Thingthe type of the objects to be compared.
Parameters
xconst reference to the first object for comparison.
yconst reference to the second object for comparison.
Returns
The boolean value true if x is weighted lex less than y, and false otherwise.
Exceptions
This function guarantees not to throw a LibsemigroupsException.
Complexity
See wt_lex_compare_no_checks(Iterator, Iterator, Iterator, Iterator, std::vector<size_t> const&).

◆ init() [1/2]

WtLexCompare & init ( std::vector< size_t > && weights,
bool should_check )
inline

This function reinitializes an existing WtLexCompare object so that it is in the same state as if it was newly constructed using the same arguments.

Parameters
weightsthe weights vector.
should_checkif true (checks), the call operator will check validity; if false (no_checks), it will not.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ init() [2/2]

WtLexCompare & init ( std::vector< size_t > const & weights,
bool should_check )
inline

This function reinitializes an existing WtLexCompare object so that it is in the same state as if it was newly constructed using the same arguments.

Parameters
weightsthe weights vector.
should_checkif true (checks), the call operator will check validity; if false (no_checks), it will not.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ operator()()

template<typename Thing>
bool operator() ( Thing const & x,
Thing const & y ) const
inlinenodiscard

Call operator that compares x and y using wt_lex_compare (if the constructor parameter should_check is true) or wt_lex_compare_no_checks (if should_check is false).

Template Parameters
Thingthe type of the objects to be compared.
Parameters
xconst reference to the first object for comparison.
yconst reference to the second object for comparison.
Returns
The boolean value true if x is weighted lex less than y, and false otherwise.
Exceptions
LibsemigroupsExceptionif should_check is true and any letter is not a valid index into the weights vector.
Complexity
See:
Warning
If the constructor parameter should_check is false, it is not checked that the letters are valid indices into the weights vector.

◆ should_check() [1/2]

bool should_check ( ) const
inlinenodiscardnoexcept

This function returns the current value of the constructor parameter should_check.

Returns
Whether or not the call operator is checking its arguments.
Exceptions
This function is noexcept and is guaranteed never to throw.
See also
should_check(bool)

◆ should_check() [2/2]

WtLexCompare & should_check ( bool val)
inlinenoexcept

This function sets the value of should_check to val. This parameter determines whether or not the call operator is checking its arguments.

Parameters
valthe new value of should_check.
Returns
A reference to *this.
Exceptions
This function is noexcept and is guaranteed never to throw.
See also
should_check()

◆ weights() [1/2]

std::vector< size_t > const & weights ( ) const
inlinenodiscardnoexcept

This function returns the current value of the weights used to define the comparison implemented by WtLexCompare.

Returns
The current weights.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ weights() [2/2]

WtLexCompare & weights ( std::vector< size_t > const & val)
inline

This function can be used to redefine the weights used to define the comparison implemented by WtLexCompare.

Parameters
valthe new weights to use.
Returns
A reference to *this.

Member Data Documentation

◆ checks

bool checks = true
staticconstexpr

This constant can be used in the constructors to indicate that checks should be performed on the arguments to the call operator.

◆ no_checks

bool no_checks = false
staticconstexpr

This constant can be used in the constructors to indicate that no checks should be performed on the arguments to the call operator.


The documentation for this struct was generated from the following file: