Skip to content

Commit 03f76b9

Browse files
authored
Updated libraries
1 parent 4d67d7c commit 03f76b9

File tree

3 files changed

+360
-4
lines changed

3 files changed

+360
-4
lines changed

libraries/SortedOrderedSet.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void SymmetricExceptWith(IEnumerable<T> col)
133133
{ if (col.Contains(x)) { }
134134
else
135135
{ rset.Add(x);
136-
rseq.Add(x);
136+
rseq.add(x);
137137
}
138138
}
139139

@@ -142,7 +142,7 @@ public void SymmetricExceptWith(IEnumerable<T> col)
142142
else
143143
{
144144
rset.Add(x);
145-
rseq.Add(x);
145+
rseq.add(x);
146146
}
147147
}
148148

@@ -157,7 +157,7 @@ public void UnionWith(IEnumerable<T> col)
157157
bool added = elementSet.Add(obj);
158158
if (added)
159159
{
160-
elementSeq.Add((T)obj);
160+
elementSeq.add((T)obj);
161161
}
162162
}
163163
}
@@ -171,7 +171,7 @@ public bool addAll(ICollection<T> col)
171171
if (added)
172172
{
173173
changed = true;
174-
elementSeq.Add((T)obj);
174+
elementSeq.add((T)obj);
175175
}
176176
}
177177
return changed;
@@ -340,3 +340,4 @@ public bool equals(Object col)
340340
public bool SetEquals(IEnumerable<T> col)
341341
{ return elementSet.SetEquals(col); }
342342
}
343+

libraries/UmlRsdsOcl.hpp

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
template<class S, class T, class R>
2+
class UmlRsdsOcl {
3+
public:
4+
5+
static T iterate(vector<S>* _s, T initialValue, std::function<T(S,T)> _f)
6+
{ T acc = initialValue;
7+
for (auto _pos = _s->begin(); _pos != _s->end(); ++_pos)
8+
{ S _x = *_pos;
9+
acc = _f(_x,acc);
10+
}
11+
return acc;
12+
}
13+
14+
static map<S,T>* includingMap(map<S,T>* m, S src, T trg)
15+
{ map<S,T>* copy = new map<S,T>();
16+
auto iter = m->begin();
17+
for ( ; iter != m->end(); ++iter)
18+
{ S key = iter->first;
19+
(*copy)[key] = iter->second;
20+
}
21+
(*copy)[src] = trg;
22+
return copy;
23+
}
24+
25+
26+
static map<S,T>* unionMap(map<S,T>* m1, map<S,T>* m2)
27+
{ map<S,T>* res = new map<S,T>();
28+
auto iter = m1->begin();
29+
for ( ; iter != m1->end(); ++iter)
30+
{ S key = iter->first;
31+
if (m2->count(key) == 0)
32+
{ (*res)[key] = iter->second; }
33+
}
34+
for (iter = m2->begin(); iter != m2->end(); ++iter)
35+
{ S key = iter->first;
36+
(*res)[key] = iter->second;
37+
}
38+
return res;
39+
}
40+
41+
42+
static bool includesAllMap(map<S,T>* sup, map<S,T>* sub)
43+
{ auto iter = sub->begin();
44+
for ( ; iter != sub->end(); ++iter)
45+
{ S key = iter->first;
46+
auto f = sup->find(key);
47+
if (f != sup->end())
48+
{ if (iter->second == f->second) {}
49+
else
50+
{ return false; }
51+
}
52+
else
53+
{ return false; }
54+
}
55+
return true;
56+
}
57+
58+
59+
static bool excludesAllMap(map<S,T>* sup, map<S,T>* sub)
60+
{ auto iter = sub->begin();
61+
for ( ; iter != sub->end(); ++iter)
62+
{ S key = iter->first;
63+
auto f = sup->find(key);
64+
if (f != sup->end())
65+
{ if (iter->second == f->second)
66+
{ return false; }
67+
}
68+
}
69+
return true;
70+
}
71+
72+
73+
static map<S,T>* excludeAllMap(map<S,T>* m1, map<S,T>* m2)
74+
{ map<S,T>* res = new map<S,T>();
75+
auto iter = m1->begin();
76+
for ( ; iter != m1->end(); ++iter)
77+
{ S key = iter->first;
78+
auto f = m2->find(key);
79+
if (f != m2->end())
80+
{ if (iter->second == f->second) { }
81+
else
82+
{ (*res)[key] = iter->second; }
83+
}
84+
else
85+
{ (*res)[key] = iter->second; }
86+
}
87+
return res;
88+
}
89+
90+
91+
static map<S,T>* excludingMapKey(map<S,T>* m, string k)
92+
{ // m - { k |-> m(k) }
93+
map<S,T>* res = new map<S,T>();
94+
auto iter = m->begin();
95+
for ( ; iter != m->end(); ++iter)
96+
{ S key = iter->first;
97+
if (key == k) {}
98+
else
99+
{ (*res)[key] = iter->second; }
100+
}
101+
return res;
102+
}
103+
104+
105+
static map<S,T>* excludingMapValue(map<S,T>* m, T v)
106+
{ // m - { k |-> v }
107+
map<S,T>* res = new map<S,T>();
108+
auto iter = m->begin();
109+
for ( ; iter != m->end(); ++iter)
110+
{ S key = iter->first;
111+
if (iter->second == v) {}
112+
else
113+
{ (*res)[key] = iter->second; }
114+
}
115+
return res;
116+
}
117+
118+
119+
120+
121+
static map<S,T>* intersectionMap(map<S,T>* m1, map<S,T>* m2)
122+
{ map<S,T>* res = new map<S,T>();
123+
auto iter = m1->begin();
124+
for ( ; iter != m1->end(); ++iter)
125+
{ S key = iter->first;
126+
if (m2->count(key) > 0)
127+
{ if (m2->at(key) == iter->second)
128+
{ (*res)[key] = iter->second; }
129+
}
130+
}
131+
return res;
132+
}
133+
134+
static std::set<S>* keys(map<S,T>* s)
135+
{ auto iter = s->begin();
136+
std::set<S>* res = new std::set<S>();
137+
138+
for ( ; iter != s->end(); ++iter)
139+
{ S key = iter->first;
140+
res->insert(key);
141+
}
142+
return res;
143+
}
144+
145+
146+
static vector<T>* values(map<S,T>* s)
147+
{ auto iter = s->begin();
148+
vector<T>* res = new vector<T>();
149+
150+
for ( ; iter != s->end(); ++iter)
151+
{ T value = iter->second;
152+
res->push_back(value);
153+
}
154+
return res;
155+
}
156+
157+
158+
static map<S,T>* restrict(map<S,T>* m1, std::set<S>* ks)
159+
{ map<S,T>* res = new map<S,T>();
160+
auto iter = m1->begin();
161+
for ( ; iter != m1->end(); ++iter)
162+
{ S key = iter->first;
163+
if (ks->find(key) != ks->end())
164+
{ (*res)[key] = iter->second; }
165+
}
166+
return res;
167+
}
168+
169+
static map<S,T>* antirestrict(map<S,T>* m1, std::set<S>* ks)
170+
{ map<S,T>* res = new map<S,T>();
171+
auto iter = m1->begin();
172+
for ( ; iter != m1->end(); ++iter)
173+
{ S key = iter->first;
174+
if (ks->find(key) == ks->end())
175+
{ (*res)[key] = iter->second; }
176+
}
177+
return res;
178+
}
179+
180+
static map<S,T>* selectMap(map<S,T>* m1, std::function<bool(T)> f)
181+
{ map<S,T>* res = new map<S,T>();
182+
auto iter = m1->begin();
183+
for ( ; iter != m1->end(); ++iter)
184+
{ S key = iter->first;
185+
T val = iter->second;
186+
if (f(val))
187+
{ (*res)[key] = val; }
188+
}
189+
return res;
190+
}
191+
192+
static map<S,T>* rejectMap(map<S,T>* m1, std::function<bool(T)> f)
193+
{ map<S,T>* res = new map<S,T>();
194+
auto iter = m1->begin();
195+
for ( ; iter != m1->end(); ++iter)
196+
{ S key = iter->first;
197+
T val = iter->second;
198+
if (f(val)) { }
199+
else
200+
{ (*res)[key] = val; }
201+
}
202+
return res;
203+
}
204+
205+
static map<S,R>* collectMap(map<S,T>* m1,
206+
std::function<R(T)> f)
207+
{ map<S,R>* res = new map<S,R>();
208+
auto iter = m1->begin();
209+
for ( ; iter != m1->end(); ++iter)
210+
{ S key = iter->first;
211+
T val = iter->second;
212+
213+
(*res)[key] = f(val);
214+
}
215+
return res;
216+
}
217+
218+
219+
};
220+
221+

