-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNthOrderStringIterator.C
63 lines (44 loc) · 1.1 KB
/
NthOrderStringIterator.C
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
/**************************************************************
NthOrderStringIterator.C
Copyright (C)2013 William H. Majoros ([email protected]).
This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
License (GPL) version 3, as described at www.opensource.org.
***************************************************************/
#include "NthOrderStringIterator.H"
#include <iostream>
NthOrderStringIterator::NthOrderStringIterator(int N,Alphabet &alphabet)
: alphabet(alphabet), N(N), alphabetSize(alphabet.getNumElements())
{
// ctor
reset();
}
BOOM::String NthOrderStringIterator::getNextString()
{
BOOM::String *s=current.toString(alphabet);
BOOM::String retval=*s;
delete s;
advance();
return retval;
}
bool NthOrderStringIterator::done()
{
return !hasMore;
}
void NthOrderStringIterator::reset()
{
Symbol z=0;
for(int i=0 ; i<N ; ++i)
current.append(z);
hasMore=true;
}
void NthOrderStringIterator::advance()
{
for(int i=N-1 ; i>=0 ; --i)
{
Symbol &s=current[i];
++s;
if(s<alphabetSize) return;
s=0;
}
hasMore=false;
}