Set オブジェクト¶
This section details the public API for set and frozenset
objects.  Any functionality not listed below is best accessed using either
the abstract object protocol (including PyObject_CallMethod(),
PyObject_RichCompareBool(), PyObject_Hash(),
PyObject_Repr(), PyObject_IsTrue(), PyObject_Print(), and
PyObject_GetIter()) or the abstract number protocol (including
PyNumber_And(), PyNumber_Subtract(), PyNumber_Or(),
PyNumber_Xor(), PyNumber_InPlaceAnd(),
PyNumber_InPlaceSubtract(), PyNumber_InPlaceOr(), and
PyNumber_InPlaceXor()).
- 
PySetObject¶
- This subtype of - PyObjectis used to hold the internal data for both- setand- frozensetobjects. It is like a- PyDictObjectin that it is a fixed size for small sets (much like tuple storage) and will point to a separate, variable sized block of memory for medium and large sized sets (much like list storage). None of the fields of this structure should be considered public and all are subject to change. All access should be done through the documented API rather than by manipulating the values in the structure.
- 
PyTypeObject PySet_Type¶
- この - PyTypeObjectのインスタンスは、Python の- set型を表します。
- 
PyTypeObject PyFrozenSet_Type¶
- この - PyTypeObjectのインスタンスは、Python の- frozenset型を表します。
以降の型チェックマクロはすべての Python オブジェクトに対するポインタに対して動作します。同様に、コンストラクタはすべてのイテレート可能な Python オブジェクトに対して動作します。
- 
int PyAnySet_Check(PyObject *p)¶
- p が - setか- frozenset、あるいはそのサブタイプのオブジェクトであれば、true を返します。この関数は常に成功します。
- 
int PyAnySet_CheckExact(PyObject *p)¶
- p が - setか- frozensetのどちらかのオブジェクトであるときに true を返します。サブタイプのオブジェクトは含みません。この関数は常に成功します。
- 
int PyFrozenSet_CheckExact(PyObject *p)¶
- p が - frozensetオブジェクトだがサブタイプのインスタンスでない場合に真を返します。この関数は常に成功します。
- 
PyObject* PySet_New(PyObject *iterable)¶
- Return value: New reference.iterable が返すオブジェクトを含む新しい setを返します。 iterable がNULLのときは、空の set を返します。 成功したら新しい set を、失敗したらNULLを返します。 iterable がイテレート可能でない場合は、TypeErrorを送出します。 このコンストラクタは set をコピーするときにも使えます (c=set(s))。
- 
PyObject* PyFrozenSet_New(PyObject *iterable)¶
- Return value: New reference.iterable が返すオブジェクトを含む新しい frozensetを返します。 iterable がNULLのときは、空の frozenset を返します。 成功時には新しい set を、失敗時にはNULLを返します。 iterable がイテレート可能でない場合は、TypeErrorを送出します。
以降の関数やマクロは、 set と frozenset とそのサブタイプのインスタンスに対して利用できます。
- 
Py_ssize_t PySet_Size(PyObject *anyset)¶
- setや- frozensetのオブジェクトの長さを返します。- len(anyset)と同じです。 anyset が- set、- frozensetおよびそのサブタイプのオブジェクトでない場合は、- PyExc_SystemErrorを送出します。
- 
Py_ssize_t PySet_GET_SIZE(PyObject *anyset)¶
- エラーチェックを行わない、 - PySet_Size()のマクロ形式。
- 
int PySet_Contains(PyObject *anyset, PyObject *key)¶
- 見つかったら - 1を、見つからなかったら- 0を、エラーが発生した場合は- -1を返します。 Python の- __contains__()メソッドと違って、この関数は非ハッシュ set を一時的な frozenset に自動で変換しません。 key がハッシュ可能で無い場合、- TypeErrorを送出します。 anyset が- set,- frozenset及びそのサブタイプのオブジェクトで無い場合は- PyExc_SystemErrorを送出します。
- 
int PySet_Add(PyObject *set, PyObject *key)¶
- Add key to a - setinstance. Also works with- frozensetinstances (like- PyTuple_SetItem()it can be used to fill in the values of brand new frozensets before they are exposed to other code). Return- 0on success or- -1on failure. Raise a- TypeErrorif the key is unhashable. Raise a- MemoryErrorif there is no room to grow. Raise a- SystemErrorif set is not an instance of- setor its subtype.
以降の関数は、 set とそのサブタイプに対して利用可能です。 frozenset とそのサブタイプには利用できません。
- 
int PySet_Discard(PyObject *set, PyObject *key)¶
- key が見つかって、値を削除したら - 1を返します。 見つからなかったら (何もせずに)- 0を返します。 エラーが発生した場合は- -1を返します。 key が無くても- KeyErrorを送出しません。 key がハッシュ可能でない場合は- TypeErrorを送出します。 Python の- discard()メソッドと違って、この関数は非ハッシュ set を一時的な frozenset に変換しません。 set が- setかそのサブタイプのインスタンスでないときは、- PyExc_SystemErrorを送出します。