Macaulay2 Engine
Loading...
Searching...
No Matches
OverlapTable.cpp
Go to the documentation of this file.
2#include "interface/m2-types.h" // for M2_gbTrace
3#include <iostream> // for cout
4
5// will call find to see if degree exists, and if not will call
6// insert. If degree exists, append overlap to value of degree
7auto OverlapTable::insert(int deg, bool isGenerator, Overlap o) -> void
8{
9 if (M2_gbTrace >= 3)
10 {
11 std::cout << "overlapTable: inserting deg="
12 << deg
13 << " isGenerator=" << isGenerator
14 << " overlap=" << o
15 << std::endl;
16 }
17 std::deque<Overlap> emptyDeque;
18 auto ret = mOverlapMap.insert(std::make_pair(std::make_pair(deg,isGenerator),
19 emptyDeque));
20 // ret is a std::pair<iterator,bool>
21 // ret.first is the iterator into mOverlapMap, which itself is a pair <key,value>
22 // the keys are std::pair<deg,bool> value is deque. So we push_back o on the deque.
23 (ret.first)->second.push_back(o);
24}
25
26// is the overlap map empty?
27auto OverlapTable::isFinished() const -> bool
28{
29 return mOverlapMap.empty();
30}
31
32// is the overlap map empty in degrees <= topDegree?
33auto OverlapTable::isFinished(int topDegree) const -> bool
34{
35 auto beginIter = mOverlapMap.begin();
36 if (beginIter == mOverlapMap.end()) return true;
37 return (beginIter->first.first > topDegree);
38}
39
40// returns the lowest degree and a pointer to the overlaps
41// in that degree if isFinished returns false. Otherwise
42// return (-1,nullptr).
43auto OverlapTable::nextDegreeOverlaps() -> std::pair<int,std::deque<Overlap>*>
44{
45 auto iter = mOverlapMap.begin();
46 if (iter == mOverlapMap.end()) return std::make_pair(-1,nullptr);
47 return std::make_pair(iter->first.first, &(iter->second));
48}
49
50auto OverlapTable::size() const -> size_t
51{
52 size_t sum = 0;
53 for (auto& i : mOverlapMap)
54 {
55 sum += i.second.size();
56 }
57 return sum;
58}
59
61{
62 auto iter = mOverlapMap.begin();
63 if (iter == mOverlapMap.end()) return;
64 mOverlapMap.erase(iter);
65}
66
67auto operator<<(std::ostream& o, Overlap& a) -> std::ostream&
68{
69 o << "[" << std::get<0>(a) << ","
70 << std::get<1>(a) << ","
71 << std::get<2>(a) << "]";
72 return o;
73}
74
75std::ostream& operator<<(std::ostream& o, const std::deque<Overlap>& val)
76{
77 int count = 0;
78 for (auto a : val)
79 {
80 o << a;
81 o << ",";
82 count++;
83 if (count % 10 == 0) o << std::endl;
84 }
85 return o;
86}
87
88auto OverlapTable::dump(std::ostream& ostr, bool outputDeques) const -> std::ostream&
89{
90 ostr << "OverlapTable with " << size() << " elements:" << std::endl;
91 for (auto i : mOverlapMap)
92 {
93 if (!outputDeques)
94 ostr << " Degree [" << i.first.first
95 << "," << i.first.second << "] # = " << i.second.size() << std::endl;
96 else
97 ostr << " Degree [" << i.first.first
98 << "," << i.first.second << "] # = " << i.second << std::endl;
99 }
100 ostr << std::endl;
101 return ostr;
102}
103
104std::ostream& operator<<(std::ostream& ostr, const OverlapTable& overlapTable)
105{
106 return overlapTable.dump(ostr,false);
107}
108
109// Local Variables:
110// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
111// indent-tabs-mode: nil
112// End:
auto operator<<(std::ostream &o, Overlap &a) -> std::ostream &
std::tuple< int, int, int, bool > Overlap
OverlapTable — degree-sorted queue of pending word overlaps for non-commutative GB drivers.
auto insert(int deg, bool isGenerator, Overlap o) -> void
auto isFinished() const -> bool
auto dump(std::ostream &ostr, bool outputDeques) const -> std::ostream &
auto removeLowestDegree() -> void
auto size() const -> size_t
auto nextDegreeOverlaps() -> std::pair< int, std::deque< Overlap > * >
OverlapMap mOverlapMap
int M2_gbTrace
Definition m2-types.cpp:52
Engine-to-interpreter type vocabulary across the C++ / .dd boundary.