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 | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 7 | |
Guido van Rossum | 2ec9031 | 1997-05-13 21:23:32 +0000 | [diff] [blame] | 8 | /* Dictionary object type -- mapping from hashable object to object */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 9 | |
Raymond Hettinger | 930427b | 2003-05-03 06:51:59 +0000 | [diff] [blame] | 10 | /* The distribution includes a separate file, Objects/dictnotes.txt, |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 11 | describing explorations into dictionary design and optimization. |
Raymond Hettinger | 930427b | 2003-05-03 06:51:59 +0000 | [diff] [blame] | 12 | It covers typical dictionary use patterns, the parameters for |
| 13 | tuning dictionaries, and several ideas for possible optimizations. |
| 14 | */ |
| 15 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 16 | #ifndef Py_LIMITED_API |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 17 | |
Benjamin Peterson | 7d95e40 | 2012-04-23 11:24:50 -0400 | [diff] [blame] | 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 | */ |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 23 | typedef struct { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 24 | PyObject_HEAD |
Benjamin Peterson | 7d95e40 | 2012-04-23 11:24:50 -0400 | [diff] [blame] | 25 | Py_ssize_t ma_used; |
| 26 | PyDictKeysObject *ma_keys; |
| 27 | PyObject **ma_values; |
| 28 | } PyDictObject; |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 29 | |
Eric Snow | 96c6af9 | 2015-05-29 22:21:39 -0600 | [diff] [blame] | 30 | typedef struct { |
| 31 | PyObject_HEAD |
| 32 | PyDictObject *dv_dict; |
| 33 | } _PyDictViewObject; |
| 34 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 35 | #endif /* Py_LIMITED_API */ |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 36 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 37 | PyAPI_DATA(PyTypeObject) PyDict_Type; |
Christian Heimes | a22e8bd | 2007-11-29 22:35:39 +0000 | [diff] [blame] | 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; |
Guido van Rossum | 2ec9031 | 1997-05-13 21:23:32 +0000 | [diff] [blame] | 44 | |
Thomas Wouters | 27d517b | 2007-02-25 20:39:11 +0000 | [diff] [blame] | 45 | #define PyDict_Check(op) \ |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 46 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) |
| 47 | #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) |
Eric Snow | 8c7ed01 | 2015-05-30 09:29:53 -0600 | [diff] [blame] | 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) |
Christian Heimes | a22e8bd | 2007-11-29 22:35:39 +0000 | [diff] [blame] | 51 | /* This excludes Values, since they are not sets. */ |
| 52 | # define PyDictViewSet_Check(op) \ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 53 | (PyDictKeys_Check(op) || PyDictItems_Check(op)) |
Christian Heimes | a22e8bd | 2007-11-29 22:35:39 +0000 | [diff] [blame] | 54 | |
Guido van Rossum | 2ec9031 | 1997-05-13 21:23:32 +0000 | [diff] [blame] | 55 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 56 | PyAPI_FUNC(PyObject *) PyDict_New(void); |
| 57 | PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key); |
Benjamin Peterson | 39992d3 | 2014-05-03 19:39:15 -0400 | [diff] [blame] | 58 | #ifndef Py_LIMITED_API |
Raymond Hettinger | 4b74fba | 2014-05-03 16:32:11 -0700 | [diff] [blame] | 59 | PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key, |
| 60 | Py_hash_t hash); |
Benjamin Peterson | 39992d3 | 2014-05-03 19:39:15 -0400 | [diff] [blame] | 61 | #endif |
Alexandre Vassalotti | cb31433 | 2008-06-01 03:53:03 +0000 | [diff] [blame] | 62 | PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key); |
Brett Cannon | fd07415 | 2012-04-14 14:10:13 -0400 | [diff] [blame] | 63 | PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, |
| 64 | struct _Py_Identifier *key); |
Martin v. Löwis | 1c0689c | 2014-01-03 21:36:49 +0100 | [diff] [blame] | 65 | #ifndef Py_LIMITED_API |
Benjamin Peterson | 00e9886 | 2013-03-07 22:16:29 -0500 | [diff] [blame] | 66 | PyAPI_FUNC(PyObject *) PyDict_SetDefault( |
| 67 | PyObject *mp, PyObject *key, PyObject *defaultobj); |
Martin v. Löwis | 1c0689c | 2014-01-03 21:36:49 +0100 | [diff] [blame] | 68 | #endif |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 69 | PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item); |
Benjamin Peterson | 39992d3 | 2014-05-03 19:39:15 -0400 | [diff] [blame] | 70 | #ifndef Py_LIMITED_API |
Raymond Hettinger | 4b74fba | 2014-05-03 16:32:11 -0700 | [diff] [blame] | 71 | PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key, |
| 72 | PyObject *item, Py_hash_t hash); |
Benjamin Peterson | 39992d3 | 2014-05-03 19:39:15 -0400 | [diff] [blame] | 73 | #endif |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 74 | PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key); |
Serhiy Storchaka | b9d98d5 | 2015-10-02 12:47:11 +0300 | [diff] [blame] | 75 | #ifndef Py_LIMITED_API |
| 76 | PyAPI_FUNC(int) _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key, |
| 77 | Py_hash_t hash); |
| 78 | #endif |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 79 | PyAPI_FUNC(void) PyDict_Clear(PyObject *mp); |
| 80 | PyAPI_FUNC(int) PyDict_Next( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 81 | PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 82 | #ifndef Py_LIMITED_API |
Benjamin Peterson | 7d95e40 | 2012-04-23 11:24:50 -0400 | [diff] [blame] | 83 | PyDictKeysObject *_PyDict_NewKeysForClass(void); |
| 84 | PyAPI_FUNC(PyObject *) PyObject_GenericGetDict(PyObject *, void *); |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 85 | PyAPI_FUNC(int) _PyDict_Next( |
Benjamin Peterson | 8f67d08 | 2010-10-17 20:54:53 +0000 | [diff] [blame] | 86 | PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash); |
Eric Snow | 96c6af9 | 2015-05-29 22:21:39 -0600 | [diff] [blame] | 87 | PyObject *_PyDictView_New(PyObject *, PyTypeObject *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 88 | #endif |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 89 | PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp); |
| 90 | PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp); |
| 91 | PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp); |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 92 | PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 93 | PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp); |
Raymond Hettinger | bc0f2ab | 2003-11-25 21:12:14 +0000 | [diff] [blame] | 94 | PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 95 | #ifndef Py_LIMITED_API |
Benjamin Peterson | 8f67d08 | 2010-10-17 20:54:53 +0000 | [diff] [blame] | 96 | PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash); |
Christian Heimes | 99170a5 | 2007-12-19 02:07:34 +0000 | [diff] [blame] | 97 | PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused); |
Antoine Pitrou | 3a652b1 | 2009-03-23 18:52:06 +0000 | [diff] [blame] | 98 | PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp); |
Benjamin Peterson | fb88636 | 2010-04-24 18:21:17 +0000 | [diff] [blame] | 99 | PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp); |
Martin v. Loewis | 4f2f3b6 | 2012-04-24 19:13:57 +0200 | [diff] [blame] | 100 | Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys); |
Serhiy Storchaka | 0ce7a3a | 2015-12-22 08:16:18 +0200 | [diff] [blame] | 101 | Py_ssize_t _PyDict_SizeOf(PyDictObject *); |
Eric Snow | 96c6af9 | 2015-05-29 22:21:39 -0600 | [diff] [blame] | 102 | PyObject *_PyDict_Pop(PyDictObject *, PyObject *, PyObject *); |
| 103 | PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *); |
Benjamin Peterson | 7d95e40 | 2012-04-23 11:24:50 -0400 | [diff] [blame] | 104 | #define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL) |
Antoine Pitrou | 9a812cb | 2011-11-15 00:00:12 +0100 | [diff] [blame] | 105 | |
| 106 | PyAPI_FUNC(int) PyDict_ClearFreeList(void); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 107 | #endif |
Jeremy Hylton | a12c7a7 | 2000-03-30 22:27:31 +0000 | [diff] [blame] | 108 | |
Tim Peters | f582b82 | 2001-12-11 18:51:08 +0000 | [diff] [blame] | 109 | /* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 110 | PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other); |
Tim Peters | f582b82 | 2001-12-11 18:51:08 +0000 | [diff] [blame] | 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 | */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 117 | PyAPI_FUNC(int) PyDict_Merge(PyObject *mp, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 118 | PyObject *other, |
| 119 | int override); |
Tim Peters | f582b82 | 2001-12-11 18:51:08 +0000 | [diff] [blame] | 120 | |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 121 | #ifndef Py_LIMITED_API |
| 122 | PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other); |
| 123 | #endif |
| 124 | |
Tim Peters | f582b82 | 2001-12-11 18:51:08 +0000 | [diff] [blame] | 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 | */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 130 | PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 131 | PyObject *seq2, |
| 132 | int override); |
Guido van Rossum | 2ec9031 | 1997-05-13 21:23:32 +0000 | [diff] [blame] | 133 | |
Martin v. Löwis | 32b4a1b | 2002-12-11 13:21:12 +0000 | [diff] [blame] | 134 | PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key); |
Victor Stinner | 3c1e481 | 2012-03-26 22:10:51 +0200 | [diff] [blame] | 135 | PyAPI_FUNC(PyObject *) _PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *key); |
Martin v. Löwis | 32b4a1b | 2002-12-11 13:21:12 +0000 | [diff] [blame] | 136 | PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item); |
Victor Stinner | 3c1e481 | 2012-03-26 22:10:51 +0200 | [diff] [blame] | 137 | PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item); |
Martin v. Löwis | 32b4a1b | 2002-12-11 13:21:12 +0000 | [diff] [blame] | 138 | PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 139 | |
Benjamin Peterson | 7d95e40 | 2012-04-23 11:24:50 -0400 | [diff] [blame] | 140 | #ifndef Py_LIMITED_API |
Victor Stinner | 8ea8650 | 2013-11-08 14:07:11 +0100 | [diff] [blame] | 141 | PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key); |
| 142 | PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out); |
| 143 | |
Benjamin Peterson | 7d95e40 | 2012-04-23 11:24:50 -0400 | [diff] [blame] | 144 | int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value); |
| 145 | PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *); |
| 146 | #endif |
| 147 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 148 | #ifdef __cplusplus |
| 149 | } |
| 150 | #endif |
| 151 | #endif /* !Py_DICTOBJECT_H */ |