jpayne@69: #ifndef Py_DICTOBJECT_H jpayne@69: #define Py_DICTOBJECT_H jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: /* Dictionary object type -- mapping from hashable object to object */ jpayne@69: jpayne@69: /* The distribution includes a separate file, Objects/dictnotes.txt, jpayne@69: describing explorations into dictionary design and optimization. jpayne@69: It covers typical dictionary use patterns, the parameters for jpayne@69: tuning dictionaries, and several ideas for possible optimizations. jpayne@69: */ jpayne@69: jpayne@69: PyAPI_DATA(PyTypeObject) PyDict_Type; jpayne@69: jpayne@69: #define PyDict_Check(op) \ jpayne@69: PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) jpayne@69: #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) jpayne@69: jpayne@69: PyAPI_FUNC(PyObject *) PyDict_New(void); jpayne@69: PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key); jpayne@69: PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key); jpayne@69: PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item); jpayne@69: PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key); jpayne@69: PyAPI_FUNC(void) PyDict_Clear(PyObject *mp); jpayne@69: PyAPI_FUNC(int) PyDict_Next( jpayne@69: PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value); jpayne@69: PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp); jpayne@69: PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp); jpayne@69: PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp); jpayne@69: PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp); jpayne@69: PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp); jpayne@69: PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key); jpayne@69: jpayne@69: /* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */ jpayne@69: PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other); jpayne@69: jpayne@69: /* PyDict_Merge updates/merges from a mapping object (an object that jpayne@69: supports PyMapping_Keys() and PyObject_GetItem()). If override is true, jpayne@69: the last occurrence of a key wins, else the first. The Python jpayne@69: dict.update(other) is equivalent to PyDict_Merge(dict, other, 1). jpayne@69: */ jpayne@69: PyAPI_FUNC(int) PyDict_Merge(PyObject *mp, jpayne@69: PyObject *other, jpayne@69: int override); jpayne@69: jpayne@69: /* PyDict_MergeFromSeq2 updates/merges from an iterable object producing jpayne@69: iterable objects of length 2. If override is true, the last occurrence jpayne@69: of a key wins, else the first. The Python dict constructor dict(seq2) jpayne@69: is equivalent to dict={}; PyDict_MergeFromSeq(dict, seq2, 1). jpayne@69: */ jpayne@69: PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d, jpayne@69: PyObject *seq2, jpayne@69: int override); jpayne@69: jpayne@69: PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key); jpayne@69: PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item); jpayne@69: PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key); jpayne@69: jpayne@69: /* Dictionary (keys, values, items) views */ jpayne@69: jpayne@69: PyAPI_DATA(PyTypeObject) PyDictKeys_Type; jpayne@69: PyAPI_DATA(PyTypeObject) PyDictValues_Type; jpayne@69: PyAPI_DATA(PyTypeObject) PyDictItems_Type; jpayne@69: jpayne@69: #define PyDictKeys_Check(op) PyObject_TypeCheck(op, &PyDictKeys_Type) jpayne@69: #define PyDictValues_Check(op) PyObject_TypeCheck(op, &PyDictValues_Type) jpayne@69: #define PyDictItems_Check(op) PyObject_TypeCheck(op, &PyDictItems_Type) jpayne@69: /* This excludes Values, since they are not sets. */ jpayne@69: # define PyDictViewSet_Check(op) \ jpayne@69: (PyDictKeys_Check(op) || PyDictItems_Check(op)) jpayne@69: jpayne@69: /* Dictionary (key, value, items) iterators */ jpayne@69: jpayne@69: PyAPI_DATA(PyTypeObject) PyDictIterKey_Type; jpayne@69: PyAPI_DATA(PyTypeObject) PyDictIterValue_Type; jpayne@69: PyAPI_DATA(PyTypeObject) PyDictIterItem_Type; jpayne@69: jpayne@69: PyAPI_DATA(PyTypeObject) PyDictRevIterKey_Type; jpayne@69: PyAPI_DATA(PyTypeObject) PyDictRevIterItem_Type; jpayne@69: PyAPI_DATA(PyTypeObject) PyDictRevIterValue_Type; jpayne@69: jpayne@69: jpayne@69: #ifndef Py_LIMITED_API jpayne@69: # define Py_CPYTHON_DICTOBJECT_H jpayne@69: # include "cpython/dictobject.h" jpayne@69: # undef Py_CPYTHON_DICTOBJECT_H jpayne@69: #endif jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: #endif /* !Py_DICTOBJECT_H */