Comment on the set_swap_bodies() helper function.

This commit is contained in:
Raymond Hettinger 2005-07-31 01:33:10 +00:00
parent 9f1a6796eb
commit 934d63eb40
1 changed files with 13 additions and 0 deletions

View File

@ -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)
{