1
cdef extern from "Python.h":
3
############################################################################
5
############################################################################
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()).
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
29
# PyTypeObject PySet_Type
30
# This is an instance of PyTypeObject representing the Python set type.
32
# PyTypeObject PyFrozenSet_Type
33
# This is an instance of PyTypeObject representing the Python frozenset type.
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.
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.
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.
47
bint PyFrozenSet_CheckExact(object p)
48
# Return true if p is a frozenset object but not an instance of a subtype.
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)).
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.
66
# The following functions and macros are available for instances
67
# of set or frozenset or instances of their subtypes.
69
int 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.
74
int PySet_GET_SIZE(object anyset)
75
# Macro form of PySet_Size() without error checking.
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.
86
# The following functions are available for instances of set or
87
# its subtypes but not for instances of frozenset or its subtypes.
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.
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.
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.
112
int PySet_Clear(object set)
113
# Empty an existing set of all elements.