Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ExactCompare.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <string/LinearString.h>
9#include <string/CyclicString.h>
10
11namespace string {
12
13namespace naive {
14
20public:
31 template < class SymbolType >
33
44 template < class SymbolType >
46};
47
48template < class SymbolType >
50 size_t n = u.getContent ( ).size ( );
51 size_t m = v.getContent ( ).size ( );
52 size_t k = 0;
53
54 while ( k < n && k < m && u.getContent ( )[k] == v.getContent ( )[k] ) k++;
55
56 if ( ( k == m ) && ( k == n ) )
57 return 0;
58 else if ( k == m )
59 return -1;
60 else if ( k == n )
61 return 1;
62 else if ( u.getContent ( )[k] < v.getContent ( )[k] )
63 return -1;
64 else
65 return 1;
66}
67
68template < class SymbolType >
70 size_t n = u.getContent ( ).size ( );
71 size_t m = v.getContent ( ).size ( );
72 size_t i = 0;
73 size_t j = 0;
74
75 bool last = false;
76
77 while ( i < n && j < m ) {
78 size_t k = 0;
79
80 while ( k < n && u.getContent ( )[( i + k ) % n] == v.getContent ( )[( j + k ) % m] ) k++;
81
82 if ( k >= n ) return 0;
83
84 last = u.getContent ( )[( i + k ) % n] > v.getContent ( )[( j + k ) % m];
85
86 if ( last )
87 i += k + 1;
88 else
89 j += k + 1;
90 }
91
92 return last ? 1 : -1;
93}
94
95} /* namespace naive */
96
97} /* namespace string */
98
Cyclic string.
Definition: CyclicString.h:60
const ext::vector< SymbolType > & getContent() const &
Definition: CyclicString.h:219
Linear string.
Definition: LinearString.h:57
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: ExactCompare.h:19
static int compare(const string::LinearString< SymbolType > &u, const string::LinearString< SymbolType > &v)
Definition: ExactCompare.h:49
int i
Definition: AllEpsilonClosure.h:118
Definition: RandomStringFactory.cpp:12