blob: f67c3214ddd9ab2d16198ec60e2cced1d88048fb [file] [log] [blame]
Victor Stinnerffedd9a2018-11-27 00:12:26 +01001#ifndef Py_CPYTHON_DICTOBJECT_H
2# error "this header file must not be included directly"
3#endif
4
Victor Stinnerffedd9a2018-11-27 00:12:26 +01005typedef struct _dictkeysobject PyDictKeysObject;
6
7/* The ma_values pointer is NULL for a combined table
8 * or points to an array of PyObject* for a split table
9 */
10typedef struct {
11 PyObject_HEAD
12
13 /* Number of items in the dictionary */
14 Py_ssize_t ma_used;
15
16 /* Dictionary version: globally unique, value change each time
17 the dictionary is modified */
18 uint64_t ma_version_tag;
19
20 PyDictKeysObject *ma_keys;
21
22 /* If ma_values is NULL, the table is "combined": keys and values
23 are stored in ma_keys.
24
25 If ma_values is not NULL, the table is splitted:
26 keys are stored in ma_keys and values are stored in ma_values */
27 PyObject **ma_values;
28} PyDictObject;
29
30PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
31 Py_hash_t hash);
32PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,
33 struct _Py_Identifier *key);
Serhiy Storchakaa24107b2019-02-25 17:59:46 +020034PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *);
Victor Stinnerffedd9a2018-11-27 00:12:26 +010035PyAPI_FUNC(PyObject *) PyDict_SetDefault(
36 PyObject *mp, PyObject *key, PyObject *defaultobj);
37PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key,
38 PyObject *item, Py_hash_t hash);
39PyAPI_FUNC(int) _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key,
40 Py_hash_t hash);
41PyAPI_FUNC(int) _PyDict_DelItemIf(PyObject *mp, PyObject *key,
42 int (*predicate)(PyObject *value));
43PyDictKeysObject *_PyDict_NewKeysForClass(void);
Victor Stinnerffedd9a2018-11-27 00:12:26 +010044PyAPI_FUNC(int) _PyDict_Next(
45 PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
46
47/* Get the number of items of a dictionary. */
48#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used)
49PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash);
50PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
51PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
52PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
53Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys);
54PyAPI_FUNC(Py_ssize_t) _PyDict_SizeOf(PyDictObject *);
55PyAPI_FUNC(PyObject *) _PyDict_Pop(PyObject *, PyObject *, PyObject *);
56PyObject *_PyDict_Pop_KnownHash(PyObject *, PyObject *, Py_hash_t, PyObject *);
57PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
58#define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL)
59
Victor Stinnerffedd9a2018-11-27 00:12:26 +010060/* Like PyDict_Merge, but override can be 0, 1 or 2. If override is 0,
61 the first occurrence of a key wins, if override is 1, the last occurrence
62 of a key wins, if override is 2, a KeyError with conflicting key as
63 argument is raised.
64*/
65PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
66PyAPI_FUNC(PyObject *) _PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *key);
67PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item);
68
69PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key);
70PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out);
71
72int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);
73PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
Pablo Galindo109826c2020-10-20 06:22:44 +010074Py_ssize_t _PyDict_GetItemHint(PyDictObject *, PyObject *, Py_ssize_t, PyObject **);
Victor Stinnerffedd9a2018-11-27 00:12:26 +010075
76/* _PyDictView */
77
78typedef struct {
79 PyObject_HEAD
80 PyDictObject *dv_dict;
81} _PyDictViewObject;
82
83PyAPI_FUNC(PyObject *) _PyDictView_New(PyObject *, PyTypeObject *);
84PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other);