|
||||
File indexing completed on 2025-01-30 10:18:04
0001 #ifndef Py_CPYTHON_SETOBJECT_H 0002 # error "this header file must not be included directly" 0003 #endif 0004 0005 /* There are three kinds of entries in the table: 0006 0007 1. Unused: key == NULL and hash == 0 0008 2. Dummy: key == dummy and hash == -1 0009 3. Active: key != NULL and key != dummy and hash != -1 0010 0011 The hash field of Unused slots is always zero. 0012 0013 The hash field of Dummy slots are set to -1 0014 meaning that dummy entries can be detected by 0015 either entry->key==dummy or by entry->hash==-1. 0016 */ 0017 0018 #define PySet_MINSIZE 8 0019 0020 typedef struct { 0021 PyObject *key; 0022 Py_hash_t hash; /* Cached hash code of the key */ 0023 } setentry; 0024 0025 /* The SetObject data structure is shared by set and frozenset objects. 0026 0027 Invariant for sets: 0028 - hash is -1 0029 0030 Invariants for frozensets: 0031 - data is immutable. 0032 - hash is the hash of the frozenset or -1 if not computed yet. 0033 0034 */ 0035 0036 typedef struct { 0037 PyObject_HEAD 0038 0039 Py_ssize_t fill; /* Number active and dummy entries*/ 0040 Py_ssize_t used; /* Number active entries */ 0041 0042 /* The table contains mask + 1 slots, and that's a power of 2. 0043 * We store the mask instead of the size because the mask is more 0044 * frequently needed. 0045 */ 0046 Py_ssize_t mask; 0047 0048 /* The table points to a fixed-size smalltable for small tables 0049 * or to additional malloc'ed memory for bigger tables. 0050 * The table pointer is never NULL which saves us from repeated 0051 * runtime null-tests. 0052 */ 0053 setentry *table; 0054 Py_hash_t hash; /* Only used by frozenset objects */ 0055 Py_ssize_t finger; /* Search finger for pop() */ 0056 0057 setentry smalltable[PySet_MINSIZE]; 0058 PyObject *weakreflist; /* List of weak references */ 0059 } PySetObject; 0060 0061 #define _PySet_CAST(so) \ 0062 (assert(PyAnySet_Check(so)), _Py_CAST(PySetObject*, so)) 0063 0064 static inline Py_ssize_t PySet_GET_SIZE(PyObject *so) { 0065 return _PySet_CAST(so)->used; 0066 } 0067 #define PySet_GET_SIZE(so) PySet_GET_SIZE(_PyObject_CAST(so)) 0068 0069 PyAPI_DATA(PyObject *) _PySet_Dummy; 0070 0071 PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash); 0072 PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |