-
Notifications
You must be signed in to change notification settings - Fork 1
/
set.py
59 lines (50 loc) · 1.34 KB
/
set.py
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
# can't remember if this is supposed to work yet or not
class Set(ValueComparator):
def equals(self, item, comp):
v = self.value
c_match = {}
i_match = {}
for c in v:
c_match[id(c)] = {}
for i in item:
i_match[id(i)] = {}
for c in v:
for i in item:
if comp.descend(i, c):
c_match[id(c)][id(i)] = None
i_match[id(i)][id(c)] = None
# remove ambiguity by delete all no matches and exact matches
def no_match(match):
no_match = []
for key in match:
if not key:
no_match.append(key)
return no_match
missing = no_match(c_match)
del(c_match[missing])
extra = no_match(i_match)
del(i_match[extra])
for c in c_match.keys():
cm = c_match[c]
if len(cm) == 1:
i, = cm
im = i_match[i]
if len(im) == 1:
# totally unambiguous match, remove from both sides
del(c_match[c])
del(i_match[i])
# now we need to generate sets of compatible assumptions
for (v2, m2) in v_match.keys():
for key in v:
if extra.has_key(key):
del extra[key]
else:
missing.append(key)
if extra or missing:
self.extra = extra.keys()
self.missing = missing
return False
else:
return True
def expr(self, expr):
pass