File: /Users/paulross/dev/Python-3.6.2/Include/dictobject.h

Green shading in the line number column means the source is part of the translation unit, red means it is conditionally excluded. Highlighted line numbers link to the translation unit page. Highlighted macros link to the macro page.

       1: #ifndef Py_DICTOBJECT_H
       2: #define Py_DICTOBJECT_H
       3: #ifdef __cplusplus
       4: extern "C" {
       5: #endif
       6: 
       7: 
       8: /* Dictionary object type -- mapping from hashable object to object */
       9: 
      10: /* The distribution includes a separate file, Objects/dictnotes.txt,
      11:    describing explorations into dictionary design and optimization.
      12:    It covers typical dictionary use patterns, the parameters for
      13:    tuning dictionaries, and several ideas for possible optimizations.
      14: */
      15: 
      16: #ifndef Py_LIMITED_API
      17: 
      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:  */
      23: typedef struct {
      24:     PyObject_HEAD
      25: 
      26:     /* Number of items in the dictionary */
      27:     Py_ssize_t ma_used;
      28: 
      29:     /* Dictionary version: globally unique, value change each time
      30:        the dictionary is modified */
      31:     uint64_t ma_version_tag;
      32: 
      33:     PyDictKeysObject *ma_keys;
      34: 
      35:     /* If ma_values is NULL, the table is "combined": keys and values
      36:        are stored in ma_keys.
      37: 
      38:        If ma_values is not NULL, the table is splitted:
      39:        keys are stored in ma_keys and values are stored in ma_values */
      40:     PyObject **ma_values;
      41: } PyDictObject;
      42: 
      43: typedef struct {
      44:     PyObject_HEAD
      45:     PyDictObject *dv_dict;
      46: } _PyDictViewObject;
      47: 
      48: #endif /* Py_LIMITED_API */
      49: 
      50: PyAPI_DATA(PyTypeObject) PyDict_Type;
      51: PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;
      52: PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;
      53: PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;
      54: PyAPI_DATA(PyTypeObject) PyDictKeys_Type;
      55: PyAPI_DATA(PyTypeObject) PyDictItems_Type;
      56: PyAPI_DATA(PyTypeObject) PyDictValues_Type;
      57: 
      58: #define PyDict_Check(op) \
      59:                  PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
      60: #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
      61: #define PyDictKeys_Check(op) PyObject_TypeCheck(op, &PyDictKeys_Type)
      62: #define PyDictItems_Check(op) PyObject_TypeCheck(op, &PyDictItems_Type)
      63: #define PyDictValues_Check(op) PyObject_TypeCheck(op, &PyDictValues_Type)
      64: /* This excludes Values, since they are not sets. */
      65: # define PyDictViewSet_Check(op) \
      66:     (PyDictKeys_Check(op) || PyDictItems_Check(op))
      67: 
      68: 
      69: PyAPI_FUNC(PyObject *) PyDict_New(void);
      70: PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
      71: #ifndef Py_LIMITED_API
      72: PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
      73:                                        Py_hash_t hash);
      74: #endif
      75: PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key);
      76: #ifndef Py_LIMITED_API
      77: PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,
      78:                                                   struct _Py_Identifier *key);
      79: PyAPI_FUNC(PyObject *) PyDict_SetDefault(
      80:     PyObject *mp, PyObject *key, PyObject *defaultobj);
      81: #endif
      82: PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item);
      83: #ifndef Py_LIMITED_API
      84: PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key,
      85:                                           PyObject *item, Py_hash_t hash);
      86: #endif
      87: PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key);
      88: #ifndef Py_LIMITED_API
      89: PyAPI_FUNC(int) _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key,
      90:                                           Py_hash_t hash);
      91: PyAPI_FUNC(int) _PyDict_DelItemIf(PyObject *mp, PyObject *key,
      92:                                   int (*predicate)(PyObject *value));
      93: #endif
      94: PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);
      95: PyAPI_FUNC(int) PyDict_Next(
      96:     PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);
      97: #ifndef Py_LIMITED_API
      98: PyDictKeysObject *_PyDict_NewKeysForClass(void);
      99: PyAPI_FUNC(PyObject *) PyObject_GenericGetDict(PyObject *, void *);
     100: PyAPI_FUNC(int) _PyDict_Next(
     101:     PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
     102: PyObject *_PyDictView_New(PyObject *, PyTypeObject *);
     103: #endif
     104: PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);
     105: PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);
     106: PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);
     107: PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp);
     108: PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp);
     109: PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key);
     110: #ifndef Py_LIMITED_API
     111: PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash);
     112: PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
     113: PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
     114: PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
     115: Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys);
     116: Py_ssize_t _PyDict_SizeOf(PyDictObject *);
     117: PyAPI_FUNC(PyObject *) _PyDict_Pop(PyObject *, PyObject *, PyObject *);
     118: PyObject *_PyDict_Pop_KnownHash(PyObject *, PyObject *, Py_hash_t, PyObject *);
     119: PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
     120: #define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL)
     121: 
     122: PyAPI_FUNC(int) PyDict_ClearFreeList(void);
     123: #endif
     124: 
     125: /* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */
     126: PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other);
     127: 
     128: /* PyDict_Merge updates/merges from a mapping object (an object that
     129:    supports PyMapping_Keys() and PyObject_GetItem()).  If override is true,
     130:    the last occurrence of a key wins, else the first.  The Python
     131:    dict.update(other) is equivalent to PyDict_Merge(dict, other, 1).
     132: */
     133: PyAPI_FUNC(int) PyDict_Merge(PyObject *mp,
     134:                                    PyObject *other,
     135:                                    int override);
     136: 
     137: #ifndef Py_LIMITED_API
     138: /* Like PyDict_Merge, but override can be 0, 1 or 2.  If override is 0,
     139:    the first occurrence of a key wins, if override is 1, the last occurrence
     140:    of a key wins, if override is 2, a KeyError with conflicting key as
     141:    argument is raised.
     142: */
     143: PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
     144: PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other);
     145: #endif
     146: 
     147: /* PyDict_MergeFromSeq2 updates/merges from an iterable object producing
     148:    iterable objects of length 2.  If override is true, the last occurrence
     149:    of a key wins, else the first.  The Python dict constructor dict(seq2)
     150:    is equivalent to dict={}; PyDict_MergeFromSeq(dict, seq2, 1).
     151: */
     152: PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d,
     153:                                            PyObject *seq2,
     154:                                            int override);
     155: 
     156: PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key);
     157: #ifndef Py_LIMITED_API
     158: PyAPI_FUNC(PyObject *) _PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *key);
     159: #endif /* !Py_LIMITED_API */
     160: PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);
     161: #ifndef Py_LIMITED_API
     162: PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item);
     163: #endif /* !Py_LIMITED_API */
     164: PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key);
     165: 
     166: #ifndef Py_LIMITED_API
     167: PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key);
     168: PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out);
     169: 
     170: int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);
     171: PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
     172: #endif
     173: 
     174: #ifdef __cplusplus
     175: }
     176: #endif
     177: #endif /* !Py_DICTOBJECT_H */
     178: