dictobject.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef Py_DICTOBJECT_H
  2. #define Py_DICTOBJECT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Dictionary object type -- mapping from hashable object to object */
  7. /* The distribution includes a separate file, Objects/dictnotes.txt,
  8. describing explorations into dictionary design and optimization.
  9. It covers typical dictionary use patterns, the parameters for
  10. tuning dictionaries, and several ideas for possible optimizations.
  11. */
  12. PyAPI_DATA(PyTypeObject) PyDict_Type;
  13. #define PyDict_Check(op) \
  14. PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
  15. #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
  16. PyAPI_FUNC(PyObject *) PyDict_New(void);
  17. PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
  18. PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key);
  19. PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item);
  20. PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key);
  21. PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);
  22. PyAPI_FUNC(int) PyDict_Next(
  23. PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);
  24. PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);
  25. PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);
  26. PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);
  27. PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp);
  28. PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp);
  29. PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key);
  30. /* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */
  31. PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other);
  32. /* PyDict_Merge updates/merges from a mapping object (an object that
  33. supports PyMapping_Keys() and PyObject_GetItem()). If override is true,
  34. the last occurrence of a key wins, else the first. The Python
  35. dict.update(other) is equivalent to PyDict_Merge(dict, other, 1).
  36. */
  37. PyAPI_FUNC(int) PyDict_Merge(PyObject *mp,
  38. PyObject *other,
  39. int override);
  40. /* PyDict_MergeFromSeq2 updates/merges from an iterable object producing
  41. iterable objects of length 2. If override is true, the last occurrence
  42. of a key wins, else the first. The Python dict constructor dict(seq2)
  43. is equivalent to dict={}; PyDict_MergeFromSeq(dict, seq2, 1).
  44. */
  45. PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d,
  46. PyObject *seq2,
  47. int override);
  48. PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key);
  49. PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);
  50. PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key);
  51. /* Dictionary (keys, values, items) views */
  52. PyAPI_DATA(PyTypeObject) PyDictKeys_Type;
  53. PyAPI_DATA(PyTypeObject) PyDictValues_Type;
  54. PyAPI_DATA(PyTypeObject) PyDictItems_Type;
  55. #define PyDictKeys_Check(op) PyObject_TypeCheck(op, &PyDictKeys_Type)
  56. #define PyDictValues_Check(op) PyObject_TypeCheck(op, &PyDictValues_Type)
  57. #define PyDictItems_Check(op) PyObject_TypeCheck(op, &PyDictItems_Type)
  58. /* This excludes Values, since they are not sets. */
  59. # define PyDictViewSet_Check(op) \
  60. (PyDictKeys_Check(op) || PyDictItems_Check(op))
  61. /* Dictionary (key, value, items) iterators */
  62. PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;
  63. PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;
  64. PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;
  65. PyAPI_DATA(PyTypeObject) PyDictRevIterKey_Type;
  66. PyAPI_DATA(PyTypeObject) PyDictRevIterItem_Type;
  67. PyAPI_DATA(PyTypeObject) PyDictRevIterValue_Type;
  68. #ifndef Py_LIMITED_API
  69. # define Py_CPYTHON_DICTOBJECT_H
  70. # include "cpython/dictobject.h"
  71. # undef Py_CPYTHON_DICTOBJECT_H
  72. #endif
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif /* !Py_DICTOBJECT_H */