Mercurial > cpython-lru_cache-weakref
annotate Include/setobject.h @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 75039d3118ae |
| children | fd25030223b0 |
| rev | line source |
|---|---|
|
30929
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
1 /* Set object interface */ |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
2 |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
3 #ifndef Py_SETOBJECT_H |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
4 #define Py_SETOBJECT_H |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
5 #ifdef __cplusplus |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
6 extern "C" { |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
7 #endif |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
8 |
|
35292
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
9 |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
10 /* |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
11 There are three kinds of slots in the table: |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
12 |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
13 1. Unused: key == NULL |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
14 2. Active: key != NULL and key != dummy |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
15 3. Dummy: key == dummy |
|
35301
3086620db46b
Model set.pop() after dict.popitem().
Raymond Hettinger <python@rcn.com>
parents:
35297
diff
changeset
|
16 |
|
3086620db46b
Model set.pop() after dict.popitem().
Raymond Hettinger <python@rcn.com>
parents:
35297
diff
changeset
|
17 Note: .pop() abuses the hash field of an Unused or Dummy slot to |
|
3086620db46b
Model set.pop() after dict.popitem().
Raymond Hettinger <python@rcn.com>
parents:
35297
diff
changeset
|
18 hold a search finger. The hash field of Unused or Dummy slots has |
|
3086620db46b
Model set.pop() after dict.popitem().
Raymond Hettinger <python@rcn.com>
parents:
35297
diff
changeset
|
19 no meaning otherwise. |
|
35292
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
20 */ |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
21 |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
22 #define PySet_MINSIZE 8 |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
23 |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
24 typedef struct { |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
25 long hash; /* cached hash code for the entry key */ |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
26 PyObject *key; |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
27 } setentry; |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
28 |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
29 |
|
30929
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
30 /* |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
31 This data structure is shared by set and frozenset objects. |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
32 */ |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
33 |
|
35292
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
34 typedef struct _setobject PySetObject; |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
35 struct _setobject { |
|
30929
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
36 PyObject_HEAD |
|
35292
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
37 |
| 38872 | 38 Py_ssize_t fill; /* # Active + # Dummy */ |
| 39 Py_ssize_t used; /* # Active */ | |
|
35292
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
40 |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
41 /* The table contains mask + 1 slots, and that's a power of 2. |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
42 * We store the mask instead of the size because the mask is more |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
43 * frequently needed. |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
44 */ |
| 38872 | 45 Py_ssize_t mask; |
|
33856
60c60dc75c77
Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents:
32158
diff
changeset
|
46 |
|
35292
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
47 /* table points to smalltable for small tables, else to |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
48 * additional malloc'ed memory. table is never NULL! This rule |
|
35297
26bf6c27e9ce
* Improve code for the empty frozenset singleton:
Raymond Hettinger <python@rcn.com>
parents:
35292
diff
changeset
|
49 * saves repeated runtime null-tests. |
|
33856
60c60dc75c77
Wrote down the invariants of some common objects whose structure is
Armin Rigo <arigo@tunes.org>
parents:
32158
diff
changeset
|
50 */ |
|
35292
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
51 setentry *table; |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
52 setentry *(*lookup)(PySetObject *so, PyObject *key, long hash); |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
53 setentry smalltable[PySet_MINSIZE]; |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
54 |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
55 long hash; /* only used by frozenset objects */ |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
56 PyObject *weakreflist; /* List of weak references */ |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
57 }; |
|
30929
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
58 |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
59 PyAPI_DATA(PyTypeObject) PySet_Type; |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
60 PyAPI_DATA(PyTypeObject) PyFrozenSet_Type; |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
61 |
|
35321
bdcb01a9b60c
* Bring in INIT_NONZERO_SET_SLOTS macro from dictionary code.
Raymond Hettinger <python@rcn.com>
parents:
35301
diff
changeset
|
62 /* Invariants for frozensets: |
|
35292
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
63 * data is immutable. |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
64 * hash is the hash of the frozenset or -1 if not computed yet. |
|
35321
bdcb01a9b60c
* Bring in INIT_NONZERO_SET_SLOTS macro from dictionary code.
Raymond Hettinger <python@rcn.com>
parents:
35301
diff
changeset
|
65 * Invariants for sets: |
|
bdcb01a9b60c
* Bring in INIT_NONZERO_SET_SLOTS macro from dictionary code.
Raymond Hettinger <python@rcn.com>
parents:
35301
diff
changeset
|
66 * hash is -1 |
|
35292
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
67 */ |
|
35a698302c63
Revised the set() and frozenset() implementaion to use its own internal
Raymond Hettinger <python@rcn.com>
parents:
33856
diff
changeset
|
68 |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
69 #define PyFrozenSet_CheckExact(ob) (Py_TYPE(ob) == &PyFrozenSet_Type) |
|
35321
bdcb01a9b60c
* Bring in INIT_NONZERO_SET_SLOTS macro from dictionary code.
Raymond Hettinger <python@rcn.com>
parents:
35301
diff
changeset
|
70 #define PyAnySet_CheckExact(ob) \ |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
71 (Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type) |
|
30931
fa6e8d4f88c6
Various fixups (most suggested by Armin Rigo).
Raymond Hettinger <python@rcn.com>
parents:
30929
diff
changeset
|
72 #define PyAnySet_Check(ob) \ |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
73 (Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type || \ |
|
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
74 PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \ |
|
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42334
diff
changeset
|
75 PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type)) |
|
45037
77d052ce1f4c
Factor-out common code with a new macro
Raymond Hettinger <python@rcn.com>
parents:
44350
diff
changeset
|
76 #define PySet_Check(ob) \ |
|
45138
4f6f44bc5195
Ensure that PySet_Add() operates on a newly created frozenset, like PyTuple_SetItem does.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45037
diff
changeset
|
77 (Py_TYPE(ob) == &PySet_Type || \ |
|
4f6f44bc5195
Ensure that PySet_Add() operates on a newly created frozenset, like PyTuple_SetItem does.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45037
diff
changeset
|
78 PyType_IsSubtype(Py_TYPE(ob), &PySet_Type)) |
|
4f6f44bc5195
Ensure that PySet_Add() operates on a newly created frozenset, like PyTuple_SetItem does.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45037
diff
changeset
|
79 #define PyFrozenSet_Check(ob) \ |
|
45139
75039d3118ae
Nasty typo in setobject.h
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45138
diff
changeset
|
80 (Py_TYPE(ob) == &PyFrozenSet_Type || \ |
|
45138
4f6f44bc5195
Ensure that PySet_Add() operates on a newly created frozenset, like PyTuple_SetItem does.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
45037
diff
changeset
|
81 PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type)) |
|
30931
fa6e8d4f88c6
Various fixups (most suggested by Armin Rigo).
Raymond Hettinger <python@rcn.com>
parents:
30929
diff
changeset
|
82 |
|
35346
dd2357953fe3
Add a C API for sets and frozensets.
Raymond Hettinger <python@rcn.com>
parents:
35321
diff
changeset
|
83 PyAPI_FUNC(PyObject *) PySet_New(PyObject *); |
|
dd2357953fe3
Add a C API for sets and frozensets.
Raymond Hettinger <python@rcn.com>
parents:
35321
diff
changeset
|
84 PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *); |
|
36833
9e81788b0d4b
Use Py_ssize_t for PySet_Size() like all the other Py*_Size() functions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35348
diff
changeset
|
85 PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset); |
|
35346
dd2357953fe3
Add a C API for sets and frozensets.
Raymond Hettinger <python@rcn.com>
parents:
35321
diff
changeset
|
86 #define PySet_GET_SIZE(so) (((PySetObject *)(so))->used) |
|
37315
19059df45cfe
SF patch #1458476 with modifications based on discussions in python-dev. This
Barry Warsaw <barry@python.org>
parents:
36833
diff
changeset
|
87 PyAPI_FUNC(int) PySet_Clear(PyObject *set); |
|
35346
dd2357953fe3
Add a C API for sets and frozensets.
Raymond Hettinger <python@rcn.com>
parents:
35321
diff
changeset
|
88 PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key); |
|
35348
2f1bf64b837e
Numerous fix-ups to C API and docs. Added tests for C API.
Raymond Hettinger <python@rcn.com>
parents:
35346
diff
changeset
|
89 PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key); |
|
35346
dd2357953fe3
Add a C API for sets and frozensets.
Raymond Hettinger <python@rcn.com>
parents:
35321
diff
changeset
|
90 PyAPI_FUNC(int) PySet_Add(PyObject *set, PyObject *key); |
|
41248
ec6fb091039b
Extend work on rev 52962 and 53829 eliminating redundant PyObject_Hash() calls and fixing set/dict interoperability.
Raymond Hettinger <python@rcn.com>
parents:
38872
diff
changeset
|
91 PyAPI_FUNC(int) _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **key); |
|
ec6fb091039b
Extend work on rev 52962 and 53829 eliminating redundant PyObject_Hash() calls and fixing set/dict interoperability.
Raymond Hettinger <python@rcn.com>
parents:
38872
diff
changeset
|
92 PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash); |
|
35346
dd2357953fe3
Add a C API for sets and frozensets.
Raymond Hettinger <python@rcn.com>
parents:
35321
diff
changeset
|
93 PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set); |
|
37315
19059df45cfe
SF patch #1458476 with modifications based on discussions in python-dev. This
Barry Warsaw <barry@python.org>
parents:
36833
diff
changeset
|
94 PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable); |
|
35346
dd2357953fe3
Add a C API for sets and frozensets.
Raymond Hettinger <python@rcn.com>
parents:
35321
diff
changeset
|
95 |
|
30929
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
96 #ifdef __cplusplus |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
97 } |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
98 #endif |
|
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
99 #endif /* !Py_SETOBJECT_H */ |
