Commit 3012414c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add set.update

parent 553bd949
......@@ -201,6 +201,24 @@ Box* setClear(BoxedSet* self, Box* v) {
return None;
}
Box* setUpdate(BoxedSet* self, BoxedTuple* args) {
assert(self->cls == set_cls);
assert(args->cls == tuple_cls);
for (auto l : args->elts) {
if (l->cls == set_cls) {
BoxedSet* s2 = static_cast<BoxedSet*>(l);
self->s.insert(s2->s.begin(), s2->s.end());
} else {
for (auto e : l->pyElements()) {
self->s.insert(e);
}
}
}
return None;
}
Box* setContains(BoxedSet* self, Box* v) {
assert(self->cls == set_cls || self->cls == frozenset_cls);
return boxBool(self->s.count(v) != 0);
......@@ -283,6 +301,7 @@ void setupSet() {
set_cls->giveAttr("add", new BoxedFunction(boxRTFunction((void*)setAdd, NONE, 2)));
set_cls->giveAttr("clear", new BoxedFunction(boxRTFunction((void*)setClear, NONE, 1)));
set_cls->giveAttr("update", new BoxedFunction(boxRTFunction((void*)setUpdate, NONE, 1, 0, true, false)));
set_cls->freeze();
frozenset_cls->freeze();
......
......@@ -60,6 +60,11 @@ print len(s)
s.clear()
print s
s.update((10, 15))
print sorted(s)
s.update((10, 15), range(8))
print sorted(s)
def f2():
print {5}
f2()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment