set.pxd 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. cdef extern from "Python.h":
  2. ############################################################################
  3. # 7.5.14 Set Objects
  4. ############################################################################
  5. # This section details the public API for set and frozenset
  6. # objects. Any functionality not listed below is best accessed
  7. # using the either the abstract object protocol (including
  8. # PyObject_CallMethod(), PyObject_RichCompareBool(),
  9. # PyObject_Hash(), PyObject_Repr(), PyObject_IsTrue(),
  10. # PyObject_Print(), and PyObject_GetIter()) or the abstract number
  11. # protocol (including PyNumber_Add(), PyNumber_Subtract(),
  12. # PyNumber_Or(), PyNumber_Xor(), PyNumber_InPlaceAdd(),
  13. # PyNumber_InPlaceSubtract(), PyNumber_InPlaceOr(), and
  14. # PyNumber_InPlaceXor()).
  15. # PySetObject
  16. # This subtype of PyObject is used to hold the internal data for
  17. # both set and frozenset objects. It is like a PyDictObject in
  18. # that it is a fixed size for small sets (much like tuple storage)
  19. # and will point to a separate, variable sized block of memory for
  20. # medium and large sized sets (much like list storage). None of
  21. # the fields of this structure should be considered public and are
  22. # subject to change. All access should be done through the
  23. # documented API rather than by manipulating the values in the
  24. # structure.
  25. # PyTypeObject PySet_Type
  26. # This is an instance of PyTypeObject representing the Python set type.
  27. # PyTypeObject PyFrozenSet_Type
  28. # This is an instance of PyTypeObject representing the Python frozenset type.
  29. # The following type check macros work on pointers to any Python
  30. # object. Likewise, the constructor functions work with any
  31. # iterable Python object.
  32. bint PyAnySet_Check(object p)
  33. # Return true if p is a set object, a frozenset object, or an
  34. # instance of a subtype.
  35. bint PyAnySet_CheckExact(object p)
  36. # Return true if p is a set object or a frozenset object but not
  37. # an instance of a subtype.
  38. bint PyFrozenSet_Check(object p)
  39. # Return true if p is a frozenset object or an instance of a subtype.
  40. bint PyFrozenSet_CheckExact(object p)
  41. # Return true if p is a frozenset object but not an instance of a subtype.
  42. bint PySet_Check(object p)
  43. # Return true if p is a set object or an instance of a subtype.
  44. object PySet_New(object iterable)
  45. # Return value: New reference.
  46. # Return a new set containing objects returned by the
  47. # iterable. The iterable may be NULL to create a new empty
  48. # set. Return the new set on success or NULL on failure. Raise
  49. # TypeError if iterable is not actually iterable. The constructor
  50. # is also useful for copying a set (c=set(s)).
  51. object PyFrozenSet_New(object iterable)
  52. # Return value: New reference.
  53. # Return a new frozenset containing objects returned by the
  54. # iterable. The iterable may be NULL to create a new empty
  55. # frozenset. Return the new set on success or NULL on
  56. # failure. Raise TypeError if iterable is not actually iterable.
  57. # The following functions and macros are available for instances
  58. # of set or frozenset or instances of their subtypes.
  59. Py_ssize_t PySet_Size(object anyset) except -1
  60. # Return the length of a set or frozenset object. Equivalent to
  61. # "len(anyset)". Raises a PyExc_SystemError if anyset is not a
  62. # set, frozenset, or an instance of a subtype.
  63. Py_ssize_t PySet_GET_SIZE(object anyset)
  64. # Macro form of PySet_Size() without error checking.
  65. bint PySet_Contains(object anyset, object key) except -1
  66. # Return 1 if found, 0 if not found, and -1 if an error is
  67. # encountered. Unlike the Python __contains__() method, this
  68. # function does not automatically convert unhashable sets into
  69. # temporary frozensets. Raise a TypeError if the key is
  70. # unhashable. Raise PyExc_SystemError if anyset is not a set,
  71. # frozenset, or an instance of a subtype.
  72. # The following functions are available for instances of set or
  73. # its subtypes but not for instances of frozenset or its subtypes.
  74. int PySet_Add(object set, object key) except -1
  75. # Add key to a set instance. Does not apply to frozenset
  76. # instances. Return 0 on success or -1 on failure. Raise a
  77. # TypeError if the key is unhashable. Raise a MemoryError if there
  78. # is no room to grow. Raise a SystemError if set is an not an
  79. # instance of set or its subtype.
  80. bint PySet_Discard(object set, object key) except -1
  81. # Return 1 if found and removed, 0 if not found (no action taken),
  82. # and -1 if an error is encountered. Does not raise KeyError for
  83. # missing keys. Raise a TypeError if the key is unhashable. Unlike
  84. # the Python discard() method, this function does not
  85. # automatically convert unhashable sets into temporary
  86. # frozensets. Raise PyExc_SystemError if set is an not an instance
  87. # of set or its subtype.
  88. object PySet_Pop(object set)
  89. # Return value: New reference.
  90. # Return a new reference to an arbitrary object in the set, and
  91. # removes the object from the set. Return NULL on failure. Raise
  92. # KeyError if the set is empty. Raise a SystemError if set is an
  93. # not an instance of set or its subtype.
  94. int PySet_Clear(object set)
  95. # Empty an existing set of all elements.