| 1 | #ifndef Py_DICTOBJECT_H |
| 2 | #define Py_DICTOBJECT_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
| 7 | |
| 8 | /* Dictionary object type -- mapping from hashable object to object */ |
| 9 | |
| 10 | /* The distribution includes a separate file, Objects/dictnotes.txt, |
| 11 | describing explorations into dictionary design and optimization. |
| 12 | It covers typical dictionary use patterns, the parameters for |
| 13 | tuning dictionaries, and several ideas for possible optimizations. |
| 14 | */ |
| 15 | |
| 16 | #ifndef Py_LIMITED_API |
| 17 | |
| 18 | typedef struct _dictkeysobject PyDictKeysObject; |
| 19 | |
| 20 | /* The ma_values pointer is NULL for a combined table |
| 21 | * or points to an array of PyObject* for a split table |
| 22 | */ |
| 23 | typedef struct { |
| 24 | PyObject_HEAD |
| 25 | Py_ssize_t ma_used; |
| 26 | PyDictKeysObject *ma_keys; |
| 27 | PyObject **ma_values; |
| 28 | } PyDictObject; |
| 29 | |
| 30 | typedef struct { |
| 31 | PyObject_HEAD |
| 32 | PyDictObject *dv_dict; |
| 33 | } _PyDictViewObject; |
| 34 | |
| 35 | #endif /* Py_LIMITED_API */ |
| 36 | |
| 37 | PyAPI_DATA(PyTypeObject) PyDict_Type; |
| 38 | PyAPI_DATA(PyTypeObject) PyDictIterKey_Type; |
| 39 | PyAPI_DATA(PyTypeObject) PyDictIterValue_Type; |
| 40 | PyAPI_DATA(PyTypeObject) PyDictIterItem_Type; |
| 41 | PyAPI_DATA(PyTypeObject) PyDictKeys_Type; |
| 42 | PyAPI_DATA(PyTypeObject) PyDictItems_Type; |
| 43 | PyAPI_DATA(PyTypeObject) PyDictValues_Type; |
| 44 | |
| 45 | #define PyDict_Check(op) \ |
| 46 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) |
| 47 | #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) |
| 48 | #define PyDictKeys_Check(op) PyObject_TypeCheck(op, &PyDictKeys_Type) |
| 49 | #define PyDictItems_Check(op) PyObject_TypeCheck(op, &PyDictItems_Type) |
| 50 | #define PyDictValues_Check(op) PyObject_TypeCheck(op, &PyDictValues_Type) |
| 51 | /* This excludes Values, since they are not sets. */ |
| 52 | # define PyDictViewSet_Check(op) \ |
| 53 | (PyDictKeys_Check(op) || PyDictItems_Check(op)) |
| 54 | |
| 55 | |
| 56 | PyAPI_FUNC(PyObject *) PyDict_New(void); |
| 57 | PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key); |
| 58 | #ifndef Py_LIMITED_API |
| 59 | PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key, |
| 60 | Py_hash_t hash); |
| 61 | #endif |
| 62 | PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key); |
| 63 | PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, |
| 64 | struct _Py_Identifier *key); |
| 65 | #ifndef Py_LIMITED_API |
| 66 | PyAPI_FUNC(PyObject *) PyDict_SetDefault( |
| 67 | PyObject *mp, PyObject *key, PyObject *defaultobj); |
| 68 | #endif |
| 69 | PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item); |
| 70 | #ifndef Py_LIMITED_API |
| 71 | PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key, |
| 72 | PyObject *item, Py_hash_t hash); |
| 73 | #endif |
| 74 | PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key); |
| 75 | #ifndef Py_LIMITED_API |
| 76 | PyAPI_FUNC(int) _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key, |
| 77 | Py_hash_t hash); |
| 78 | #endif |
| 79 | PyAPI_FUNC(void) PyDict_Clear(PyObject *mp); |
| 80 | PyAPI_FUNC(int) PyDict_Next( |
| 81 | PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value); |
| 82 | #ifndef Py_LIMITED_API |
| 83 | PyDictKeysObject *_PyDict_NewKeysForClass(void); |
| 84 | PyAPI_FUNC(PyObject *) PyObject_GenericGetDict(PyObject *, void *); |
| 85 | PyAPI_FUNC(int) _PyDict_Next( |
| 86 | PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash); |
| 87 | PyObject *_PyDictView_New(PyObject *, PyTypeObject *); |
| 88 | #endif |
| 89 | PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp); |
| 90 | PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp); |
| 91 | PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp); |
| 92 | PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp); |
| 93 | PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp); |
| 94 | PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key); |
| 95 | #ifndef Py_LIMITED_API |
| 96 | PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash); |
| 97 | PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused); |
| 98 | PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp); |
| 99 | PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp); |
| 100 | Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys); |
| 101 | Py_ssize_t _PyDict_SizeOf(PyDictObject *); |
| 102 | PyObject *_PyDict_Pop(PyDictObject *, PyObject *, PyObject *); |
| 103 | PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *); |
| 104 | #define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL) |
| 105 | |
| 106 | PyAPI_FUNC(int) PyDict_ClearFreeList(void); |
| 107 | #endif |
| 108 | |
| 109 | /* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */ |
| 110 | PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other); |
| 111 | |
| 112 | /* PyDict_Merge updates/merges from a mapping object (an object that |
| 113 | supports PyMapping_Keys() and PyObject_GetItem()). If override is true, |
| 114 | the last occurrence of a key wins, else the first. The Python |
| 115 | dict.update(other) is equivalent to PyDict_Merge(dict, other, 1). |
| 116 | */ |
| 117 | PyAPI_FUNC(int) PyDict_Merge(PyObject *mp, |
| 118 | PyObject *other, |
| 119 | int override); |
| 120 | |
| 121 | #ifndef Py_LIMITED_API |
| 122 | PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other); |
| 123 | #endif |
| 124 | |
| 125 | /* PyDict_MergeFromSeq2 updates/merges from an iterable object producing |
| 126 | iterable objects of length 2. If override is true, the last occurrence |
| 127 | of a key wins, else the first. The Python dict constructor dict(seq2) |
| 128 | is equivalent to dict={}; PyDict_MergeFromSeq(dict, seq2, 1). |
| 129 | */ |
| 130 | PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d, |
| 131 | PyObject *seq2, |
| 132 | int override); |
| 133 | |
| 134 | PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key); |
| 135 | PyAPI_FUNC(PyObject *) _PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *key); |
| 136 | PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item); |
| 137 | PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item); |
| 138 | PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key); |
| 139 | |
| 140 | #ifndef Py_LIMITED_API |
| 141 | PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key); |
| 142 | PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out); |
| 143 | |
| 144 | int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value); |
| 145 | PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *); |
| 146 | #endif |
| 147 | |
| 148 | #ifdef __cplusplus |
| 149 | } |
| 150 | #endif |
| 151 | #endif /* !Py_DICTOBJECT_H */ |
| 152 | |