-
Notifications
You must be signed in to change notification settings - Fork 5
/
coxtypes.cpp
237 lines (165 loc) · 4.84 KB
/
coxtypes.cpp
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
/*
This is coxtypes.cpp
Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux
See file main.cpp for full copyright notice
*/
#include "coxtypes.h"
/****************************************************************************
Chapter I -- The CoxWord class.
This section defines the functions in the CoxWord class that are not
inlined :
- the constructor CoxWord(n);
- the destructor ~CoxWord();
- append(a) : appends the letter a to the end of g;
- append(h) : appends the word h to the end of g;
- erase(j) : erases the j-th letter from g;
- insert(j,a) : inserts the letter a in the j-th place in g;
- reset() : resets g to the identity element;
- setSubWord(h,first,r) : sets a subword in g;
****************************************************************************/
namespace coxtypes {
CoxWord::CoxWord(const Ulong& n):d_list(n+1)
{
d_list.setSize(1);
}
CoxWord::~CoxWord()
{}
CoxWord& CoxWord::append(const CoxLetter& a)
/*
Appends a to the end of g, resizing as necessary. Recall that for now
our CoxWords are always zero-terminated strings!
*/
{
d_list[d_list.size()-1] = a;
d_list.append('\0');
return *this;
}
CoxWord& CoxWord::append(const CoxWord& h)
/*
Appends h to the end of g.
NOTE : care should be exercised in applying this function, that l(gh) =
l(g) + l(h) in W; otherwise we would violate the basic principle that
only reduced words enter the program. Use prod otherwise.
*/
{
d_list.setData(h.d_list.ptr(),d_list.size()-1,h.d_list.size());
return *this;
}
CoxWord& CoxWord::erase(const Length& j)
/*
Erases the j-th letter from g.
NOTE : care should be exercised in applying this function, that the result
be reduced; otherwise we would violate the basic principle that only
reduced words enter the program.
*/
{
d_list.setData(d_list.ptr()+j+1,j,d_list.size()-1-j);
d_list.setSize(d_list.size()-1);
return *this;
}
CoxWord& CoxWord::insert(const Length& j, const CoxLetter& a)
/*
Inserts a at the j-th place in g.
NOTE : care should be exercised in applying this function, that the result
be reduced; otherwise we would violate the basic principle that only
reduced words enter the program.
*/
{
d_list.setSize(d_list.size()+1);
d_list.setData(d_list.ptr()+j,j+1,d_list.size()-1-j);
d_list[j] = a;
return *this;
}
CoxWord& CoxWord::reset()
/*
Sets g to the identity.
*/
{
d_list.setSize(1);
d_list[0] = '\0';
return *this;
}
CoxWord& CoxWord::setSubWord(const CoxWord& h, const Length& first,
const Length& r)
{
d_list.setData(h.d_list.ptr(),first,r);
return *this;
}
};
/*****************************************************************************
Chapter II -- Comparison operators
This section defines the comparison operators for CoxWords. We do word
comparisons textually because this is so much cheaper. If comparisons
as group elements are required, normalize first.
- operator== (g,h) : tells if g and h are equal as words;
- operator< (g,h) : tells if g<h lexicographically as words;
******************************************************************************/
namespace coxtypes {
bool operator== (const CoxWord& g, const CoxWord& h)
/*
Tells if g and h are equal as words.
*/
{
if (g.length() != h.length())
return false;
for (Ulong j = 0; j < g.length(); ++j) {
if (g[j] != h[j])
return false;
}
return true;
}
bool operator< (const CoxWord& g, const CoxWord& h)
/*
Tells if g < h length-lexicographically
*/
{
if (g.length() < h.length())
return true;
if (g.length() > h.length())
return false;
for (Ulong j = 0; j < g.length(); ++j) {
if (g[j] < h[j])
return true;
if (g[j] > h[j])
return false;
}
/* if we get to this point, words are equal */
return false;
}
};
/****************************************************************************
Chapter III -- Input/Output.
This section provides some input/output functions for the basic types
defined in this module. The following functions are provided :
- append(str,x) : appends a CoxNbr to the string;
- print(file,a,l) : prints the array a in rank l on the file;
****************************************************************************/
namespace coxtypes {
String& append(String& str, const CoxNbr& x)
/*
Appends x to str in numeral form; uses buf to write out the value.
*/
{
static String buf(digits(COXNBR_MAX,10)+1);
buf.setLength(sprintf(buf.ptr(),"%lu",static_cast<Ulong>(x)));
append(str,buf);
return str;
}
void print(FILE *outputfile, CoxArr a, Rank l)
/*
Prints a in array form on the outputfile..
*/
{
fprintf(outputfile,"[");
for (Ulong j = 0; j < l; ++j)
{
fprintf(outputfile,"%d",a[j]);
if (j+1 < l) /* there is more to come */
{
fprintf(outputfile,",");
}
}
fprintf(outputfile,"]");
return;
}
};