• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef Py_DICTOBJECT_H
2 #define Py_DICTOBJECT_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 /* Dictionary object type -- mapping from hashable object to object */
8 
9 /* The distribution includes a separate file, Objects/dictnotes.txt,
10    describing explorations into dictionary design and optimization.
11    It covers typical dictionary use patterns, the parameters for
12    tuning dictionaries, and several ideas for possible optimizations.
13 */
14 
15 PyAPI_DATA(PyTypeObject) PyDict_Type;
16 
17 #define PyDict_Check(op) \
18                  PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
19 #define PyDict_CheckExact(op) Py_IS_TYPE((op), &PyDict_Type)
20 
21 PyAPI_FUNC(PyObject *) PyDict_New(void);
22 PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
23 PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key);
24 PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item);
25 PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key);
26 PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);
27 PyAPI_FUNC(int) PyDict_Next(
28     PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);
29 PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);
30 PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);
31 PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);
32 PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp);
33 PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp);
34 PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key);
35 
36 /* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */
37 PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other);
38 
39 /* PyDict_Merge updates/merges from a mapping object (an object that
40    supports PyMapping_Keys() and PyObject_GetItem()).  If override is true,
41    the last occurrence of a key wins, else the first.  The Python
42    dict.update(other) is equivalent to PyDict_Merge(dict, other, 1).
43 */
44 PyAPI_FUNC(int) PyDict_Merge(PyObject *mp,
45                              PyObject *other,
46                              int override);
47 
48 /* PyDict_MergeFromSeq2 updates/merges from an iterable object producing
49    iterable objects of length 2.  If override is true, the last occurrence
50    of a key wins, else the first.  The Python dict constructor dict(seq2)
51    is equivalent to dict={}; PyDict_MergeFromSeq(dict, seq2, 1).
52 */
53 PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d,
54                                      PyObject *seq2,
55                                      int override);
56 
57 PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key);
58 PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);
59 PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key);
60 
61 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030D0000
62 // Return the object from dictionary *op* which has a key *key*.
63 // - If the key is present, set *result to a new strong reference to the value
64 //   and return 1.
65 // - If the key is missing, set *result to NULL and return 0 .
66 // - On error, raise an exception and return -1.
67 PyAPI_FUNC(int) PyDict_GetItemRef(PyObject *mp, PyObject *key, PyObject **result);
68 PyAPI_FUNC(int) PyDict_GetItemStringRef(PyObject *mp, const char *key, PyObject **result);
69 #endif
70 
71 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
72 PyAPI_FUNC(PyObject *) PyObject_GenericGetDict(PyObject *, void *);
73 #endif
74 
75 /* Dictionary (keys, values, items) views */
76 
77 PyAPI_DATA(PyTypeObject) PyDictKeys_Type;
78 PyAPI_DATA(PyTypeObject) PyDictValues_Type;
79 PyAPI_DATA(PyTypeObject) PyDictItems_Type;
80 
81 #define PyDictKeys_Check(op) PyObject_TypeCheck((op), &PyDictKeys_Type)
82 #define PyDictValues_Check(op) PyObject_TypeCheck((op), &PyDictValues_Type)
83 #define PyDictItems_Check(op) PyObject_TypeCheck((op), &PyDictItems_Type)
84 /* This excludes Values, since they are not sets. */
85 # define PyDictViewSet_Check(op) \
86     (PyDictKeys_Check(op) || PyDictItems_Check(op))
87 
88 /* Dictionary (key, value, items) iterators */
89 
90 PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;
91 PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;
92 PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;
93 
94 PyAPI_DATA(PyTypeObject) PyDictRevIterKey_Type;
95 PyAPI_DATA(PyTypeObject) PyDictRevIterItem_Type;
96 PyAPI_DATA(PyTypeObject) PyDictRevIterValue_Type;
97 
98 
99 #ifndef Py_LIMITED_API
100 #  define Py_CPYTHON_DICTOBJECT_H
101 #  include "cpython/dictobject.h"
102 #  undef Py_CPYTHON_DICTOBJECT_H
103 #endif
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 #endif /* !Py_DICTOBJECT_H */
109