Class
LexicalComparator for lexical comparison.
Defined in | <seqan/sequence.h> |
---|---|
Signature |
template <[typename TSpec]>
class Lexical;
|
Template Parameters
TSpec |
The specializing size type, defaults to size_t. |
---|
Interface Function Overview
-
void compare(comparator, left, right);
Compares two objects. -
bool isPrefix(left, right);, bool isPrefix(comparator);
Test whether a sequence is the prefix of another sequence. -
bool isEqual(left, right);, bool isEqual(comparator);
Operator "==". -
bool isGreater(left, right);, bool isGreater(comparator);
Operator ">". -
bool isGreaterOrEqual(left, right);, bool isGreaterOrEqual(comparator);
Operator ">=". -
bool isLess(left, right);, bool isLess(comparator);
Operator "<". -
bool isLessOrEqual(left, right);, bool isLessOrEqual(comparator);
Operator "<=". -
bool isNotEqual(left, right);, bool isNotEqual(comparator);
Operator "!=". -
bool isPrefix(left, right);, bool isPrefix(comparator);
Test whether a sequence is the prefix of another sequence. -
TSize lcpLength(left, right);, TSize lcpLength(comparator);
Length of the longest common prefix.
Detailed Description
This class implement comparator objects that perform (lexical) comparisons between two sequences. The result of the comparison is stored in the data members of the instance and can be accessed by some functions, for example isLess or isEqual.
In most cases, there is no need for an explicite use of comparators, but sometimes this concept provide the opportunity to speed up the code.
Examples
This program compares the strings str1 and str2:
if (isLess(str1, str2)) //first comparison
{
//str1 < str2
}
else if (isGreater(str1, str2)) //second comparison
{
//str1 > str2
}
else
{
//str == str2
}
Using a comparator, the same program only needs one comparison instead of two:
Lexical <> comparator(str1, str2); //comparison is executed here
if (isLess(comparator))
{
//str1 < str2
}
else if (lexGreater(comparator))
{
//str1 > str2
}
else
{
//str == str2
}
The state of a default constructed Lexical instance is undefined until it is set by a call of compare.
See Also
Interface Functions Detail
void compare(comparator, left, right);
Parameters
comparator
|
Object that stores the results. Types: Lexical |
---|---|
left
|
The first objects. |
right
|
The second objects that is compared to left. |
Data Races
See Also
bool isPrefix(left, right);
bool isPrefix(comparator);
Parameters
left
|
The first sequence. |
---|---|
right
|
The putative prefix. |
comparator
|
A comparator. Types: Lexical |
Returns
bool |
true if left is a prefix ofright, false otherwise. |
---|
By definition, a sequence is a prefix of itself: hasPrefix("abc", "abc") is true.
Data Races
bool isEqual(left, right);
bool isEqual(comparator);
Parameters
left
|
The first parameter. |
---|---|
right
|
The second parameter that is compared to left. |
comparator
|
A comparator. Types: Lexical |
Returns
bool |
true if left equals right, false otherwise. |
---|
Data Races
bool isGreater(left, right);
bool isGreater(comparator);
Parameters
left
|
The first parameter. |
---|---|
right
|
The second parameter that is compared to left. |
comparator
|
A comparator. Types: Lexical |
Returns
bool |
true if left is greater than right, false otherwise. |
---|
Data Races
bool isGreaterOrEqual(left, right);
bool isGreaterOrEqual(comparator);
Parameters
left
|
The first parameter. |
---|---|
right
|
The second parameter that is compared to left. |
comparator
|
A comparator. Types: Lexical |
Returns
bool |
true if left is greater than or equal to right, false otherwise. |
---|
Data Races
bool isLess(left, right);
bool isLess(comparator);
Parameters
left
|
The first parameter. |
---|---|
right
|
The second parameter that is compared to left. |
comparator
|
A comparator. Types: Lexical |
Returns
bool |
true if left is less than right, false otherwise. |
---|
Data Races
bool isLessOrEqual(left, right);
bool isLessOrEqual(comparator);
Parameters
left
|
The first parameter. |
---|---|
right
|
The second parameter that is compared to left. |
comparator
|
A comparator. Types: Lexical |
Returns
bool |
true if left is less than or equal to right, false otherwise. |
---|
Data Races
bool isNotEqual(left, right);
bool isNotEqual(comparator);
Parameters
left
|
The first parameter. |
---|---|
right
|
The second parameter that is compared to left. |
comparator
|
A comparator. Types: Lexical |
Returns
bool |
true if left does not equal right, false otherwise. |
---|
Data Races
bool isPrefix(left, right);
bool isPrefix(comparator);
Parameters
left
|
The putative prefix. |
---|---|
right
|
The second sequence. |
comparator
|
A comparator. Types: Lexical |
Returns
bool |
true if left is a prefix ofright, false otherwise. |
---|
By definition, a sequence is a prefix of itself: isPrefix("abc", "abc") is true.
Data Races
TSize lcpLength(left, right);
TSize lcpLength(comparator);
Parameters
left
|
The first sequence. |
---|---|
right
|
The second sequence. |
comparator
|
A comparator. Types: Lexical |
Returns
TSize |
The length of the longest common prefix of left and right. TSize is the Size type of the left size type. |
---|
By definition, a sequence is a prefix of itself: hasPrefix("abc", "abc") is true.