|
@@ -52,14 +52,15 @@ Element function list_append(a : Element, b : Element):
|
|
|
|
|
|
Element function set_add(a : Element, b : Element):
|
|
|
if (bool_not(set_in(a, b))):
|
|
|
- create_edge(a, b)
|
|
|
+ dict_add(a, b, a)
|
|
|
return a!
|
|
|
|
|
|
Element function set_pop(a : Element):
|
|
|
if (integer_gt(set_len(a), 0)):
|
|
|
Element edge
|
|
|
+ Element result
|
|
|
edge = read_out(a, 0)
|
|
|
- edge = read_edge_dst(edge)
|
|
|
+ result = read_edge_dst(read_out(edge, 0))
|
|
|
delete_element(edge)
|
|
|
return edge!
|
|
|
else:
|
|
@@ -67,7 +68,7 @@ Element function set_pop(a : Element):
|
|
|
|
|
|
Element function set_read(a : Element):
|
|
|
if (integer_gt(set_len(a), 0)):
|
|
|
- return read_edge_dst(read_out(a, 0))!
|
|
|
+ return read_edge_dst(read_out(read_out(a, 0), 0))!
|
|
|
else:
|
|
|
return read_root()!
|
|
|
|
|
@@ -178,30 +179,16 @@ Element function list_pop(lst : Element, index : Integer):
|
|
|
return v!
|
|
|
|
|
|
Element function set_copy(a : Element):
|
|
|
- Element b
|
|
|
- Integer i
|
|
|
- Integer count
|
|
|
-
|
|
|
- b = set_create()
|
|
|
- i = 0
|
|
|
- count = read_nr_out(a)
|
|
|
-
|
|
|
- while (i < count):
|
|
|
- set_add(b, read_edge_dst(read_out(a, i)))
|
|
|
- i = i + 1
|
|
|
-
|
|
|
- return b!
|
|
|
+ return read_dict_keys(a)!
|
|
|
|
|
|
String function set_to_string(s : Element):
|
|
|
String result
|
|
|
Integer i
|
|
|
|
|
|
result = "{"
|
|
|
- i = 0
|
|
|
+ s = set_copy(s)
|
|
|
while (i < read_nr_out(s)):
|
|
|
- result = result + cast_v2s(read_edge_dst(read_out(s, i)))
|
|
|
- result = result + ", "
|
|
|
- i = i + 1
|
|
|
+ result = (result + cast_v2s(set_pop(s))) + ", "
|
|
|
|
|
|
result = result + "}"
|
|
|
|
|
@@ -253,7 +240,6 @@ String function dict_to_string(d : Element):
|
|
|
|
|
|
Element function set_overlap(sa : Element, sb : Element):
|
|
|
Element result
|
|
|
- Integer i
|
|
|
|
|
|
if (read_nr_out(sa) > read_nr_out(sb)):
|
|
|
// Pick the smallest set to iterate over, so switch if sa is not the smallest
|
|
@@ -262,13 +248,14 @@ Element function set_overlap(sa : Element, sb : Element):
|
|
|
sb = result
|
|
|
|
|
|
result = set_create()
|
|
|
- i = 0
|
|
|
+ sa = set_copy(sa)
|
|
|
|
|
|
// Iterate over each element of sa and only add it to the result if it is also in sb
|
|
|
while (i < read_nr_out(sa)):
|
|
|
- if (set_in(sb, read_edge_dst(read_out(sa, i)))):
|
|
|
+ elem = set_pop(sa)
|
|
|
+ if (set_in(sb, elem)):
|
|
|
// Shared between both
|
|
|
- set_add(result, read_edge_dst(read_out(sa, i)))
|
|
|
+ set_add(result, elem)
|
|
|
i = i + 1
|
|
|
|
|
|
return result!
|
|
@@ -277,16 +264,10 @@ Boolean function set_equality(sa : Element, sb : Element):
|
|
|
if (read_nr_out(sa) != read_nr_out(sb)):
|
|
|
return False!
|
|
|
|
|
|
- Integer i
|
|
|
- i = 0
|
|
|
- while (i < read_nr_out(sa)):
|
|
|
- if (set_in(sb, read_edge_dst(read_out(sa, i)))):
|
|
|
- // Shared between both, so all is fine
|
|
|
- i = i + 1
|
|
|
- else:
|
|
|
- // Not shared
|
|
|
+ sa = set_copy(sa)
|
|
|
+ while (0 < set_len(sa)):
|
|
|
+ if (bool_not(set_in(sb, set_pop(sa)))):
|
|
|
return False!
|
|
|
-
|
|
|
return True!
|
|
|
|
|
|
Boolean function dict_eq(da : Element, db : Element):
|
|
@@ -361,3 +342,15 @@ Element function make_reverse_dictionary(dict : Element):
|
|
|
dict_add(reverse, value, key)
|
|
|
|
|
|
return reverse!
|
|
|
+
|
|
|
+Element function set_remove(a: Element, b: Element):
|
|
|
+ return dict_delete(a, b)!
|
|
|
+
|
|
|
+Element function set_remove_node(a: Element, b: Element):
|
|
|
+ return dict_delete_node(a, b)!
|
|
|
+
|
|
|
+Boolean function set_in(a: Element, b: Element):
|
|
|
+ return dict_in(a, b)!
|
|
|
+
|
|
|
+Element function set_in_node(a: Element, b: Element):
|
|
|
+ return dict_in_node(a, b)!
|