Macaulay2 Engine
Loading...
Searching...
No Matches
Word.hpp
Go to the documentation of this file.
1#ifndef _word_hpp_
2#define _word_hpp_
3
38
39#include <iosfwd> // for ostream
40#include <vector> // for vector, vector<>::value_type
41
55class Word
56{
57public:
58 // warning: the pointers begin, end, should not go out of scope while this Word is in use.
59 Word() : mBegin(nullptr), mEnd(nullptr), mSize(0) {}
60
61 Word(const int* begin, const int* end) : mBegin(begin), mEnd(end), mSize(end-begin) {}
62
63 // keyword 'explicit' to prevent calling this constructor implicitly. It
64 // causes some strange behavior in debugging.
65 // to be honest, we should only be using this in the unit-tests file ONLY
66 explicit Word(const std::vector<int>& val) : mBegin(val.data()), mEnd(val.data() + val.size()), mSize(val.size()) {}
67
68 void init(const int* begin, const int* end) { mBegin = begin; mEnd = end; mSize = end-begin; }
69 // this constructor is a bit dangerous since we have several std::vector<int> types running around
70 //void init(const std::vector<int>& val) { mBegin = val.data(); mEnd = val.data() + val.size(); }
71
72 const int* begin() const { return mBegin; }
73 const int* end() const { return mEnd; }
74 int size() const { return mSize; }
75
76 bool operator==(Word rhs) const
77 {
78 if (mSize != rhs.mSize) return false;
79 for (auto i=0; i<mSize; ++i)
80 if (mBegin[i] != rhs.mBegin[i])
81 return false;
82 return true;
83 }
84
85 int operator[](int i) const { return *(mBegin + i); }
86
87private:
88 // Caution. We DO NOT own these pointers.
89 // It is the responsibility of the calling code to not let these pointers expire.
90 const int* mBegin;
91 const int* mEnd;
92 int mSize;
93};
94
95std::ostream& operator<<(std::ostream& o, const Word& w);
96
110// this class is intended for use in the word table, taking ecart degree (i.e.
111// the power of an 'invisible' homogenizing variable) into consideration when
112// checking divisibility.
113// Other data included is the heft degree of the monomial as entered, so that
114// a word table may sort.
116{
117public:
118 // warning: the pointers begin, end, should not go out of scope while this Word is in use.
120
121 WordWithData(const int* begin, const int* end, int ecartDegree, int heftDegree) :
124 {
125 mWord.init(begin,end);
126 }
127
128 // keyword 'explicit' to prevent calling this constructor implicitly. It
129 // causes some strange behavior in debugging.
130 // to be honest, we should only be using this in the unit-tests file ONLY
131 //explicit WordWithData(const std::vector<int>& val) : mBegin(val.data()), mEnd(val.data() + val.size()) {}
132
133 void init(const int* begin, const int* end, int ecartDegree, int heftDegree)
134 {
135 mWord.init(begin,end);
138 }
139
140 const int* begin() const { return word().begin(); }
141 const int* end() const { return word().end(); }
142
143 Word word() const { return mWord; }
144
145 int ecartDegree() const { return mEcartDegree; }
146 int heftDegree() const { return mHeftDegree; }
147
148 size_t size() const { return word().size(); }
149
151 {
152 // Warning: == ignores heft degree, but not ecart degree
153 if (ecartDegree() != rhs.ecartDegree()) return false;
154 return word() == rhs.word();
155 }
156
157private:
158 // Caution. We DO NOT own the pointers that are in mWord
159 // It is the responsibility of the calling code to not let these pointers expire.
161
164};
165
166std::ostream& operator<<(std::ostream& o, const WordWithData& w);
167
168#endif
169
170// Local Variables:
171// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
172// indent-tabs-mode: nil
173// End:
std::ostream & operator<<(std::ostream &o, const Word &w)
Definition Word.cpp:4
Word(const int *begin, const int *end)
Definition Word.hpp:61
bool operator==(Word rhs) const
Definition Word.hpp:76
Word()
Definition Word.hpp:59
const int * begin() const
Definition Word.hpp:72
void init(const int *begin, const int *end)
Definition Word.hpp:68
int mSize
Definition Word.hpp:92
const int * mEnd
Definition Word.hpp:91
const int * end() const
Definition Word.hpp:73
int size() const
Definition Word.hpp:74
Word(const std::vector< int > &val)
Definition Word.hpp:66
const int * mBegin
Definition Word.hpp:90
int operator[](int i) const
Definition Word.hpp:85
Non-owning view of a non-commutative word: [begin, end) of int variable indices.
Definition Word.hpp:56
const int * end() const
Definition Word.hpp:141
WordWithData(const int *begin, const int *end, int ecartDegree, int heftDegree)
Definition Word.hpp:121
int heftDegree() const
Definition Word.hpp:146
void init(const int *begin, const int *end, int ecartDegree, int heftDegree)
Definition Word.hpp:133
int mHeftDegree
Definition Word.hpp:163
Word word() const
Definition Word.hpp:143
Word mWord
Definition Word.hpp:160
size_t size() const
Definition Word.hpp:148
bool operator==(WordWithData rhs)
Definition Word.hpp:150
const int * begin() const
Definition Word.hpp:140
int ecartDegree() const
Definition Word.hpp:145
int mEcartDegree
Definition Word.hpp:162
Word plus its ecart degree and heft degree — the value type WordWithDataTable stores.
Definition Word.hpp:116