]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.10/Include/setobject.h
AppPkg/Applications/Python/Python-2.7.10: Initial Checkin part 1/5.
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Include / setobject.h
CommitLineData
c8042e10
DM
1/* Set object interface */\r
2\r
3#ifndef Py_SETOBJECT_H\r
4#define Py_SETOBJECT_H\r
5#ifdef __cplusplus\r
6extern "C" {\r
7#endif\r
8\r
9\r
10/*\r
11There are three kinds of slots in the table:\r
12\r
131. Unused: key == NULL\r
142. Active: key != NULL and key != dummy\r
153. Dummy: key == dummy\r
16\r
17Note: .pop() abuses the hash field of an Unused or Dummy slot to\r
18hold a search finger. The hash field of Unused or Dummy slots has\r
19no meaning otherwise.\r
20*/\r
21\r
22#define PySet_MINSIZE 8\r
23\r
24typedef struct {\r
25 long hash; /* cached hash code for the entry key */\r
26 PyObject *key;\r
27} setentry;\r
28\r
29\r
30/*\r
31This data structure is shared by set and frozenset objects.\r
32*/\r
33\r
34typedef struct _setobject PySetObject;\r
35struct _setobject {\r
36 PyObject_HEAD\r
37\r
38 Py_ssize_t fill; /* # Active + # Dummy */\r
39 Py_ssize_t used; /* # Active */\r
40\r
41 /* The table contains mask + 1 slots, and that's a power of 2.\r
42 * We store the mask instead of the size because the mask is more\r
43 * frequently needed.\r
44 */\r
45 Py_ssize_t mask;\r
46\r
47 /* table points to smalltable for small tables, else to\r
48 * additional malloc'ed memory. table is never NULL! This rule\r
49 * saves repeated runtime null-tests.\r
50 */\r
51 setentry *table;\r
52 setentry *(*lookup)(PySetObject *so, PyObject *key, long hash);\r
53 setentry smalltable[PySet_MINSIZE];\r
54\r
55 long hash; /* only used by frozenset objects */\r
56 PyObject *weakreflist; /* List of weak references */\r
57};\r
58\r
59PyAPI_DATA(PyTypeObject) PySet_Type;\r
60PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;\r
61\r
62/* Invariants for frozensets:\r
63 * data is immutable.\r
64 * hash is the hash of the frozenset or -1 if not computed yet.\r
65 * Invariants for sets:\r
66 * hash is -1\r
67 */\r
68\r
69#define PyFrozenSet_CheckExact(ob) (Py_TYPE(ob) == &PyFrozenSet_Type)\r
70#define PyAnySet_CheckExact(ob) \\r
71 (Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type)\r
72#define PyAnySet_Check(ob) \\r
73 (Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type || \\r
74 PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \\r
75 PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))\r
76#define PySet_Check(ob) \\r
77 (Py_TYPE(ob) == &PySet_Type || \\r
78 PyType_IsSubtype(Py_TYPE(ob), &PySet_Type))\r
79#define PyFrozenSet_Check(ob) \\r
80 (Py_TYPE(ob) == &PyFrozenSet_Type || \\r
81 PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))\r
82\r
83PyAPI_FUNC(PyObject *) PySet_New(PyObject *);\r
84PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *);\r
85PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset);\r
86#define PySet_GET_SIZE(so) (((PySetObject *)(so))->used)\r
87PyAPI_FUNC(int) PySet_Clear(PyObject *set);\r
88PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key);\r
89PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key);\r
90PyAPI_FUNC(int) PySet_Add(PyObject *set, PyObject *key);\r
91PyAPI_FUNC(int) _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **key);\r
92PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash);\r
93PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set);\r
94PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);\r
95\r
96#ifdef __cplusplus\r
97}\r
98#endif\r
99#endif /* !Py_SETOBJECT_H */\r