blob: 4fbb645458f21ed5c091b64f22d7c4c46eecd377 [file] [log] [blame]
Raymond Hettingera690a992003-11-16 16:17:49 +00001#include "Python.h"
2
3/* set object implementation
4 written and maintained by Raymond D. Hettinger <python@rcn.com>
5 derived from sets.py written by Greg V. Wilson, Alex Martelli,
6 Guido van Rossum, Raymond Hettinger, and Tim Peters.
7
8 Copyright (c) 2003 Python Software Foundation.
9 All rights reserved.
10*/
11
Raymond Hettingera690a992003-11-16 16:17:49 +000012static PyObject *
Raymond Hettingera38123e2003-11-24 22:18:49 +000013set_update(PySetObject *so, PyObject *other)
Raymond Hettingera690a992003-11-16 16:17:49 +000014{
Raymond Hettingera38123e2003-11-24 22:18:49 +000015 PyObject *item, *data, *it;
Raymond Hettingera690a992003-11-16 16:17:49 +000016
Raymond Hettingera38123e2003-11-24 22:18:49 +000017 if (PyAnySet_Check(other)) {
18 if (PyDict_Merge(so->data, ((PySetObject *)other)->data, 0) == -1)
19 return NULL;
20 Py_RETURN_NONE;
Raymond Hettingera690a992003-11-16 16:17:49 +000021 }
22
Raymond Hettingera38123e2003-11-24 22:18:49 +000023 it = PyObject_GetIter(other);
24 if (it == NULL)
25 return NULL;
26 data = so->data;
Raymond Hettingera690a992003-11-16 16:17:49 +000027
Raymond Hettingera38123e2003-11-24 22:18:49 +000028 while ((item = PyIter_Next(it)) != NULL) {
Raymond Hettingera690a992003-11-16 16:17:49 +000029 if (PyDict_SetItem(data, item, Py_True) == -1) {
Raymond Hettingera38123e2003-11-24 22:18:49 +000030 Py_DECREF(it);
Raymond Hettingera690a992003-11-16 16:17:49 +000031 Py_DECREF(item);
Raymond Hettingera38123e2003-11-24 22:18:49 +000032 return NULL;
Raymond Hettingera690a992003-11-16 16:17:49 +000033 }
34 Py_DECREF(item);
35 }
Raymond Hettingera38123e2003-11-24 22:18:49 +000036 Py_DECREF(it);
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +000037 if (PyErr_Occurred())
Raymond Hettingera38123e2003-11-24 22:18:49 +000038 return NULL;
39 Py_RETURN_NONE;
40}
41
42PyDoc_STRVAR(update_doc,
43"Update a set with the union of itself and another.");
44
45static PyObject *
46make_new_set(PyTypeObject *type, PyObject *iterable)
47{
48 PyObject *data = NULL;
49 PyObject *tmp;
50 PySetObject *so = NULL;
51
52 data = PyDict_New();
53 if (data == NULL)
54 return NULL;
Raymond Hettingera690a992003-11-16 16:17:49 +000055
56 /* create PySetObject structure */
57 so = (PySetObject *)type->tp_alloc(type, 0);
Raymond Hettingera38123e2003-11-24 22:18:49 +000058 if (so == NULL) {
59 Py_DECREF(data);
60 return NULL;
61 }
Raymond Hettingera690a992003-11-16 16:17:49 +000062 so->data = data;
63 so->hash = -1;
64
Raymond Hettingera38123e2003-11-24 22:18:49 +000065 if (iterable != NULL) {
66 tmp = set_update(so, iterable);
67 if (tmp == NULL) {
68 Py_DECREF(so);
69 return NULL;
70 }
71 Py_DECREF(tmp);
72 }
73
Raymond Hettingera690a992003-11-16 16:17:49 +000074 return (PyObject *)so;
75}
76
77static PyObject *
Raymond Hettinger50a4bb32003-11-17 16:42:33 +000078frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Raymond Hettingera690a992003-11-16 16:17:49 +000079{
80 PyObject *iterable = NULL;
81
82 if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable))
83 return NULL;
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +000084 if (iterable != NULL && PyFrozenSet_CheckExact(iterable)) {
Raymond Hettinger49ba4c32003-11-23 02:49:05 +000085 Py_INCREF(iterable);
86 return iterable;
87 }
Raymond Hettingera690a992003-11-16 16:17:49 +000088 return make_new_set(type, iterable);
89}
90
Raymond Hettinger50a4bb32003-11-17 16:42:33 +000091static PyObject *
92set_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
93{
Raymond Hettinger50a4bb32003-11-17 16:42:33 +000094 return make_new_set(type, NULL);
95}
96
Raymond Hettingerbfd334a2003-11-22 03:55:23 +000097static PyObject *
98frozenset_dict_wrapper(PyObject *d)
99{
100 PySetObject *w;
101
102 assert(PyDict_Check(d));
103 w = (PySetObject *)make_new_set(&PyFrozenSet_Type, NULL);
104 if (w == NULL)
105 return NULL;
106 Py_DECREF(w->data);
107 Py_INCREF(d);
108 w->data = d;
109 return (PyObject *)w;
110}
111
Raymond Hettingera690a992003-11-16 16:17:49 +0000112static void
113set_dealloc(PySetObject *so)
114{
115 PyObject_GC_UnTrack(so);
116 Py_XDECREF(so->data);
117 so->ob_type->tp_free(so);
118}
119
120static int
121set_traverse(PySetObject *so, visitproc visit, void *arg)
122{
123 if (so->data)
124 return visit(so->data, arg);
125 return 0;
126}
127
128static PyObject *
129set_iter(PySetObject *so)
130{
131 return PyObject_GetIter(so->data);
132}
133
134static int
135set_len(PySetObject *so)
136{
137 return PyDict_Size(so->data);
138}
139
140static int
141set_contains(PySetObject *so, PyObject *key)
142{
Raymond Hettingerbfd334a2003-11-22 03:55:23 +0000143 PyObject *tmp;
Raymond Hettinger19c2d772003-11-21 18:36:54 +0000144 int result;
145
Raymond Hettingerbc0f2ab2003-11-25 21:12:14 +0000146 result = PyDict_Contains(so->data, key);
Raymond Hettingera38123e2003-11-24 22:18:49 +0000147 if (result == -1 && PyAnySet_Check(key)) {
Raymond Hettinger19c2d772003-11-21 18:36:54 +0000148 PyErr_Clear();
Raymond Hettingerbfd334a2003-11-22 03:55:23 +0000149 tmp = frozenset_dict_wrapper(((PySetObject *)(key))->data);
Raymond Hettinger19c2d772003-11-21 18:36:54 +0000150 if (tmp == NULL)
151 return -1;
Raymond Hettingerbc0f2ab2003-11-25 21:12:14 +0000152 result = PyDict_Contains(so->data, tmp);
Raymond Hettinger19c2d772003-11-21 18:36:54 +0000153 Py_DECREF(tmp);
154 }
155 return result;
Raymond Hettingera690a992003-11-16 16:17:49 +0000156}
157
158static PyObject *
Raymond Hettinger8f5cdaa2003-12-13 11:26:12 +0000159set_direct_contains(PySetObject *so, PyObject *key)
160{
Raymond Hettinger8f5cdaa2003-12-13 11:26:12 +0000161 long result;
162
Raymond Hettinger438e02d2003-12-13 19:38:47 +0000163 result = set_contains(so, key);
Raymond Hettinger8f5cdaa2003-12-13 11:26:12 +0000164 if (result == -1)
165 return NULL;
166 return PyBool_FromLong(result);
167}
168
169PyDoc_STRVAR(contains_doc, "x.__contains__(y) <==> y in x.");
170
171static PyObject *
Raymond Hettingera690a992003-11-16 16:17:49 +0000172set_copy(PySetObject *so)
173{
Raymond Hettingera38123e2003-11-24 22:18:49 +0000174 return make_new_set(so->ob_type, (PyObject *)so);
Raymond Hettingera690a992003-11-16 16:17:49 +0000175}
176
Raymond Hettinger49ba4c32003-11-23 02:49:05 +0000177static PyObject *
178frozenset_copy(PySetObject *so)
179{
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +0000180 if (PyFrozenSet_CheckExact(so)) {
Raymond Hettinger49ba4c32003-11-23 02:49:05 +0000181 Py_INCREF(so);
182 return (PyObject *)so;
183 }
184 return set_copy(so);
185}
186
Raymond Hettingera690a992003-11-16 16:17:49 +0000187PyDoc_STRVAR(copy_doc, "Return a shallow copy of a set.");
188
189static PyObject *
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +0000190set_union(PySetObject *so, PyObject *other)
191{
192 PySetObject *result;
193 PyObject *rv;
194
195 result = (PySetObject *)set_copy(so);
196 if (result == NULL)
197 return NULL;
Raymond Hettingera38123e2003-11-24 22:18:49 +0000198 rv = set_update(result, other);
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +0000199 if (rv == NULL) {
200 Py_DECREF(result);
201 return NULL;
202 }
203 Py_DECREF(rv);
204 return (PyObject *)result;
205}
206
207PyDoc_STRVAR(union_doc,
208 "Return the union of two sets as a new set.\n\
209\n\
210(i.e. all elements that are in either set.)");
211
212static PyObject *
Raymond Hettingera690a992003-11-16 16:17:49 +0000213set_or(PySetObject *so, PyObject *other)
214{
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000215 if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000216 Py_INCREF(Py_NotImplemented);
217 return Py_NotImplemented;
218 }
219 return set_union(so, other);
220}
221
222static PyObject *
223set_ior(PySetObject *so, PyObject *other)
224{
225 PyObject *result;
226
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000227 if (!PyAnySet_Check(other)) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000228 Py_INCREF(Py_NotImplemented);
229 return Py_NotImplemented;
230 }
Raymond Hettingera38123e2003-11-24 22:18:49 +0000231 result = set_update(so, other);
Raymond Hettingera690a992003-11-16 16:17:49 +0000232 if (result == NULL)
233 return NULL;
234 Py_DECREF(result);
235 Py_INCREF(so);
236 return (PyObject *)so;
237}
238
239static PyObject *
240set_intersection(PySetObject *so, PyObject *other)
241{
242 PySetObject *result;
243 PyObject *item, *selfdata, *tgtdata, *it;
244
245 result = (PySetObject *)make_new_set(so->ob_type, NULL);
246 if (result == NULL)
247 return NULL;
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +0000248 tgtdata = result->data;
249 selfdata = so->data;
250
251 if (PyAnySet_Check(other) &&
252 PyDict_Size(((PySetObject *)other)->data) > PyDict_Size(selfdata)) {
253 selfdata = ((PySetObject *)other)->data;
254 other = (PyObject *)so;
255 } else if (PyDict_Check(other) &&
256 PyDict_Size(other) > PyDict_Size(selfdata)) {
257 selfdata = other;
258 other = so->data;
259 }
260
Raymond Hettingera690a992003-11-16 16:17:49 +0000261 it = PyObject_GetIter(other);
262 if (it == NULL) {
263 Py_DECREF(result);
264 return NULL;
265 }
266
Raymond Hettingera690a992003-11-16 16:17:49 +0000267 while ((item = PyIter_Next(it)) != NULL) {
Raymond Hettingerbc0f2ab2003-11-25 21:12:14 +0000268 if (PyDict_Contains(selfdata, item)) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000269 if (PyDict_SetItem(tgtdata, item, Py_True) == -1) {
270 Py_DECREF(it);
271 Py_DECREF(result);
272 Py_DECREF(item);
Raymond Hettingera690a992003-11-16 16:17:49 +0000273 return NULL;
274 }
275 }
276 Py_DECREF(item);
277 }
278 Py_DECREF(it);
279 if (PyErr_Occurred()) {
280 Py_DECREF(result);
281 return NULL;
282 }
283 return (PyObject *)result;
284}
285
286PyDoc_STRVAR(intersection_doc,
287"Return the intersection of two sets as a new set.\n\
288\n\
289(i.e. all elements that are in both sets.)");
290
291static PyObject *
292set_intersection_update(PySetObject *so, PyObject *other)
293{
294 PyObject *item, *selfdata, *it, *newdict, *tmp;
295
296 newdict = PyDict_New();
297 if (newdict == NULL)
298 return newdict;
299
300 it = PyObject_GetIter(other);
301 if (it == NULL) {
302 Py_DECREF(newdict);
303 return NULL;
304 }
305
306 selfdata = so->data;
307 while ((item = PyIter_Next(it)) != NULL) {
Raymond Hettingerbc0f2ab2003-11-25 21:12:14 +0000308 if (PyDict_Contains(selfdata, item)) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000309 if (PyDict_SetItem(newdict, item, Py_True) == -1) {
310 Py_DECREF(newdict);
311 Py_DECREF(it);
312 Py_DECREF(item);
Raymond Hettingera690a992003-11-16 16:17:49 +0000313 return NULL;
314 }
315 }
316 Py_DECREF(item);
317 }
318 Py_DECREF(it);
319 if (PyErr_Occurred()) {
320 Py_DECREF(newdict);
321 return NULL;
322 }
323 tmp = so->data;
324 so->data = newdict;
325 Py_DECREF(tmp);
326 Py_RETURN_NONE;
327}
328
329PyDoc_STRVAR(intersection_update_doc,
330"Update a set with the intersection of itself and another.");
331
332static PyObject *
333set_and(PySetObject *so, PyObject *other)
334{
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000335 if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000336 Py_INCREF(Py_NotImplemented);
337 return Py_NotImplemented;
338 }
339 return set_intersection(so, other);
340}
341
342static PyObject *
343set_iand(PySetObject *so, PyObject *other)
344{
345 PyObject *result;
346
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000347 if (!PyAnySet_Check(other)) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000348 Py_INCREF(Py_NotImplemented);
349 return Py_NotImplemented;
350 }
351 result = set_intersection_update(so, other);
352 if (result == NULL)
353 return NULL;
354 Py_DECREF(result);
355 Py_INCREF(so);
356 return (PyObject *)so;
357}
358
359static PyObject *
Raymond Hettingera690a992003-11-16 16:17:49 +0000360set_difference_update(PySetObject *so, PyObject *other)
361{
362 PyObject *item, *tgtdata, *it;
363
364 it = PyObject_GetIter(other);
365 if (it == NULL)
366 return NULL;
367
368 tgtdata = so->data;
369 while ((item = PyIter_Next(it)) != NULL) {
370 if (PyDict_DelItem(tgtdata, item) == -1) {
371 if (PyErr_ExceptionMatches(PyExc_KeyError))
372 PyErr_Clear();
373 else {
374 Py_DECREF(it);
375 Py_DECREF(item);
376 return NULL;
377 }
378 }
379 Py_DECREF(item);
380 }
381 Py_DECREF(it);
382 if (PyErr_Occurred())
383 return NULL;
384 Py_RETURN_NONE;
385}
386
387PyDoc_STRVAR(difference_update_doc,
388"Remove all elements of another set from this set.");
389
390static PyObject *
Raymond Hettingerfb4e33a2003-12-15 13:23:55 +0000391set_difference(PySetObject *so, PyObject *other)
392{
393 PyObject *result, *tmp;
394 PyObject *otherdata, *tgtdata;
395 PyObject *key, *value;
396 int pos = 0;
397
398 if (PyDict_Check(other))
399 otherdata = other;
400 else if (PyAnySet_Check(other))
401 otherdata = ((PySetObject *)other)->data;
402 else {
403 result = set_copy(so);
404 if (result == NULL)
405 return result;
406 tmp = set_difference_update((PySetObject *)result, other);
407 if (tmp != NULL) {
408 Py_DECREF(tmp);
409 return result;
410 }
411 Py_DECREF(result);
412 return NULL;
413 }
414
415 result = make_new_set(so->ob_type, NULL);
416 if (result == NULL)
417 return NULL;
418 tgtdata = ((PySetObject *)result)->data;
419
420 while (PyDict_Next(so->data, &pos, &key, &value)) {
421 if (!PyDict_Contains(otherdata, key)) {
422 if (PyDict_SetItem(tgtdata, key, Py_True) == -1)
423 return NULL;
424 }
425 }
426 return result;
427}
428
429PyDoc_STRVAR(difference_doc,
430"Return the difference of two sets as a new set.\n\
431\n\
432(i.e. all elements that are in this set but not the other.)");
433static PyObject *
Raymond Hettingera690a992003-11-16 16:17:49 +0000434set_sub(PySetObject *so, PyObject *other)
435{
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000436 if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000437 Py_INCREF(Py_NotImplemented);
438 return Py_NotImplemented;
439 }
440 return set_difference(so, other);
441}
442
443static PyObject *
444set_isub(PySetObject *so, PyObject *other)
445{
446 PyObject *result;
447
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000448 if (!PyAnySet_Check(other)) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000449 Py_INCREF(Py_NotImplemented);
450 return Py_NotImplemented;
451 }
452 result = set_difference_update(so, other);
453 if (result == NULL)
454 return NULL;
455 Py_DECREF(result);
456 Py_INCREF(so);
457 return (PyObject *)so;
458}
459
460static PyObject *
Raymond Hettingera690a992003-11-16 16:17:49 +0000461set_symmetric_difference_update(PySetObject *so, PyObject *other)
462{
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000463 PyObject *selfdata, *otherdata;
Raymond Hettingera690a992003-11-16 16:17:49 +0000464 PySetObject *otherset = NULL;
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000465 PyObject *key, *value;
466 int pos = 0;
Raymond Hettingera690a992003-11-16 16:17:49 +0000467
468 selfdata = so->data;
Raymond Hettingera690a992003-11-16 16:17:49 +0000469 if (PyDict_Check(other))
470 otherdata = other;
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000471 else if (PyAnySet_Check(other))
Raymond Hettingera690a992003-11-16 16:17:49 +0000472 otherdata = ((PySetObject *)other)->data;
473 else {
474 otherset = (PySetObject *)make_new_set(so->ob_type, other);
475 if (otherset == NULL)
476 return NULL;
477 otherdata = otherset->data;
478 }
479
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000480 while (PyDict_Next(otherdata, &pos, &key, &value)) {
481 if (PyDict_Contains(selfdata, key)) {
482 if (PyDict_DelItem(selfdata, key) == -1) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000483 Py_XDECREF(otherset);
Raymond Hettingera690a992003-11-16 16:17:49 +0000484 return NULL;
485 }
486 } else {
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000487 if (PyDict_SetItem(selfdata, key, Py_True) == -1) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000488 Py_XDECREF(otherset);
Raymond Hettingera690a992003-11-16 16:17:49 +0000489 return NULL;
490 }
491 }
Raymond Hettingera690a992003-11-16 16:17:49 +0000492 }
493 Py_XDECREF(otherset);
Raymond Hettingera690a992003-11-16 16:17:49 +0000494 Py_RETURN_NONE;
495}
496
497PyDoc_STRVAR(symmetric_difference_update_doc,
498"Update a set with the symmetric difference of itself and another.");
499
500static PyObject *
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +0000501set_symmetric_difference(PySetObject *so, PyObject *other)
502{
503 PySetObject *result;
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000504 PyObject *selfdata, *otherdata, *tgtdata, *rv, *otherset;
505 PyObject *key, *value;
506 int pos = 0;
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +0000507
508 if (PyDict_Check(other))
509 otherdata = other;
510 else if (PyAnySet_Check(other))
511 otherdata = ((PySetObject *)other)->data;
512 else {
513 otherset = make_new_set(so->ob_type, other);
514 if (otherset == NULL)
515 return NULL;
516 rv = set_symmetric_difference_update((PySetObject *)otherset, (PyObject *)so);
517 if (rv == NULL)
518 return NULL;
519 Py_DECREF(rv);
520 return otherset;
521 }
522
523 result = (PySetObject *)make_new_set(so->ob_type, NULL);
524 if (result == NULL)
525 return NULL;
526 tgtdata = result->data;
527 selfdata = so->data;
528
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000529 while (PyDict_Next(otherdata, &pos, &key, &value)) {
530 if (!PyDict_Contains(selfdata, key)) {
531 if (PyDict_SetItem(tgtdata, key, Py_True) == -1) {
532 Py_DECREF(result);
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +0000533 return NULL;
534 }
535 }
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +0000536 }
537
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000538 pos = 0;
539 while (PyDict_Next(selfdata, &pos, &key, &value)) {
540 if (!PyDict_Contains(otherdata, key)) {
541 if (PyDict_SetItem(tgtdata, key, Py_True) == -1) {
542 Py_DECREF(result);
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +0000543 return NULL;
544 }
545 }
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +0000546 }
547
548 return (PyObject *)result;
549}
550
551PyDoc_STRVAR(symmetric_difference_doc,
552"Return the symmetric difference of two sets as a new set.\n\
553\n\
554(i.e. all elements that are in exactly one of the sets.)");
555
556static PyObject *
Raymond Hettingera690a992003-11-16 16:17:49 +0000557set_xor(PySetObject *so, PyObject *other)
558{
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000559 if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000560 Py_INCREF(Py_NotImplemented);
561 return Py_NotImplemented;
562 }
563 return set_symmetric_difference(so, other);
564}
565
566static PyObject *
567set_ixor(PySetObject *so, PyObject *other)
568{
569 PyObject *result;
570
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000571 if (!PyAnySet_Check(other)) {
Raymond Hettingera690a992003-11-16 16:17:49 +0000572 Py_INCREF(Py_NotImplemented);
573 return Py_NotImplemented;
574 }
575 result = set_symmetric_difference_update(so, other);
576 if (result == NULL)
577 return NULL;
578 Py_DECREF(result);
579 Py_INCREF(so);
580 return (PyObject *)so;
581}
582
583static PyObject *
584set_issubset(PySetObject *so, PyObject *other)
585{
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000586 PyObject *otherdata, *tmp, *result;
587 PyObject *key, *value;
588 int pos = 0;
Raymond Hettingera690a992003-11-16 16:17:49 +0000589
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000590 if (!PyAnySet_Check(other)) {
Raymond Hettinger3fbec702003-11-21 07:56:36 +0000591 tmp = make_new_set(&PySet_Type, other);
592 if (tmp == NULL)
593 return NULL;
594 result = set_issubset(so, tmp);
595 Py_DECREF(tmp);
596 return result;
Raymond Hettingera690a992003-11-16 16:17:49 +0000597 }
598 if (set_len(so) > set_len((PySetObject *)other))
599 Py_RETURN_FALSE;
Raymond Hettingera690a992003-11-16 16:17:49 +0000600
601 otherdata = ((PySetObject *)other)->data;
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000602 while (PyDict_Next(((PySetObject *)so)->data, &pos, &key, &value)) {
603 if (!PyDict_Contains(otherdata, key))
Raymond Hettingera690a992003-11-16 16:17:49 +0000604 Py_RETURN_FALSE;
Raymond Hettingera690a992003-11-16 16:17:49 +0000605 }
Raymond Hettingera690a992003-11-16 16:17:49 +0000606 Py_RETURN_TRUE;
607}
608
609PyDoc_STRVAR(issubset_doc, "Report whether another set contains this set.");
610
611static PyObject *
612set_issuperset(PySetObject *so, PyObject *other)
613{
Raymond Hettinger3fbec702003-11-21 07:56:36 +0000614 PyObject *tmp, *result;
615
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000616 if (!PyAnySet_Check(other)) {
Raymond Hettinger3fbec702003-11-21 07:56:36 +0000617 tmp = make_new_set(&PySet_Type, other);
618 if (tmp == NULL)
619 return NULL;
620 result = set_issuperset(so, tmp);
621 Py_DECREF(tmp);
622 return result;
Raymond Hettingera690a992003-11-16 16:17:49 +0000623 }
624 return set_issubset((PySetObject *)other, (PyObject *)so);
625}
626
627PyDoc_STRVAR(issuperset_doc, "Report whether this set contains another set.");
628
629static long
630set_nohash(PyObject *self)
631{
632 PyErr_SetString(PyExc_TypeError, "set objects are unhashable");
633 return -1;
634}
635
636static int
637set_nocmp(PyObject *self)
638{
639 PyErr_SetString(PyExc_TypeError, "cannot compare sets using cmp()");
640 return -1;
641}
642
643static long
644frozenset_hash(PyObject *self)
645{
Raymond Hettingera690a992003-11-16 16:17:49 +0000646 PySetObject *so = (PySetObject *)self;
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000647 PyObject *key, *value;
648 int pos = 0;
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000649 long hash = 0;
Raymond Hettinger438e02d2003-12-13 19:38:47 +0000650
Raymond Hettingera690a992003-11-16 16:17:49 +0000651 if (so->hash != -1)
652 return so->hash;
Raymond Hettingera690a992003-11-16 16:17:49 +0000653
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000654 while (PyDict_Next(so->data, &pos, &key, &value)) {
Raymond Hettinger49ba4c32003-11-23 02:49:05 +0000655 /* Multiplying by a large prime increases the bit dispersion for
656 closely spaced hash values. The is important because some
657 use cases have many combinations of a small number of
658 elements with nearby hashes so that many distinct combinations
659 collapse to only a handful of distinct hash values. */
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000660 hash ^= PyObject_Hash(key) * 3644798167u;
Raymond Hettingera690a992003-11-16 16:17:49 +0000661 }
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000662 so->hash = hash;
Raymond Hettingera690a992003-11-16 16:17:49 +0000663 return hash;
664}
665
666static PyObject *
667set_richcompare(PySetObject *v, PyObject *w, int op)
668{
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000669 if(!PyAnySet_Check(w)) {
670 if (op == Py_EQ)
671 Py_RETURN_FALSE;
672 if (op == Py_NE)
673 Py_RETURN_TRUE;
Raymond Hettingera690a992003-11-16 16:17:49 +0000674 PyErr_SetString(PyExc_TypeError, "can only compare to a set");
675 return NULL;
676 }
677 switch (op) {
678 case Py_EQ:
679 case Py_NE:
680 return PyObject_RichCompare(((PySetObject *)v)->data,
681 ((PySetObject *)w)->data, op);
682 case Py_LE:
683 return set_issubset((PySetObject *)v, w);
684 case Py_GE:
685 return set_issuperset((PySetObject *)v, w);
686 case Py_LT:
687 if (set_len(v) >= set_len((PySetObject *)w))
688 Py_RETURN_FALSE;
689 return set_issubset((PySetObject *)v, w);
690 case Py_GT:
691 if (set_len(v) <= set_len((PySetObject *)w))
692 Py_RETURN_FALSE;
693 return set_issuperset((PySetObject *)v, w);
694 }
695 Py_INCREF(Py_NotImplemented);
696 return Py_NotImplemented;
697}
698
699static PyObject *
700set_repr(PySetObject *so)
701{
702 PyObject *keys, *result, *listrepr;
703
704 keys = PyDict_Keys(so->data);
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000705 if (keys == NULL)
706 return NULL;
Raymond Hettingera690a992003-11-16 16:17:49 +0000707 listrepr = PyObject_Repr(keys);
708 Py_DECREF(keys);
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000709 if (listrepr == NULL)
710 return NULL;
Raymond Hettingera690a992003-11-16 16:17:49 +0000711
712 result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name,
713 PyString_AS_STRING(listrepr));
714 Py_DECREF(listrepr);
715 return result;
716}
717
718static int
719set_tp_print(PySetObject *so, FILE *fp, int flags)
720{
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000721 PyObject *key, *value;
Raymond Hettinger438e02d2003-12-13 19:38:47 +0000722 int pos=0, firstpass=1;
Raymond Hettingera690a992003-11-16 16:17:49 +0000723
Raymond Hettingera690a992003-11-16 16:17:49 +0000724 fprintf(fp, "%s([", so->ob_type->tp_name);
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000725 while (PyDict_Next(so->data, &pos, &key, &value)) {
Raymond Hettinger438e02d2003-12-13 19:38:47 +0000726 if (firstpass)
727 firstpass = 0;
728 else
Raymond Hettingere2c277a2003-11-16 16:36:58 +0000729 fprintf(fp, ", ");
Raymond Hettingerdc5ae112003-12-13 14:46:46 +0000730 if (PyObject_Print(key, fp, 0) != 0)
Raymond Hettingera690a992003-11-16 16:17:49 +0000731 return -1;
Raymond Hettingera690a992003-11-16 16:17:49 +0000732 }
Raymond Hettingera690a992003-11-16 16:17:49 +0000733 fprintf(fp, "])");
734 return 0;
735}
736
737static PyObject *
738set_clear(PySetObject *so)
739{
740 PyDict_Clear(so->data);
741 so->hash = -1;
Raymond Hettinger438e02d2003-12-13 19:38:47 +0000742 Py_RETURN_NONE;
Raymond Hettingera690a992003-11-16 16:17:49 +0000743}
744
745PyDoc_STRVAR(clear_doc, "Remove all elements from this set.");
746
747static int
748set_tp_clear(PySetObject *so)
749{
750 PyDict_Clear(so->data);
751 so->hash = -1;
752 return 0;
753}
754
755static PyObject *
756set_add(PySetObject *so, PyObject *item)
757{
758 if (PyDict_SetItem(so->data, item, Py_True) == -1)
759 return NULL;
Raymond Hettinger438e02d2003-12-13 19:38:47 +0000760 Py_RETURN_NONE;
Raymond Hettingera690a992003-11-16 16:17:49 +0000761}
762
763PyDoc_STRVAR(add_doc,
764"Add an element to a set.\n\
765\n\
766This has no effect if the element is already present.");
767
768static PyObject *
769set_remove(PySetObject *so, PyObject *item)
770{
Raymond Hettinger0deab622003-12-13 18:53:18 +0000771 PyObject *tmp, *result;
Raymond Hettingerbfd334a2003-11-22 03:55:23 +0000772
Raymond Hettinger0deab622003-12-13 18:53:18 +0000773 if (PyType_IsSubtype(item->ob_type, &PySet_Type)) {
Raymond Hettingerbfd334a2003-11-22 03:55:23 +0000774 tmp = frozenset_dict_wrapper(((PySetObject *)(item))->data);
775 if (tmp == NULL)
776 return NULL;
Raymond Hettinger0deab622003-12-13 18:53:18 +0000777 result = set_remove(so, tmp);
Raymond Hettingerbfd334a2003-11-22 03:55:23 +0000778 Py_DECREF(tmp);
Raymond Hettinger0deab622003-12-13 18:53:18 +0000779 return result;
Raymond Hettingerbfd334a2003-11-22 03:55:23 +0000780 }
Raymond Hettinger0deab622003-12-13 18:53:18 +0000781
782 if (PyDict_DelItem(so->data, item) == -1)
783 return NULL;
Raymond Hettinger438e02d2003-12-13 19:38:47 +0000784 Py_RETURN_NONE;
Raymond Hettingera690a992003-11-16 16:17:49 +0000785}
786
787PyDoc_STRVAR(remove_doc,
788"Remove an element from a set; it must be a member.\n\
789\n\
790If the element is not a member, raise a KeyError.");
791
792static PyObject *
793set_discard(PySetObject *so, PyObject *item)
794{
Raymond Hettinger0deab622003-12-13 18:53:18 +0000795 PyObject *tmp, *result;
796
797 if (PyType_IsSubtype(item->ob_type, &PySet_Type)) {
798 tmp = frozenset_dict_wrapper(((PySetObject *)(item))->data);
799 if (tmp == NULL)
800 return NULL;
801 result = set_discard(so, tmp);
802 Py_DECREF(tmp);
803 return result;
804 }
Raymond Hettingerbfd334a2003-11-22 03:55:23 +0000805
Guido van Rossumb61982b2003-11-18 19:27:19 +0000806 if (PyDict_DelItem(so->data, item) == -1) {
Raymond Hettinger0deab622003-12-13 18:53:18 +0000807 if (!PyErr_ExceptionMatches(PyExc_KeyError))
808 return NULL;
809 PyErr_Clear();
Guido van Rossumb61982b2003-11-18 19:27:19 +0000810 }
Raymond Hettinger438e02d2003-12-13 19:38:47 +0000811 Py_RETURN_NONE;
Raymond Hettingera690a992003-11-16 16:17:49 +0000812}
813
814PyDoc_STRVAR(discard_doc,
815"Remove an element from a set if it is a member.\n\
816\n\
817If the element is not a member, do nothing.");
818
819static PyObject *
820set_pop(PySetObject *so)
821{
822 PyObject *key, *value;
823 int pos = 0;
824
825 if (!PyDict_Next(so->data, &pos, &key, &value)) {
826 PyErr_SetString(PyExc_KeyError, "pop from an empty set");
827 return NULL;
828 }
829 Py_INCREF(key);
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000830 if (PyDict_DelItem(so->data, key) == -1) {
831 Py_DECREF(key);
832 return NULL;
833 }
Raymond Hettingera690a992003-11-16 16:17:49 +0000834 return key;
835}
836
837PyDoc_STRVAR(pop_doc, "Remove and return an arbitrary set element.");
838
839static PyObject *
840set_reduce(PySetObject *so)
841{
842 PyObject *keys=NULL, *args=NULL, *result=NULL;
843
844 keys = PyDict_Keys(so->data);
845 if (keys == NULL)
846 goto done;
847 args = PyTuple_Pack(1, keys);
848 if (args == NULL)
849 goto done;
850 result = PyTuple_Pack(2, so->ob_type, args);
851done:
852 Py_XDECREF(args);
853 Py_XDECREF(keys);
854 return result;
855}
856
857PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
858
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000859static int
860set_init(PySetObject *self, PyObject *args, PyObject *kwds)
861{
862 PyObject *iterable = NULL;
863 PyObject *result;
864
865 if (!PyAnySet_Check(self))
866 return -1;
867 if (!PyArg_UnpackTuple(args, self->ob_type->tp_name, 0, 1, &iterable))
868 return -1;
869 PyDict_Clear(self->data);
870 self->hash = -1;
871 if (iterable == NULL)
872 return 0;
Raymond Hettingera38123e2003-11-24 22:18:49 +0000873 result = set_update(self, iterable);
Raymond Hettinger50a4bb32003-11-17 16:42:33 +0000874 if (result != NULL) {
875 Py_DECREF(result);
876 return 0;
877 }
878 return -1;
879}
880
Raymond Hettingera690a992003-11-16 16:17:49 +0000881static PySequenceMethods set_as_sequence = {
882 (inquiry)set_len, /* sq_length */
883 0, /* sq_concat */
884 0, /* sq_repeat */
885 0, /* sq_item */
886 0, /* sq_slice */
887 0, /* sq_ass_item */
888 0, /* sq_ass_slice */
889 (objobjproc)set_contains, /* sq_contains */
890};
891
892/* set object ********************************************************/
893
894static PyMethodDef set_methods[] = {
895 {"add", (PyCFunction)set_add, METH_O,
896 add_doc},
897 {"clear", (PyCFunction)set_clear, METH_NOARGS,
898 clear_doc},
Raymond Hettinger0deab622003-12-13 18:53:18 +0000899 {"__contains__",(PyCFunction)set_direct_contains, METH_O | METH_COEXIST,
Raymond Hettinger8f5cdaa2003-12-13 11:26:12 +0000900 contains_doc},
Raymond Hettingera690a992003-11-16 16:17:49 +0000901 {"copy", (PyCFunction)set_copy, METH_NOARGS,
902 copy_doc},
903 {"__copy__", (PyCFunction)set_copy, METH_NOARGS,
904 copy_doc},
905 {"discard", (PyCFunction)set_discard, METH_O,
906 discard_doc},
907 {"difference", (PyCFunction)set_difference, METH_O,
908 difference_doc},
909 {"difference_update", (PyCFunction)set_difference_update, METH_O,
910 difference_update_doc},
911 {"intersection",(PyCFunction)set_intersection, METH_O,
912 intersection_doc},
913 {"intersection_update",(PyCFunction)set_intersection_update, METH_O,
914 intersection_update_doc},
915 {"issubset", (PyCFunction)set_issubset, METH_O,
916 issubset_doc},
917 {"issuperset", (PyCFunction)set_issuperset, METH_O,
918 issuperset_doc},
919 {"pop", (PyCFunction)set_pop, METH_NOARGS,
920 pop_doc},
921 {"__reduce__", (PyCFunction)set_reduce, METH_NOARGS,
922 reduce_doc},
923 {"remove", (PyCFunction)set_remove, METH_O,
924 remove_doc},
925 {"symmetric_difference",(PyCFunction)set_symmetric_difference, METH_O,
926 symmetric_difference_doc},
927 {"symmetric_difference_update",(PyCFunction)set_symmetric_difference_update, METH_O,
928 symmetric_difference_update_doc},
929 {"union", (PyCFunction)set_union, METH_O,
930 union_doc},
Raymond Hettingera38123e2003-11-24 22:18:49 +0000931 {"update", (PyCFunction)set_update, METH_O,
932 update_doc},
Raymond Hettingera690a992003-11-16 16:17:49 +0000933 {NULL, NULL} /* sentinel */
934};
935
936static PyNumberMethods set_as_number = {
937 0, /*nb_add*/
938 (binaryfunc)set_sub, /*nb_subtract*/
939 0, /*nb_multiply*/
940 0, /*nb_divide*/
941 0, /*nb_remainder*/
942 0, /*nb_divmod*/
943 0, /*nb_power*/
944 0, /*nb_negative*/
945 0, /*nb_positive*/
946 0, /*nb_absolute*/
947 0, /*nb_nonzero*/
948 0, /*nb_invert*/
949 0, /*nb_lshift*/
950 0, /*nb_rshift*/
951 (binaryfunc)set_and, /*nb_and*/
952 (binaryfunc)set_xor, /*nb_xor*/
953 (binaryfunc)set_or, /*nb_or*/
954 0, /*nb_coerce*/
955 0, /*nb_int*/
956 0, /*nb_long*/
957 0, /*nb_float*/
958 0, /*nb_oct*/
959 0, /*nb_hex*/
960 0, /*nb_inplace_add*/
961 (binaryfunc)set_isub, /*nb_inplace_subtract*/
962 0, /*nb_inplace_multiply*/
963 0, /*nb_inplace_divide*/
964 0, /*nb_inplace_remainder*/
965 0, /*nb_inplace_power*/
966 0, /*nb_inplace_lshift*/
967 0, /*nb_inplace_rshift*/
968 (binaryfunc)set_iand, /*nb_inplace_and*/
969 (binaryfunc)set_ixor, /*nb_inplace_xor*/
970 (binaryfunc)set_ior, /*nb_inplace_or*/
971};
972
973PyDoc_STRVAR(set_doc,
974"set(iterable) --> set object\n\
975\n\
976Build an unordered collection.");
977
978PyTypeObject PySet_Type = {
979 PyObject_HEAD_INIT(&PyType_Type)
980 0, /* ob_size */
981 "set", /* tp_name */
982 sizeof(PySetObject), /* tp_basicsize */
983 0, /* tp_itemsize */
984 /* methods */
985 (destructor)set_dealloc, /* tp_dealloc */
986 (printfunc)set_tp_print, /* tp_print */
987 0, /* tp_getattr */
988 0, /* tp_setattr */
989 (cmpfunc)set_nocmp, /* tp_compare */
990 (reprfunc)set_repr, /* tp_repr */
991 &set_as_number, /* tp_as_number */
992 &set_as_sequence, /* tp_as_sequence */
993 0, /* tp_as_mapping */
994 set_nohash, /* tp_hash */
995 0, /* tp_call */
996 0, /* tp_str */
997 PyObject_GenericGetAttr, /* tp_getattro */
998 0, /* tp_setattro */
999 0, /* tp_as_buffer */
1000 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES |
1001 Py_TPFLAGS_BASETYPE, /* tp_flags */
1002 set_doc, /* tp_doc */
1003 (traverseproc)set_traverse, /* tp_traverse */
1004 (inquiry)set_tp_clear, /* tp_clear */
1005 (richcmpfunc)set_richcompare, /* tp_richcompare */
1006 0, /* tp_weaklistoffset */
1007 (getiterfunc)set_iter, /* tp_iter */
1008 0, /* tp_iternext */
1009 set_methods, /* tp_methods */
1010 0, /* tp_members */
1011 0, /* tp_getset */
1012 0, /* tp_base */
1013 0, /* tp_dict */
1014 0, /* tp_descr_get */
1015 0, /* tp_descr_set */
1016 0, /* tp_dictoffset */
Raymond Hettinger50a4bb32003-11-17 16:42:33 +00001017 (initproc)set_init, /* tp_init */
Raymond Hettingera690a992003-11-16 16:17:49 +00001018 PyType_GenericAlloc, /* tp_alloc */
1019 set_new, /* tp_new */
1020 PyObject_GC_Del, /* tp_free */
1021};
1022
1023/* frozenset object ********************************************************/
1024
1025
1026static PyMethodDef frozenset_methods[] = {
Raymond Hettinger0deab622003-12-13 18:53:18 +00001027 {"__contains__",(PyCFunction)set_direct_contains, METH_O | METH_COEXIST,
Raymond Hettinger8f5cdaa2003-12-13 11:26:12 +00001028 contains_doc},
Raymond Hettinger49ba4c32003-11-23 02:49:05 +00001029 {"copy", (PyCFunction)frozenset_copy, METH_NOARGS,
Raymond Hettingera690a992003-11-16 16:17:49 +00001030 copy_doc},
Raymond Hettinger49ba4c32003-11-23 02:49:05 +00001031 {"__copy__", (PyCFunction)frozenset_copy, METH_NOARGS,
Raymond Hettingera690a992003-11-16 16:17:49 +00001032 copy_doc},
Raymond Hettinger49ba4c32003-11-23 02:49:05 +00001033 {"difference", (PyCFunction)set_difference, METH_O,
Raymond Hettingera690a992003-11-16 16:17:49 +00001034 difference_doc},
1035 {"intersection",(PyCFunction)set_intersection, METH_O,
1036 intersection_doc},
Raymond Hettinger49ba4c32003-11-23 02:49:05 +00001037 {"issubset", (PyCFunction)set_issubset, METH_O,
Raymond Hettingera690a992003-11-16 16:17:49 +00001038 issubset_doc},
Raymond Hettinger49ba4c32003-11-23 02:49:05 +00001039 {"issuperset", (PyCFunction)set_issuperset, METH_O,
Raymond Hettingera690a992003-11-16 16:17:49 +00001040 issuperset_doc},
1041 {"__reduce__", (PyCFunction)set_reduce, METH_NOARGS,
1042 reduce_doc},
1043 {"symmetric_difference",(PyCFunction)set_symmetric_difference, METH_O,
1044 symmetric_difference_doc},
1045 {"union", (PyCFunction)set_union, METH_O,
1046 union_doc},
1047 {NULL, NULL} /* sentinel */
1048};
1049
1050static PyNumberMethods frozenset_as_number = {
1051 0, /*nb_add*/
1052 (binaryfunc)set_sub, /*nb_subtract*/
1053 0, /*nb_multiply*/
1054 0, /*nb_divide*/
1055 0, /*nb_remainder*/
1056 0, /*nb_divmod*/
1057 0, /*nb_power*/
1058 0, /*nb_negative*/
1059 0, /*nb_positive*/
1060 0, /*nb_absolute*/
1061 0, /*nb_nonzero*/
1062 0, /*nb_invert*/
1063 0, /*nb_lshift*/
1064 0, /*nb_rshift*/
1065 (binaryfunc)set_and, /*nb_and*/
1066 (binaryfunc)set_xor, /*nb_xor*/
1067 (binaryfunc)set_or, /*nb_or*/
1068};
1069
1070PyDoc_STRVAR(frozenset_doc,
1071"frozenset(iterable) --> frozenset object\n\
1072\n\
1073Build an immutable unordered collection.");
1074
1075PyTypeObject PyFrozenSet_Type = {
1076 PyObject_HEAD_INIT(&PyType_Type)
1077 0, /* ob_size */
1078 "frozenset", /* tp_name */
1079 sizeof(PySetObject), /* tp_basicsize */
Raymond Hettingerf5f41bf2003-11-24 02:57:33 +00001080 0, /* tp_itemsize */ /* methods */
Raymond Hettingera690a992003-11-16 16:17:49 +00001081 (destructor)set_dealloc, /* tp_dealloc */
1082 (printfunc)set_tp_print, /* tp_print */
1083 0, /* tp_getattr */
1084 0, /* tp_setattr */
1085 (cmpfunc)set_nocmp, /* tp_compare */
1086 (reprfunc)set_repr, /* tp_repr */
1087 &frozenset_as_number, /* tp_as_number */
1088 &set_as_sequence, /* tp_as_sequence */
1089 0, /* tp_as_mapping */
1090 frozenset_hash, /* tp_hash */
1091 0, /* tp_call */
1092 0, /* tp_str */
1093 PyObject_GenericGetAttr, /* tp_getattro */
1094 0, /* tp_setattro */
1095 0, /* tp_as_buffer */
1096 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES |
1097 Py_TPFLAGS_BASETYPE, /* tp_flags */
1098 frozenset_doc, /* tp_doc */
1099 (traverseproc)set_traverse, /* tp_traverse */
1100 0, /* tp_clear */
1101 (richcmpfunc)set_richcompare, /* tp_richcompare */
1102 0, /* tp_weaklistoffset */
1103 (getiterfunc)set_iter, /* tp_iter */
1104 0, /* tp_iternext */
1105 frozenset_methods, /* tp_methods */
1106 0, /* tp_members */
1107 0, /* tp_getset */
1108 0, /* tp_base */
1109 0, /* tp_dict */
1110 0, /* tp_descr_get */
1111 0, /* tp_descr_set */
1112 0, /* tp_dictoffset */
1113 0, /* tp_init */
1114 PyType_GenericAlloc, /* tp_alloc */
Raymond Hettinger50a4bb32003-11-17 16:42:33 +00001115 frozenset_new, /* tp_new */
Raymond Hettingera690a992003-11-16 16:17:49 +00001116 PyObject_GC_Del, /* tp_free */
1117};