-
Notifications
You must be signed in to change notification settings - Fork 171
/
sequence_lexical.h
763 lines (687 loc) · 21.8 KB
/
sequence_lexical.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
// ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2018, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Andreas Gogol-Doering <andreas.doering@mdc-berlin.de>
// ==========================================================================
// Implementation of efficient lexical sequence comparison.
// ==========================================================================
#ifndef SEQAN_HEADER_LEXICAL_H
#define SEQAN_HEADER_LEXICAL_H
namespace seqan
{
//////////////////////////////////////////////////////////////////////////////
// Switches for prefix ordering mode
//////////////////////////////////////////////////////////////////////////////
/*!
* @defgroup PrefixOrderTags Prefix Order Tags
* @brief Specify whether less-than or greather-than comparison is meant.
*
*
* @tag PrefixOrderTags#TagPrefixLess
* @headerfile <seqan/sequence.h>
* @brief A prefix is smaller.
*
* @signature typedef Tag<TagPrefixLess_> const TagPrefixLess;
*
*
* @tag PrefixOrderTags#TagPrefixGreater
* @headerfile <seqan/sequence.h>
* @brief A prefix is larger.
*
* @signature typedef Tag<TagPrefixGreater_> const TagPrefixGreater;
*/
struct TagPrefixLess_ {};
typedef Tag<TagPrefixLess_> const TagPrefixLess;
struct TagPrefixGreater_ {};
typedef Tag<TagPrefixGreater_> const TagPrefixGreater;
/*!
* @mfn DefaultPrefixOrder
* @headerfile <seqan/sequence.h>
* @brief The default prefix order.
*
* @signature DefaultPrefixOrder<T>::Type;
*
* @tparam T The type to query for the prefix order.
*
* @return Type The prefix order tag type of T, see @link PrefixOrderTags @endlink.
*/
template <typename T>
struct DefaultPrefixOrder
{
typedef TagPrefixLess Type;
};
//////////////////////////////////////////////////////////////////////////////
// Lexical
//////////////////////////////////////////////////////////////////////////////
/*!
* @class Lexical
* @headerfile <seqan/sequence.h>
* @brief Comparator for lexical comparison.
*
* @signature template <[typename TSpec]>
* class Lexical;
*
* @tparam TSpec The specializing size type, defaults to <tt>size_t</tt>.
*
* 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 @link
* Lexical#isLess @endlink or @link Lexical#isEqual @endlink.
*
* 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.
*
* @section Examples
*
* This program compares the strings <tt>str1</tt> and <tt>str2</tt>:
*
* @code{.cpp}
* if (isLess(str1, str2)) //first comparison
* {
* //str1 < str2
* }
* else if (isGreater(str1, str2)) //second comparison
* {
* //str1 > str2
* }
* else
* {
* //str == str2
* }
* @endcode
*
* Using a comparator, the same program only needs one comparison instead of two:
*
* @code{.cpp}
* Lexical <> comparator(str1, str2); //comparison is executed here
* if (isLess(comparator))
* {
* //str1 < str2
* }
* else if (lexGreater(comparator))
* {
* //str1 > str2
* }
* else
* {
* //str == str2
* }
* @endcode
*
* The state of a default constructed <tt>Lexical</tt> instance is undefined until it is set by a call of @link
* Lexical#compare @endlink.
*
* @see Comparator
*/
template <typename TSpec = size_t>
struct Lexical
{
public:
typename Size<Lexical>::Type data_lcp;
char data_compare;
public:
Lexical()
{
}
template <typename TLeft, typename TRight>
Lexical(TLeft const & left, TRight const & right)
{
compare(*this, left, right);
}
Lexical(Lexical const & other):
data_lcp(other.data_lcp),
data_compare(other.data_compare)
{
}
Lexical & operator=(Lexical const & other)
{
data_compare = other.data_compare;
data_lcp = other.data_lcp;
return *this;
}
~Lexical() {}
//____________________________________________________________________________
enum
{
EQUAL = 1,
LESS = 2,
GREATER = 4,
LEFT_IS_PREFIX = 8,
RIGHT_IS_PREFIX = 16
};
};
//////////////////////////////////////////////////////////////////////////////
// Metafunctions
//////////////////////////////////////////////////////////////////////////////
// Comparator: returns object that can compare objects of type T
// TODO(holtgrew): Does this belong to the StringConcept?
/*!
* @mfn Comparator
* @headerfile <seqan/sequence.h>
* @brief Type of comparator object
*
* @signature Comparator<T>::Type;
*
* @tparam T Type for which the comparator type is to be determined.
*
* @return Type the comparator type.
*
* Comparators are objects that can be used to compare other objects and store the result of comparisons.
*/
template <typename T>
struct Comparator
{
typedef Lexical<typename Size<T>::Type> Type;
};
//////////////////////////////////////////////////////////////////////////////
// Size
template <typename TSpec>
struct Size<Lexical<TSpec> >
{
typedef TSpec Type;
};
template <typename TSpec>
struct Size<Lexical<TSpec> const>
{
typedef TSpec Type;
};
//////////////////////////////////////////////////////////////////////////////
// Spec
template <typename TSpec>
struct Spec<Lexical<TSpec> >
{
typedef TSpec Type;
};
template <typename TSpec>
struct Spec<Lexical<TSpec> const>
{
typedef TSpec Type;
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// compare
//////////////////////////////////////////////////////////////////////////////
// TODO(holtgrew): Does this belong to Lexical?
/*!
* @fn Lexical#compare
* @headerfile <seqan/sequence.h>
* @brief Compares two objects.
*
* @signature void compare(comparator, left, right);
*
* @param[out] comparator Object that stores the results. Types: Lexical
* @param[in] left The first objects.
* @param[in] right The second objects that is compared to <tt>left</tt>.
*
* @see Comparator
*/
template <typename TSpec, typename TLeft, typename TRight>
inline void
compare_(Lexical<TSpec> & lexical,
TLeft & left,
TRight & right)
{
typename Iterator<TLeft, Standard>::Type left_it = begin(left, Standard());
typename Size<TLeft>::Type left_length = length(left);
typename Iterator<TRight, Standard>::Type right_it = begin(right, Standard());
typename Size<TRight>::Type right_length = length(right);
if (left_length == right_length) lexical.data_compare = Lexical<TSpec>::EQUAL;
else if (left_length < right_length) lexical.data_compare = Lexical<TSpec>::LEFT_IS_PREFIX;
else
{
lexical.data_compare = Lexical<TSpec>::RIGHT_IS_PREFIX;
left_length = right_length;
}
lexical.data_lcp = 0;
for (lexical.data_lcp = 0; lexical.data_lcp < left_length; ++lexical.data_lcp)
{
if (*left_it < *right_it)
{
lexical.data_compare = Lexical<TSpec>::LESS;
break;
}
if (*left_it > *right_it)
{
lexical.data_compare = Lexical<TSpec>::GREATER;
break;
}
++left_it;
++right_it;
}
}
//////////////////////////////////////////////////////////////////////////////
template <typename TSpec, typename TLeft, typename TRight>
inline void
compare(Lexical<TSpec> & lexical,
TLeft const & left,
TRight const & right)
{
compare_(lexical, left, right);
}
// TODO(holtgrew): Are these bugs present in currently supported VC++ versions or is this only a legacy issue?
//workaround for VC++ "const arrays" bug
template <typename TSpec, typename TLeftValue, typename TRight>
inline void
compare(Lexical<TSpec> & lexical,
TLeftValue const * left,
TRight const & right)
{
compare_(lexical, left, right);
}
template <typename TSpec, typename TLeftValue, typename TRightValue>
inline void
compare(Lexical<TSpec> & lexical,
TLeftValue const * left,
TRightValue const * right)
{
compare_(lexical, left, right);
}
template <typename TSpec, typename TLeft, typename TRightValue>
inline void
compare(Lexical<TSpec> & lexical,
TLeft const & left,
TRightValue const * right)
{
compare_(lexical, left, right);
}
//////////////////////////////////////////////////////////////////////////////
// isEqual
//////////////////////////////////////////////////////////////////////////////
// TODO(holtgrew): Do we need the left/right specialization of this function here?
/*!
* @fn Lexical#isEqual
* @headerfile <seqan/sequence.h>
* @brief Operator "==".
*
* @signature bool isEqual(left, right);
* @signature bool isEqual(comparator);
*
* @param[in] left The first parameter.
* @param[in] right The second parameter that is compared to <tt>left</tt>.
* @param[in] comparator A comparator. Types: Lexical
*
* @return bool <tt>true</tt> if <tt>left</tt> equals <tt>right</tt>, <tt>false</tt> otherwise.
*/
template <typename TLeft, typename TRight >
inline bool
isEqual(TLeft const & left,
TRight const & right)
{
return left == right;
}
template <typename TSpec>
inline bool
isEqual(Lexical<TSpec> const & _lex)
{
return (_lex.data_compare & Lexical<TSpec>::EQUAL);
}
//////////////////////////////////////////////////////////////////////////////
// isNotEqual
//////////////////////////////////////////////////////////////////////////////
/*!
* @fn Lexical#isNotEqual
* @headerfile <seqan/sequence.h>
* @brief Operator "!=".
*
* @signature bool isNotEqual(left, right);
* @signature bool isNotEqual(comparator);
*
* @param[in] left The first parameter.
* @param[in] right The second parameter that is compared to <tt>left</tt>.
* @param[in] comparator A comparator. Types: Lexical
*
* @return bool <tt>true</tt> if <tt>left</tt> does not equal <tt>right</tt>, <tt>false</tt> otherwise.
*/
template <typename TLeft, typename TRight >
inline bool
isNotEqual(TLeft const & left,
TRight const & right)
{
return left != right;
}
template <typename TSpec>
inline bool
isNotEqual(Lexical<TSpec> const & _lex)
{
return !(_lex.data_compare & Lexical<TSpec>::EQUAL);
}
//////////////////////////////////////////////////////////////////////////////
// isLess
//////////////////////////////////////////////////////////////////////////////
/*!
* @fn Lexical#isLess
* @headerfile <seqan/sequence.h>
* @brief Operator "<".
*
* @signature bool isLess(left, right);
* @signature bool isLess(comparator);
*
* @param[in] left The first parameter.
* @param[in] right The second parameter that is compared to <tt>left</tt>.
* @param[in] comparator A comparator. Types: Lexical
*
* @return bool <tt>true</tt> if <tt>left</tt> is less than <tt>right</tt>, <tt>false</tt> otherwise.
*/
template <typename TLeft, typename TRight, typename TPrefixOrder >
inline bool
isLess(TLeft const & left,
TRight const & right,
Tag<TPrefixOrder> const tag)
{
typename Comparator<TLeft>::Type _lex(left, right);
return isLess(_lex, tag);
}
template <typename TLeft, typename TRight>
inline bool
isLess(TLeft const & left,
TRight const & right)
{
return left < right;
}
template <typename TSpec>
inline bool
isLess(Lexical<TSpec> const & _lex,
TagPrefixLess)
{
return (_lex.data_compare & (Lexical<TSpec>::LESS | Lexical<TSpec>::LEFT_IS_PREFIX)) != 0;
}
template <typename TSpec>
inline bool
isLess(Lexical<TSpec> const & _lex,
TagPrefixGreater)
{
return (_lex.data_compare & (Lexical<TSpec>::LESS | Lexical<TSpec>::RIGHT_IS_PREFIX)) != 0;
}
template <typename TSpec>
inline bool
isLess(Lexical<TSpec> const & _lex)
{
return isLess(_lex, typename DefaultPrefixOrder< Lexical<TSpec> >::Type());
}
//////////////////////////////////////////////////////////////////////////////
// isLessOrEqual
//////////////////////////////////////////////////////////////////////////////
/*!
* @fn Lexical#isLessOrEqual
* @headerfile <seqan/sequence.h>
* @brief Operator "<=".
*
* @signature bool isLessOrEqual(left, right);
* @signature bool isLessOrEqual(comparator);
*
* @param[in] left The first parameter.
* @param[in] right The second parameter that is compared to <tt>left</tt>.
* @param[in] comparator A comparator. Types: Lexical
*
* @return bool <tt>true</tt> if <tt>left</tt> is less than or equal to <tt>right</tt>, <tt>false</tt> otherwise.
*/
template <typename TLeft, typename TRight, typename TPrefixOrder >
inline bool
isLessOrEqual(TLeft const & left,
TRight const & right,
Tag<TPrefixOrder> const tag)
{
typename Comparator<TLeft>::Type _lex(left, right);
return isLessOrEqual(_lex, tag);
}
template <typename TLeft, typename TRight>
inline bool
isLessOrEqual(TLeft const & left,
TRight const & right)
{
return left <= right;
}
template <typename TSpec>
inline bool
isLessOrEqual(Lexical<TSpec> const & _lex,
TagPrefixLess)
{
return (_lex.data_compare & (Lexical<TSpec>::LESS | Lexical<TSpec>::EQUAL | Lexical<TSpec>::LEFT_IS_PREFIX)) != 0;
}
template <typename TSpec>
inline bool
isLessOrEqual(Lexical<TSpec> const & _lex,
TagPrefixGreater)
{
return (_lex.data_compare & (Lexical<TSpec>::LESS | Lexical<TSpec>::EQUAL | Lexical<TSpec>::RIGHT_IS_PREFIX)) != 0;
}
template <typename TSpec>
inline bool
isLessOrEqual(Lexical<TSpec> const & _lex)
{
return isLessOrEqual(_lex, typename DefaultPrefixOrder< Lexical<TSpec> >::Type());
}
//////////////////////////////////////////////////////////////////////////////
// isGreater
//////////////////////////////////////////////////////////////////////////////
/*!
* @fn Lexical#isGreater
* @headerfile <seqan/sequence.h>
* @brief Operator ">".
*
* @signature bool isGreater(left, right);
* @signature bool isGreater(comparator);
*
* @param[in] left The first parameter.
* @param[in] right The second parameter that is compared to <tt>left</tt>.
* @param[in] comparator A comparator. Types: Lexical
*
* @return bool <tt>true</tt> if <tt>left</tt> is greater than <tt>right</tt>, <tt>false</tt> otherwise.
*/
template <typename TLeft, typename TRight, typename TPrefixOrder >
inline bool
isGreater(TLeft const & left,
TRight const & right,
Tag<TPrefixOrder> const tag)
{
typename Comparator<TLeft>::Type _lex(left, right);
return isGreater(_lex, tag);
}
template <typename TLeft, typename TRight>
inline bool
isGreater(TLeft const & left,
TRight const & right)
{
return left > right;
}
template <typename TSpec>
inline bool
isGreater(Lexical<TSpec> const & _lex,
TagPrefixLess)
{
return (_lex.data_compare & (Lexical<TSpec>::GREATER | Lexical<TSpec>::RIGHT_IS_PREFIX)) != 0;
}
template <typename TSpec>
inline bool
isGreater(Lexical<TSpec> const & _lex,
TagPrefixGreater)
{
return (_lex.data_compare & (Lexical<TSpec>::GREATER | Lexical<TSpec>::LEFT_IS_PREFIX)) != 0;
}
template <typename TSpec>
inline bool
isGreater(Lexical<TSpec> const & _lex)
{
return isGreater(_lex, typename DefaultPrefixOrder< Lexical<TSpec> >::Type());
}
//////////////////////////////////////////////////////////////////////////////
// isGreaterOrEqual
//////////////////////////////////////////////////////////////////////////////
/*!
* @fn Lexical#isGreaterOrEqual
* @headerfile <seqan/sequence.h>
* @brief Operator ">=".
*
* @signature bool isGreaterOrEqual(left, right);
* @signature bool isGreaterOrEqual(comparator);
*
* @param[in] left The first parameter.
* @param[in] right The second parameter that is compared to <tt>left</tt>.
* @param[in] comparator A comparator. Types: Lexical
*
* @return bool <tt>true</tt> if <tt>left</tt> is greater than or equal to <tt>right</tt>, <tt>false</tt> otherwise.
*/
template <typename TLeft, typename TRight, typename TPrefixOrder >
inline bool
isGreaterOrEqual(TLeft const & left,
TRight const & right,
Tag<TPrefixOrder> const tag)
{
typename Comparator<TLeft>::Type _lex(left, right);
return isGreaterOrEqual(_lex, tag);
}
template <typename TLeft, typename TRight>
inline bool
isGreaterOrEqual(TLeft const & left,
TRight const & right)
{
return left >= right;
}
template <typename TSpec>
inline bool
isGreaterOrEqual(Lexical<TSpec> const & _lex,
TagPrefixLess)
{
return (_lex.data_compare & (Lexical<TSpec>::GREATER | Lexical<TSpec>::EQUAL | Lexical<TSpec>::RIGHT_IS_PREFIX)) != 0;
}
template <typename TSpec>
inline bool
isGreaterOrEqual(Lexical<TSpec> const & _lex,
TagPrefixGreater)
{
return (_lex.data_compare & (Lexical<TSpec>::GREATER | Lexical<TSpec>::EQUAL | Lexical<TSpec>::LEFT_IS_PREFIX)) != 0;
}
template <typename TSpec>
inline bool
isGreaterOrEqual(Lexical<TSpec> const & _lex)
{
return isGreaterOrEqual(_lex, typename DefaultPrefixOrder< Lexical<TSpec> >::Type());
}
//////////////////////////////////////////////////////////////////////////////
// isPrefix
//////////////////////////////////////////////////////////////////////////////
/*!
* @fn Lexical#isPrefix
* @headerfile <seqan/sequence.h>
* @brief Test whether a sequence is the prefix of another sequence.
*
* @signature bool isPrefix(left, right);
* @signature bool isPrefix(comparator);
*
* @param[in] left The putative prefix.
* @param[in] right The second sequence.
* @param[in] comparator A comparator. Types: Lexical
*
* @return bool <tt>true</tt> if <tt>left</tt> is a prefix of<tt>right</tt>, <tt>false</tt> otherwise.
*
* By definition, a sequence is a prefix of itself: <tt>isPrefix("abc", "abc")</tt> is <tt>true</tt>.
*/
template <typename TLeft, typename TRight >
inline bool
isPrefix(TLeft const & left,
TRight const & right)
{
typename Comparator<TLeft>::Type _lex(left, right);
return isPrefix(_lex);
}
template <typename TSpec>
inline bool
isPrefix(Lexical<TSpec> const & _lex)
{
return (_lex.data_compare & (Lexical<TSpec>::LEFT_IS_PREFIX | Lexical<TSpec>::EQUAL)) != 0;
}
//////////////////////////////////////////////////////////////////////////////
// hasPrefix
//////////////////////////////////////////////////////////////////////////////
/*!
* @fn Lexical#hasPrefix
* @headerfile <seqan/sequence.h>
* @brief Test whether a sequence is the prefix of another sequence.
*
* @signature bool isPrefix(left, right);
* @signature bool isPrefix(comparator);
*
* @param[in] left The first sequence.
* @param[in] right The putative prefix.
* @param[in] comparator A comparator. Types: Lexical
*
* @return bool <tt>true</tt> if <tt>left</tt> is a prefix of<tt>right</tt>, <tt>false</tt> otherwise.
*
* By definition, a sequence is a prefix of itself: <tt>hasPrefix("abc", "abc")</tt> is <tt>true</tt>.
*/
template <typename TLeft, typename TRight >
inline bool
hasPrefix(TLeft const & left,
TRight const & right)
{
typename Comparator<TLeft>::Type _lex(left, right);
return hasPrefix(_lex);
}
template <typename TSpec>
inline bool
hasPrefix(Lexical<TSpec> const & _lex)
{
return (_lex.data_compare & (Lexical<TSpec>::RIGHT_IS_PREFIX | Lexical<TSpec>::EQUAL)) != 0;
}
//////////////////////////////////////////////////////////////////////////////
// lcpLength
//////////////////////////////////////////////////////////////////////////////
/*!
* @fn Lexical#lcpLength
* @headerfile <seqan/sequence.h>
* @brief Length of the longest common prefix.
*
* @signature TSize lcpLength(left, right);
* @signature TSize lcpLength(comparator);
*
* @param[in] left The first sequence.
* @param[in] right The second sequence.
* @param[in] comparator A comparator. Types: Lexical
*
* @return TSize The length of the longest common prefix of <tt>left</tt> and <tt>right</tt>. TSize is the Size type of
* the left size type.
*
* By definition, a sequence is a prefix of itself: <tt>hasPrefix("abc", "abc")</tt> is <tt>true</tt>.
*/
template <typename TLeft, typename TRight >
inline typename Size<TLeft>::Type
lcpLength(TLeft const & left, TRight const & right)
{
typename Comparator<TLeft>::Type _lex(left, right);
return lcpLength(_lex);
}
template <typename TSpec>
inline typename Size< Lexical<TSpec> >::Type
lcpLength(Lexical<TSpec> const & _lex)
{
return _lex.data_lcp;
}
} //namespace seqan
#endif //#ifndef SEQAN_HEADER_...