Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_DICTOBJECT_H |
| 2 | #define Py_DICTOBJECT_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Guido van Rossum | 2ec9031 | 1997-05-13 21:23:32 +0000 | [diff] [blame] | 7 | /* Dictionary object type -- mapping from hashable object to object */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 8 | |
Raymond Hettinger | 930427b | 2003-05-03 06:51:59 +0000 | [diff] [blame] | 9 | /* The distribution includes a separate file, Objects/dictnotes.txt, |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 10 | describing explorations into dictionary design and optimization. |
Raymond Hettinger | 930427b | 2003-05-03 06:51:59 +0000 | [diff] [blame] | 11 | It covers typical dictionary use patterns, the parameters for |
| 12 | tuning dictionaries, and several ideas for possible optimizations. |
| 13 | */ |
| 14 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 15 | PyAPI_DATA(PyTypeObject) PyDict_Type; |
Guido van Rossum | 2ec9031 | 1997-05-13 21:23:32 +0000 | [diff] [blame] | 16 | |
Thomas Wouters | 27d517b | 2007-02-25 20:39:11 +0000 | [diff] [blame] | 17 | #define PyDict_Check(op) \ |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 18 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) |
| 19 | #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) |
Guido van Rossum | 2ec9031 | 1997-05-13 21:23:32 +0000 | [diff] [blame] | 20 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 21 | PyAPI_FUNC(PyObject *) PyDict_New(void); |
| 22 | PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key); |
Alexandre Vassalotti | cb31433 | 2008-06-01 03:53:03 +0000 | [diff] [blame] | 23 | PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 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( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 28 | PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 29 | PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp); |
| 30 | PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp); |
| 31 | PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp); |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 32 | PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 33 | PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp); |
Raymond Hettinger | bc0f2ab | 2003-11-25 21:12:14 +0000 | [diff] [blame] | 34 | PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key); |
Jeremy Hylton | a12c7a7 | 2000-03-30 22:27:31 +0000 | [diff] [blame] | 35 | |
Tim Peters | f582b82 | 2001-12-11 18:51:08 +0000 | [diff] [blame] | 36 | /* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 37 | PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other); |
Tim Peters | f582b82 | 2001-12-11 18:51:08 +0000 | [diff] [blame] | 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 | */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 44 | PyAPI_FUNC(int) PyDict_Merge(PyObject *mp, |
Victor Stinner | ffedd9a | 2018-11-27 00:12:26 +0100 | [diff] [blame] | 45 | PyObject *other, |
| 46 | int override); |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 47 | |
Tim Peters | f582b82 | 2001-12-11 18:51:08 +0000 | [diff] [blame] | 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 | */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 53 | PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d, |
Victor Stinner | ffedd9a | 2018-11-27 00:12:26 +0100 | [diff] [blame] | 54 | PyObject *seq2, |
| 55 | int override); |
Guido van Rossum | 2ec9031 | 1997-05-13 21:23:32 +0000 | [diff] [blame] | 56 | |
Martin v. Löwis | 32b4a1b | 2002-12-11 13:21:12 +0000 | [diff] [blame] | 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); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 60 | |
Victor Stinner | ffedd9a | 2018-11-27 00:12:26 +0100 | [diff] [blame] | 61 | /* Dictionary (keys, values, items) views */ |
Victor Stinner | 8ea8650 | 2013-11-08 14:07:11 +0100 | [diff] [blame] | 62 | |
Victor Stinner | ffedd9a | 2018-11-27 00:12:26 +0100 | [diff] [blame] | 63 | PyAPI_DATA(PyTypeObject) PyDictKeys_Type; |
| 64 | PyAPI_DATA(PyTypeObject) PyDictValues_Type; |
| 65 | PyAPI_DATA(PyTypeObject) PyDictItems_Type; |
| 66 | |
| 67 | #define PyDictKeys_Check(op) PyObject_TypeCheck(op, &PyDictKeys_Type) |
| 68 | #define PyDictValues_Check(op) PyObject_TypeCheck(op, &PyDictValues_Type) |
| 69 | #define PyDictItems_Check(op) PyObject_TypeCheck(op, &PyDictItems_Type) |
| 70 | /* This excludes Values, since they are not sets. */ |
| 71 | # define PyDictViewSet_Check(op) \ |
| 72 | (PyDictKeys_Check(op) || PyDictItems_Check(op)) |
| 73 | |
| 74 | /* Dictionary (key, value, items) iterators */ |
| 75 | |
| 76 | PyAPI_DATA(PyTypeObject) PyDictIterKey_Type; |
| 77 | PyAPI_DATA(PyTypeObject) PyDictIterValue_Type; |
| 78 | PyAPI_DATA(PyTypeObject) PyDictIterItem_Type; |
| 79 | |
| 80 | PyAPI_DATA(PyTypeObject) PyDictRevIterKey_Type; |
| 81 | PyAPI_DATA(PyTypeObject) PyDictRevIterItem_Type; |
| 82 | PyAPI_DATA(PyTypeObject) PyDictRevIterValue_Type; |
| 83 | |
| 84 | |
| 85 | #ifndef Py_LIMITED_API |
| 86 | # define Py_CPYTHON_DICTOBJECT_H |
| 87 | # include "cpython/dictobject.h" |
| 88 | # undef Py_CPYTHON_DICTOBJECT_H |
Benjamin Peterson | 7d95e40 | 2012-04-23 11:24:50 -0400 | [diff] [blame] | 89 | #endif |
| 90 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 91 | #ifdef __cplusplus |
| 92 | } |
| 93 | #endif |
| 94 | #endif /* !Py_DICTOBJECT_H */ |