diff options
author | Raymond Hettinger <python@rcn.com> | 2005-07-31 01:33:10 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-07-31 01:33:10 (GMT) |
commit | 934d63eb409446836a3b5f62cfe6f0460a1a2657 (patch) | |
tree | 35d754e80eae2c4181bfc9eec59d86beed9738e0 /Objects/setobject.c | |
parent | 9f1a6796eb83a2884df5fd93487634e46d8830a7 (diff) | |
download | cpython-934d63eb409446836a3b5f62cfe6f0460a1a2657.zip cpython-934d63eb409446836a3b5f62cfe6f0460a1a2657.tar.gz cpython-934d63eb409446836a3b5f62cfe6f0460a1a2657.tar.bz2 |
Comment on the set_swap_bodies() helper function.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r-- | Objects/setobject.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index e922b6e..a279ec2 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -793,6 +793,19 @@ set_len(PyObject *so) return ((PySetObject *)so)->used; } +/* set_swap_bodies() switches the contents of any two sets by moving their + internal data pointers and, if needed, copying the internal smalltables. + Semantically equivalent to: + + t=set(a); a.clear(); a.update(b); b.clear(); b.update(t); del t + + The function always succeeds and it leaves both objects in a stable state. + Useful for creating temporary frozensets from sets for membership testing + in __contains__(), discard(), and remove(). Also useful for operations + that update in-place (by allowing an intermediate result to be swapped + into one of original the inputs). +*/ + static void set_swap_bodies(PySetObject *a, PySetObject *b) { |