libraries/ocliteratoroptimised.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
2+
import ocl
3+
import math
4+
import re
5+
import copy
6+
7+
from oclfile import *
8+
from enum import Enum
9+
10+
# This is an optimised read-only iterator using tuples
11+
12+
class OclIterator :
13+
14+
def __init__(self):
15+
self.position = 0
16+
self.markedPosition = 0
17+
self.elements = tuple()
18+
19+
def getElements(self) :
20+
return self.elements
21+
22+
def getPosition(self) :
23+
return self.position
24+
25+
def hasNext(self) :
26+
result = False
27+
if self.position >= 0 and self.position < len(self.elements) :
28+
result = True
29+
else :
30+
result = False
31+
return result
32+
33+
def isAfterLast(self) :
34+
result = False
35+
if self.position > len(self.elements) :
36+
return True
37+
return result
38+
39+
def isBeforeFirst(self) :
40+
result = False
41+
if self.position <= 0 :
42+
return True
43+
return result
44+
45+
def hasPrevious(self) :
46+
result = False
47+
if self.position > 1 and self.position <= len(self.elements) + 1 :
48+
result = True
49+
else :
50+
result = False
51+
return result
52+
53+
def nextIndex(self) :
54+
result = 0
55+
result = self.position + 1
56+
return result
57+
58+
def previousIndex(self) :
59+
result = 0
60+
result = self.position - 1
61+
return result
62+
63+
def moveForward(self) :
64+
self.position = self.position + 1
65+
66+
def moveBackward(self) :
67+
self.position = self.position - 1
68+
69+
def moveTo(self, i) :
70+
self.position = i
71+
72+
def setPosition(self, i) :
73+
self.position = i
74+
75+
def markPosition(self) :
76+
self.markedPosition = self.position
77+
78+
def movePosition(self, i) :
79+
self.position = i + self.position
80+
81+
def moveToFirst(self) :
82+
self.position = 1
83+
84+
def moveToLast(self) :
85+
self.position = len(self.elements)
86+
87+
def moveToStart(self) :
88+
self.position = 0
89+
90+
def moveToEnd(self) :
91+
self.position = len(self.elements) + 1
92+
93+
def moveToMarkedPosition(self) :
94+
self.position = self.markedPosition
95+
96+
def close(self) :
97+
self.position = 0
98+
self.markedPosition = 0
99+
self.elements = tuple()
100+
101+
def newOclIterator_Sequence(sq) :
102+
ot = OclIterator()
103+
ot.elements = tuple(sq)
104+
ot.position = 0
105+
return ot
106+
107+
def getCurrent(self) :
108+
result = None
109+
if self.position <= len(self.elements) and self.position >= 1 :
110+
result = (self.elements)[self.position - 1]
111+
return result
112+
113+
def next(self) :
114+
result = None
115+
self.moveForward()
116+
return self.getCurrent()
117+
118+
def previous(self) :
119+
result = None
120+
self.moveBackward()
121+
return self.getCurrent()
122+
123+
def length(self) :
124+
return len(self.elements)
125+
126+
def at(self,i) :
127+
return self.elements[i-1]
128+
129+
130+
131+
132+
133+
134+

0 commit comments

Comments
 (0)