Class Lexical
Comparator 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

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);

Compares two objects.

Parameters

comparator Object that stores the results. Types: Lexical
left The first objects.
right The second objects that is compared to left.

Data Races

Thread safety unknown!

See Also

bool isPrefix(left, right); bool isPrefix(comparator);

Test whether a sequence is the prefix of another sequence.

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

Thread safety unknown!

bool isEqual(left, right); bool isEqual(comparator);

Operator "==".

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

Thread safety unknown!

bool isGreater(left, right); bool isGreater(comparator);

Operator ">".

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

Thread safety unknown!

bool isGreaterOrEqual(left, right); bool isGreaterOrEqual(comparator);

Operator ">=".

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

Thread safety unknown!

bool isLess(left, right); bool isLess(comparator);

Operator "<".

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

Thread safety unknown!

bool isLessOrEqual(left, right); bool isLessOrEqual(comparator);

Operator "<=".

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

Thread safety unknown!

bool isNotEqual(left, right); bool isNotEqual(comparator);

Operator "!=".

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

Thread safety unknown!

bool isPrefix(left, right); bool isPrefix(comparator);

Test whether a sequence is the prefix of another sequence.

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

Thread safety unknown!

TSize lcpLength(left, right); TSize lcpLength(comparator);

Length of the longest common prefix.

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.

Data Races

Thread safety unknown!