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