Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ExactEqual.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 true;
58 else
59 return false;
60}
61
62template < class SymbolType >
64 size_t n = u.getContent ( ).size ( );
65 size_t i = 0;
66 size_t j = 0;
67
68 if ( n != v.getContent ( ).size ( ) )
69 return false;
70
71 while ( i < n && j < n ) {
72 size_t k = 0;
73
74 while ( k < n && u.getContent ( )[( i + k ) % n] == v.getContent ( )[( j + k ) % n] ) k++;
75
76 if ( k >= n ) return true;
77
78 if ( u.getContent ( )[( i + k ) % n] > v.getContent ( )[( j + k ) % n] )
79 i += k + 1;
80 else
81 j += k + 1;
82 }
83
84 return false;
85}
86
87} /* namespace naive */
88
89} /* namespace string */
90
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: ExactEqual.h:19
static bool equals(const string::LinearString< SymbolType > &u, const string::LinearString< SymbolType > &v)
Definition: ExactEqual.h:49
int i
Definition: AllEpsilonClosure.h:118
Definition: RandomStringFactory.cpp:12