-
Notifications
You must be signed in to change notification settings - Fork 20
/
colibricore_patternset.pxi
47 lines (39 loc) · 1.25 KB
/
colibricore_patternset.pxi
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
def __bool__(self):
return self.data.size() > 0
def __len__(self):
"""Return the total number of patterns in the dictionary"""
return self.data.size()
cpdef has(self, Pattern pattern):
if not isinstance(pattern, Pattern):
raise ValueError("Expected instance of Pattern")
return self.data.has(pattern.cpattern)
def __contains__(self, pattern):
"""Test if the pattern is in the dictionary
:param pattern: A pattern
:type pattern: Pattern
:rtype: bool
"""
if not isinstance(pattern, Pattern):
raise ValueError("Expected instance of Pattern")
return self.has(pattern)
def __iter__(self):
"""Iterate over all patterns in the dictionary"""
it = self.data.begin()
cdef cPattern cpattern
it_end = self.data.end()
while it != it_end:
cpattern = deref(it)
pattern = Pattern()
pattern.bind(cpattern)
yield pattern
inc(it)
def add(self, Pattern pattern):
"""Adds a pattern to the set
:param pattern: The pattern to add
:type pattern: Pattern
"""
if not isinstance(pattern, Pattern):
raise ValueError("Expected instance of Pattern")
self.data.insert(pattern.cpattern)
#cdef getdatapointer(self):
# return address(self.data)