Back to index

python3.2  3.2.2
Classes | Defines | Functions | Variables
setobject.c File Reference
#include "Python.h"
#include "structmember.h"
#include "stringlib/eq.h"

Go to the source code of this file.

Classes

struct  setiterobject

Defines

#define PERTURB_SHIFT   5
#define INIT_NONZERO_SET_SLOTS(so)
#define EMPTY_TO_MINSIZE(so)
#define PySet_MAXFREELIST   80
#define DISCARD_NOTFOUND   0
#define DISCARD_FOUND   1

Functions

static void set_key_error (PyObject *arg)
static setentryset_lookkey (PySetObject *so, PyObject *key, register Py_hash_t hash)
static setentryset_lookkey_unicode (PySetObject *so, PyObject *key, register Py_hash_t hash)
static int set_insert_key (register PySetObject *so, PyObject *key, Py_hash_t hash)
static void set_insert_clean (register PySetObject *so, PyObject *key, Py_hash_t hash)
static int set_table_resize (PySetObject *so, Py_ssize_t minused)
static int set_add_entry (register PySetObject *so, setentry *entry)
static int set_add_key (register PySetObject *so, PyObject *key)
static int set_discard_entry (PySetObject *so, setentry *oldentry)
static int set_discard_key (PySetObject *so, PyObject *key)
static int set_clear_internal (PySetObject *so)
static int set_next (PySetObject *so, Py_ssize_t *pos_ptr, setentry **entry_ptr)
static void set_dealloc (PySetObject *so)
static PyObjectset_repr (PySetObject *so)
static Py_ssize_t set_len (PyObject *so)
static int set_merge (PySetObject *so, PyObject *otherset)
static int set_contains_key (PySetObject *so, PyObject *key)
static int set_contains_entry (PySetObject *so, setentry *entry)
static PyObjectset_pop (PySetObject *so)
 PyDoc_STRVAR (pop_doc,"Remove and return an arbitrary set element.\n\ Raises KeyError if the set is empty.")
static int set_traverse (PySetObject *so, visitproc visit, void *arg)
static Py_hash_t frozenset_hash (PyObject *self)
static void setiter_dealloc (setiterobject *si)
static int setiter_traverse (setiterobject *si, visitproc visit, void *arg)
static PyObjectsetiter_len (setiterobject *si)
 PyDoc_STRVAR (length_hint_doc,"Private method returning an estimate of len(list(it)).")
static PyObjectsetiter_iternext (setiterobject *si)
static PyObjectset_iter (PySetObject *so)
static int set_update_internal (PySetObject *so, PyObject *other)
static PyObjectset_update (PySetObject *so, PyObject *args)
 PyDoc_STRVAR (update_doc,"Update a set with the union of itself and others.")
static PyObjectmake_new_set (PyTypeObject *type, PyObject *iterable)
static PyObjectmake_new_set_basetype (PyTypeObject *type, PyObject *iterable)
static PyObjectfrozenset_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
void PySet_Fini (void)
static PyObjectset_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
static void set_swap_bodies (PySetObject *a, PySetObject *b)
static PyObjectset_copy (PySetObject *so)
static PyObjectfrozenset_copy (PySetObject *so)
 PyDoc_STRVAR (copy_doc,"Return a shallow copy of a set.")
static PyObjectset_clear (PySetObject *so)
 PyDoc_STRVAR (clear_doc,"Remove all elements from this set.")
static PyObjectset_union (PySetObject *so, PyObject *args)
 PyDoc_STRVAR (union_doc,"Return the union of sets as a new set.\n\ \n\ (i.e. all elements that are in either set.)")
static PyObjectset_or (PySetObject *so, PyObject *other)
static PyObjectset_ior (PySetObject *so, PyObject *other)
static PyObjectset_intersection (PySetObject *so, PyObject *other)
static PyObjectset_intersection_multi (PySetObject *so, PyObject *args)
 PyDoc_STRVAR (intersection_doc,"Return the intersection of two sets as a new set.\n\ \n\ (i.e. all elements that are in both sets.)")
static PyObjectset_intersection_update (PySetObject *so, PyObject *other)
static PyObjectset_intersection_update_multi (PySetObject *so, PyObject *args)
 PyDoc_STRVAR (intersection_update_doc,"Update a set with the intersection of itself and another.")
static PyObjectset_and (PySetObject *so, PyObject *other)
static PyObjectset_iand (PySetObject *so, PyObject *other)
static PyObjectset_isdisjoint (PySetObject *so, PyObject *other)
 PyDoc_STRVAR (isdisjoint_doc,"Return True if two sets have a null intersection.")
static int set_difference_update_internal (PySetObject *so, PyObject *other)
static PyObjectset_difference_update (PySetObject *so, PyObject *args)
 PyDoc_STRVAR (difference_update_doc,"Remove all elements of another set from this set.")
static PyObjectset_copy_and_difference (PySetObject *so, PyObject *other)
static PyObjectset_difference (PySetObject *so, PyObject *other)
static PyObjectset_difference_multi (PySetObject *so, PyObject *args)
 PyDoc_STRVAR (difference_doc,"Return the difference of two or more sets as a new set.\n\ \n\ (i.e. all elements that are in this set but not the others.)")
static PyObjectset_sub (PySetObject *so, PyObject *other)
static PyObjectset_isub (PySetObject *so, PyObject *other)
static PyObjectset_symmetric_difference_update (PySetObject *so, PyObject *other)
 PyDoc_STRVAR (symmetric_difference_update_doc,"Update a set with the symmetric difference of itself and another.")
static PyObjectset_symmetric_difference (PySetObject *so, PyObject *other)
 PyDoc_STRVAR (symmetric_difference_doc,"Return the symmetric difference of two sets as a new set.\n\ \n\ (i.e. all elements that are in exactly one of the sets.)")
static PyObjectset_xor (PySetObject *so, PyObject *other)
static PyObjectset_ixor (PySetObject *so, PyObject *other)
static PyObjectset_issubset (PySetObject *so, PyObject *other)
 PyDoc_STRVAR (issubset_doc,"Report whether another set contains this set.")
static PyObjectset_issuperset (PySetObject *so, PyObject *other)
 PyDoc_STRVAR (issuperset_doc,"Report whether this set contains another set.")
static PyObjectset_richcompare (PySetObject *v, PyObject *w, int op)
static PyObjectset_add (PySetObject *so, PyObject *key)
 PyDoc_STRVAR (add_doc,"Add an element to a set.\n\ \n\ This has no effect if the element is already present.")
static int set_contains (PySetObject *so, PyObject *key)
static PyObjectset_direct_contains (PySetObject *so, PyObject *key)
 PyDoc_STRVAR (contains_doc,"x.__contains__(y) <==> y in x.")
static PyObjectset_remove (PySetObject *so, PyObject *key)
 PyDoc_STRVAR (remove_doc,"Remove an element from a set; it must be a member.\n\ \n\ If the element is not a member, raise a KeyError.")
static PyObjectset_discard (PySetObject *so, PyObject *key)
 PyDoc_STRVAR (discard_doc,"Remove an element from a set if it is a member.\n\ \n\ If the element is not a member, do nothing.")
static PyObjectset_reduce (PySetObject *so)
 PyDoc_STRVAR (reduce_doc,"Return state information for pickling.")
static PyObjectset_sizeof (PySetObject *so)
 PyDoc_STRVAR (sizeof_doc,"S.__sizeof__() -> size of S in memory, in bytes")
static int set_init (PySetObject *self, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR (set_doc,"set() -> new empty set object\n\ set(iterable) -> new set object\n\ \n\ Build an unordered collection of unique elements.")
 PyDoc_STRVAR (frozenset_doc,"frozenset() -> empty frozenset object\n\ frozenset(iterable) -> frozenset object\n\ \n\ Build an immutable unordered collection of unique elements.")
PyObjectPySet_New (PyObject *iterable)
PyObjectPyFrozenSet_New (PyObject *iterable)
Py_ssize_t PySet_Size (PyObject *anyset)
int PySet_Clear (PyObject *set)
int PySet_Contains (PyObject *anyset, PyObject *key)
int PySet_Discard (PyObject *set, PyObject *key)
int PySet_Add (PyObject *anyset, PyObject *key)
int _PySet_NextEntry (PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash)
PyObjectPySet_Pop (PyObject *set)
int _PySet_Update (PyObject *set, PyObject *iterable)

Variables

static PyObjectdummy = NULL
static PySetObject * free_list [PySet_MAXFREELIST]
static int numfree = 0
static PyMethodDef setiter_methods []
PyTypeObject PySetIter_Type
static PyObjectemptyfrozenset = NULL
static PySequenceMethods set_as_sequence
static PyMethodDef set_methods []
static PyNumberMethods set_as_number
PyTypeObject PySet_Type
static PyMethodDef frozenset_methods []
static PyNumberMethods frozenset_as_number
PyTypeObject PyFrozenSet_Type

Class Documentation

struct setiterobject

Definition at line 797 of file setobject.c.

Class Members
Py_ssize_t len
Py_ssize_t si_pos
PyObject_HEAD PySetObject * si_set
Py_ssize_t si_used

Define Documentation

#define DISCARD_FOUND   1

Definition at line 407 of file setobject.c.

#define DISCARD_NOTFOUND   0

Definition at line 406 of file setobject.c.

#define EMPTY_TO_MINSIZE (   so)
Value:
do {                               \
    memset((so)->smalltable, 0, sizeof((so)->smalltable));      \
    (so)->used = (so)->fill = 0;                                \
    INIT_NONZERO_SET_SLOTS(so);                                 \
    } while(0)

Definition at line 48 of file setobject.c.

#define INIT_NONZERO_SET_SLOTS (   so)
Value:
do {                         \
    (so)->table = (so)->smalltable;                             \
    (so)->mask = PySet_MINSIZE - 1;                             \
    (so)->hash = -1;                                            \
    } while(0)

Definition at line 42 of file setobject.c.

#define PERTURB_SHIFT   5

Definition at line 29 of file setobject.c.

#define PySet_MAXFREELIST   80

Definition at line 56 of file setobject.c.


Function Documentation

int _PySet_NextEntry ( PyObject set,
Py_ssize_t pos,
PyObject **  key,
Py_hash_t hash 
)

Definition at line 2329 of file setobject.c.

{
    setentry *entry;

    if (!PyAnySet_Check(set)) {
        PyErr_BadInternalCall();
        return -1;
    }
    if (set_next((PySetObject *)set, pos, &entry) == 0)
        return 0;
    *key = entry->key;
    *hash = entry->hash;
    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _PySet_Update ( PyObject set,
PyObject iterable 
)

Definition at line 2355 of file setobject.c.

{
    if (!PySet_Check(set)) {
        PyErr_BadInternalCall();
        return -1;
    }
    return set_update_internal((PySetObject *)set, iterable);
}

Here is the call graph for this function:

static PyObject* frozenset_copy ( PySetObject *  so) [static]

Definition at line 1160 of file setobject.c.

{
    if (PyFrozenSet_CheckExact(so)) {
        Py_INCREF(so);
        return (PyObject *)so;
    }
    return set_copy(so);
}

Here is the call graph for this function:

static Py_hash_t frozenset_hash ( PyObject self) [static]

Definition at line 768 of file setobject.c.

{
    PySetObject *so = (PySetObject *)self;
    Py_hash_t h, hash = 1927868237L;
    setentry *entry;
    Py_ssize_t pos = 0;

    if (so->hash != -1)
        return so->hash;

    hash *= PySet_GET_SIZE(self) + 1;
    while (set_next(so, &pos, &entry)) {
        /* Work to increase the bit dispersion for closely spaced hash
           values.  The is important because some use cases have many
           combinations of a small number of elements with nearby
           hashes so that many distinct combinations collapse to only
           a handful of distinct hash values. */
        h = entry->hash;
        hash ^= (h ^ (h << 16) ^ 89869747L)  * 3644798167u;
    }
    hash = hash * 69069L + 907133923L;
    if (hash == -1)
        hash = 590923713L;
    so->hash = hash;
    return hash;
}

Here is the call graph for this function:

static PyObject* frozenset_new ( PyTypeObject type,
PyObject args,
PyObject kwds 
) [static]

Definition at line 1048 of file setobject.c.

{
    PyObject *iterable = NULL, *result;

    if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset()", kwds))
        return NULL;

    if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable))
        return NULL;

    if (type != &PyFrozenSet_Type)
        return make_new_set(type, iterable);

    if (iterable != NULL) {
        /* frozenset(f) is idempotent */
        if (PyFrozenSet_CheckExact(iterable)) {
            Py_INCREF(iterable);
            return iterable;
        }
        result = make_new_set(type, iterable);
        if (result == NULL || PySet_GET_SIZE(result))
            return result;
        Py_DECREF(result);
    }
    /* The empty frozenset is a singleton */
    if (emptyfrozenset == NULL)
        emptyfrozenset = make_new_set(type, NULL);
    Py_XINCREF(emptyfrozenset);
    return emptyfrozenset;
}

Here is the call graph for this function:

static PyObject* make_new_set ( PyTypeObject type,
PyObject iterable 
) [static]

Definition at line 991 of file setobject.c.

{
    register PySetObject *so = NULL;

    if (dummy == NULL) { /* Auto-initialize dummy */
        dummy = PyUnicode_FromString("<dummy key>");
        if (dummy == NULL)
            return NULL;
    }

    /* create PySetObject structure */
    if (numfree &&
        (type == &PySet_Type  ||  type == &PyFrozenSet_Type)) {
        so = free_list[--numfree];
        assert (so != NULL && PyAnySet_CheckExact(so));
        Py_TYPE(so) = type;
        _Py_NewReference((PyObject *)so);
        EMPTY_TO_MINSIZE(so);
        PyObject_GC_Track(so);
    } else {
        so = (PySetObject *)type->tp_alloc(type, 0);
        if (so == NULL)
            return NULL;
        /* tp_alloc has already zeroed the structure */
        assert(so->table == NULL && so->fill == 0 && so->used == 0);
        INIT_NONZERO_SET_SLOTS(so);
    }

    so->lookup = set_lookkey_unicode;
    so->weakreflist = NULL;

    if (iterable != NULL) {
        if (set_update_internal(so, iterable) == -1) {
            Py_DECREF(so);
            return NULL;
        }
    }

    return (PyObject *)so;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* make_new_set_basetype ( PyTypeObject type,
PyObject iterable 
) [static]

Definition at line 1033 of file setobject.c.

{
    if (type != &PySet_Type && type != &PyFrozenSet_Type) {
        if (PyType_IsSubtype(type, &PySet_Type))
            type = &PySet_Type;
        else
            type = &PyFrozenSet_Type;
    }
    return make_new_set(type, iterable);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PyDoc_STRVAR ( pop_doc  ,
"Remove and return an arbitrary set element.\n\Raises KeyError if the set is empty."   
)
PyDoc_STRVAR ( length_hint_doc  ,
"Private method returning an estimate of len(list(it))."   
)
PyDoc_STRVAR ( update_doc  ,
"Update a set with the union of itself and others."   
)
PyDoc_STRVAR ( copy_doc  ,
"Return a shallow copy of a set."   
)
PyDoc_STRVAR ( clear_doc  ,
"Remove all elements from this set."   
)
PyDoc_STRVAR ( union_doc  ,
"Return the union of sets as a new set.\n\\n\(i.e. all elements that are in either set.)"   
)
PyDoc_STRVAR ( intersection_doc  ,
"Return the intersection of two sets as a new set.\n\\n\(i.e. all elements that are in both sets.)"   
)
PyDoc_STRVAR ( intersection_update_doc  ,
"Update a set with the intersection of itself and another."   
)
PyDoc_STRVAR ( isdisjoint_doc  ,
"Return True if two sets have a null intersection."   
)
PyDoc_STRVAR ( difference_update_doc  ,
"Remove all elements of another set from this set."   
)
PyDoc_STRVAR ( difference_doc  ,
"Return the difference of two or more sets as a new set.\n\\n\(i.e. all elements that are in this set but not the others.)"   
)
PyDoc_STRVAR ( symmetric_difference_update_doc  ,
"Update a set with the symmetric difference of itself and another."   
)
PyDoc_STRVAR ( symmetric_difference_doc  ,
"Return the symmetric difference of two sets as a new set.\n\\n\(i.e. all elements that are in exactly one of the sets.)"   
)
PyDoc_STRVAR ( issubset_doc  ,
"Report whether another set contains this set."   
)
PyDoc_STRVAR ( issuperset_doc  ,
"Report whether this set contains another set."   
)
PyDoc_STRVAR ( add_doc  ,
"Add an element to a set.\n\\n\This has no effect if the element is already present."   
)
PyDoc_STRVAR ( contains_doc  ,
"x.__contains__(y) <=  ,
y in x."   
)
PyDoc_STRVAR ( remove_doc  ,
"Remove an element from a set; it must be a member.\n\\n\If the element is not a  member,
raise a KeyError."   
)
PyDoc_STRVAR ( discard_doc  ,
"Remove an element from a set if it is a member.\n\\n\If the element is not a  member,
do nothing."   
)
PyDoc_STRVAR ( reduce_doc  ,
"Return state information for pickling."   
)
PyDoc_STRVAR ( sizeof_doc  ,
"S.__sizeof__() -> size of S in  memory,
in bytes  
)
PyDoc_STRVAR ( set_doc  ,
"set() -> new empty set object\n\set(iterable) -> new set object\n\\n\Build an unordered collection of unique elements."   
)
PyDoc_STRVAR ( frozenset_doc  ,
"frozenset() -> empty frozenset object\n\frozenset(iterable) -> frozenset object\n\\n\Build an immutable unordered collection of unique elements."   
)
PyObject* PyFrozenSet_New ( PyObject iterable)

Definition at line 2272 of file setobject.c.

{
    return make_new_set(&PyFrozenSet_Type, iterable);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PySet_Add ( PyObject anyset,
PyObject key 
)

Definition at line 2318 of file setobject.c.

{
    if (!PySet_Check(anyset) &&
        (!PyFrozenSet_Check(anyset) || Py_REFCNT(anyset) != 1)) {
        PyErr_BadInternalCall();
        return -1;
    }
    return set_add_key((PySetObject *)anyset, key);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PySet_Clear ( PyObject set)

Definition at line 2288 of file setobject.c.

{
    if (!PySet_Check(set)) {
        PyErr_BadInternalCall();
        return -1;
    }
    return set_clear_internal((PySetObject *)set);
}

Here is the call graph for this function:

int PySet_Contains ( PyObject anyset,
PyObject key 
)

Definition at line 2298 of file setobject.c.

{
    if (!PyAnySet_Check(anyset)) {
        PyErr_BadInternalCall();
        return -1;
    }
    return set_contains_key((PySetObject *)anyset, key);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PySet_Discard ( PyObject set,
PyObject key 
)

Definition at line 2308 of file setobject.c.

{
    if (!PySet_Check(set)) {
        PyErr_BadInternalCall();
        return -1;
    }
    return set_discard_key((PySetObject *)set, key);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1080 of file setobject.c.

{
    PySetObject *so;

    while (numfree) {
        numfree--;
        so = free_list[numfree];
        PyObject_GC_Del(so);
    }
    Py_CLEAR(dummy);
    Py_CLEAR(emptyfrozenset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PyObject* PySet_New ( PyObject iterable)

Definition at line 2266 of file setobject.c.

{
    return make_new_set(&PySet_Type, iterable);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2345 of file setobject.c.

{
    if (!PySet_Check(set)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return set_pop((PySetObject *)set);
}

Here is the call graph for this function:

Definition at line 2278 of file setobject.c.

{
    if (!PyAnySet_Check(anyset)) {
        PyErr_BadInternalCall();
        return -1;
    }
    return PySet_GET_SIZE(anyset);
}
static PyObject* set_add ( PySetObject *  so,
PyObject key 
) [static]

Definition at line 1854 of file setobject.c.

{
    if (set_add_key(so, key) == -1)
        return NULL;
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static int set_add_entry ( register PySetObject *  so,
setentry entry 
) [static]

Definition at line 364 of file setobject.c.

{
    register Py_ssize_t n_used;
    PyObject *key = entry->key;
    Py_hash_t hash = entry->hash;

    assert(so->fill <= so->mask);  /* at least one empty slot */
    n_used = so->used;
    Py_INCREF(key);
    if (set_insert_key(so, key, hash) == -1) {
        Py_DECREF(key);
        return -1;
    }
    if (!(so->used > n_used && so->fill*3 >= (so->mask+1)*2))
        return 0;
    return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int set_add_key ( register PySetObject *  so,
PyObject key 
) [static]

Definition at line 383 of file setobject.c.

{
    register Py_hash_t hash;
    register Py_ssize_t n_used;

    if (!PyUnicode_CheckExact(key) ||
        (hash = ((PyUnicodeObject *) key)->hash) == -1) {
        hash = PyObject_Hash(key);
        if (hash == -1)
            return -1;
    }
    assert(so->fill <= so->mask);  /* at least one empty slot */
    n_used = so->used;
    Py_INCREF(key);
    if (set_insert_key(so, key, hash) == -1) {
        Py_DECREF(key);
        return -1;
    }
    if (!(so->used > n_used && so->fill*3 >= (so->mask+1)*2))
        return 0;
    return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_and ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1384 of file setobject.c.

{
    if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    return set_intersection(so, other);
}

Here is the call graph for this function:

static PyObject* set_clear ( PySetObject *  so) [static]

Definition at line 1172 of file setobject.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static int set_clear_internal ( PySetObject *  so) [static]

Definition at line 456 of file setobject.c.

{
    setentry *entry, *table;
    int table_is_malloced;
    Py_ssize_t fill;
    setentry small_copy[PySet_MINSIZE];
#ifdef Py_DEBUG
    Py_ssize_t i, n;
    assert (PyAnySet_Check(so));

    n = so->mask + 1;
    i = 0;
#endif

    table = so->table;
    assert(table != NULL);
    table_is_malloced = table != so->smalltable;

    /* This is delicate.  During the process of clearing the set,
     * decrefs can cause the set to mutate.  To avoid fatal confusion
     * (voice of experience), we have to make the set empty before
     * clearing the slots, and never refer to anything via so->ref while
     * clearing.
     */
    fill = so->fill;
    if (table_is_malloced)
        EMPTY_TO_MINSIZE(so);

    else if (fill > 0) {
        /* It's a small table with something that needs to be cleared.
         * Afraid the only safe way is to copy the set entries into
         * another small table first.
         */
        memcpy(small_copy, table, sizeof(small_copy));
        table = small_copy;
        EMPTY_TO_MINSIZE(so);
    }
    /* else it's a small table that's already empty */

    /* Now we can finally clear things.  If C had refcounts, we could
     * assert that the refcount on table is 1 now, i.e. that this function
     * has unique access to it, so decref side-effects can't alter it.
     */
    for (entry = table; fill > 0; ++entry) {
#ifdef Py_DEBUG
        assert(i < n);
        ++i;
#endif
        if (entry->key) {
            --fill;
            Py_DECREF(entry->key);
        }
#ifdef Py_DEBUG
        else
            assert(entry->key == NULL);
#endif
    }

    if (table_is_malloced)
        PyMem_DEL(table);
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int set_contains ( PySetObject *  so,
PyObject key 
) [static]

Definition at line 1867 of file setobject.c.

{
    PyObject *tmpkey;
    int rv;

    rv = set_contains_key(so, key);
    if (rv == -1) {
        if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError))
            return -1;
        PyErr_Clear();
        tmpkey = make_new_set(&PyFrozenSet_Type, key);
        if (tmpkey == NULL)
            return -1;
        rv = set_contains(so, tmpkey);
        Py_DECREF(tmpkey);
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int set_contains_entry ( PySetObject *  so,
setentry entry 
) [static]

Definition at line 698 of file setobject.c.

{
    PyObject *key;
    setentry *lu_entry;

    lu_entry = (so->lookup)(so, entry->key, entry->hash);
    if (lu_entry == NULL)
        return -1;
    key = lu_entry->key;
    return key != NULL && key != dummy;
}

Here is the caller graph for this function:

static int set_contains_key ( PySetObject *  so,
PyObject key 
) [static]

Definition at line 679 of file setobject.c.

{
    Py_hash_t hash;
    setentry *entry;

    if (!PyUnicode_CheckExact(key) ||
        (hash = ((PyUnicodeObject *) key)->hash) == -1) {
        hash = PyObject_Hash(key);
        if (hash == -1)
            return -1;
    }
    entry = (so->lookup)(so, key, hash);
    if (entry == NULL)
        return -1;
    key = entry->key;
    return key != NULL && key != dummy;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_copy ( PySetObject *  so) [static]

Definition at line 1154 of file setobject.c.

{
    return make_new_set_basetype(Py_TYPE(so), (PyObject *)so);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_copy_and_difference ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1531 of file setobject.c.

{
    PyObject *result;

    result = set_copy(so);
    if (result == NULL)
        return NULL;
    if (set_difference_update_internal((PySetObject *) result, other) != -1)
        return result;
    Py_DECREF(result);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_dealloc ( PySetObject *  so) [static]

Definition at line 555 of file setobject.c.

{
    register setentry *entry;
    Py_ssize_t fill = so->fill;
    PyObject_GC_UnTrack(so);
    Py_TRASHCAN_SAFE_BEGIN(so)
    if (so->weakreflist != NULL)
        PyObject_ClearWeakRefs((PyObject *) so);

    for (entry = so->table; fill > 0; entry++) {
        if (entry->key) {
            --fill;
            Py_DECREF(entry->key);
        }
    }
    if (so->table != so->smalltable)
        PyMem_DEL(so->table);
    if (numfree < PySet_MAXFREELIST && PyAnySet_CheckExact(so))
        free_list[numfree++] = so;
    else
        Py_TYPE(so)->tp_free(so);
    Py_TRASHCAN_SAFE_END(so)
}

Here is the call graph for this function:

static PyObject* set_difference ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1545 of file setobject.c.

{
    PyObject *result;
    setentry *entry;
    Py_ssize_t pos = 0;

    if (!PyAnySet_Check(other)  && !PyDict_CheckExact(other)) {
        return set_copy_and_difference(so, other);
    }

    /* If len(so) much more than len(other), it's more efficient to simply copy
     * so and then iterate other looking for common elements. */
    if ((PySet_GET_SIZE(so) >> 2) > PyObject_Size(other)) {
        return set_copy_and_difference(so, other);
    }

    result = make_new_set_basetype(Py_TYPE(so), NULL);
    if (result == NULL)
        return NULL;

    if (PyDict_CheckExact(other)) {
        while (set_next(so, &pos, &entry)) {
            setentry entrycopy;
            entrycopy.hash = entry->hash;
            entrycopy.key = entry->key;
            if (!_PyDict_Contains(other, entry->key, entry->hash)) {
                if (set_add_entry((PySetObject *)result, &entrycopy) == -1) {
                    Py_DECREF(result);
                    return NULL;
                }
            }
        }
        return result;
    }

    /* Iterate over so, checking for common elements in other. */
    while (set_next(so, &pos, &entry)) {
        int rv = set_contains_entry((PySetObject *)other, entry);
        if (rv == -1) {
            Py_DECREF(result);
            return NULL;
        }
        if (!rv) {
            if (set_add_entry((PySetObject *)result, entry) == -1) {
                Py_DECREF(result);
                return NULL;
            }
        }
    }
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_difference_multi ( PySetObject *  so,
PyObject args 
) [static]

Definition at line 1598 of file setobject.c.

{
    Py_ssize_t i;
    PyObject *result, *other;

    if (PyTuple_GET_SIZE(args) == 0)
        return set_copy(so);

    other = PyTuple_GET_ITEM(args, 0);
    result = set_difference(so, other);
    if (result == NULL)
        return NULL;

    for (i=1 ; i<PyTuple_GET_SIZE(args) ; i++) {
        other = PyTuple_GET_ITEM(args, i);
        if (set_difference_update_internal((PySetObject *)result, other) == -1) {
            Py_DECREF(result);
            return NULL;
        }
    }
    return result;
}

Here is the call graph for this function:

static PyObject* set_difference_update ( PySetObject *  so,
PyObject args 
) [static]

Definition at line 1515 of file setobject.c.

{
    Py_ssize_t i;

    for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
        PyObject *other = PyTuple_GET_ITEM(args, i);
        if (set_difference_update_internal(so, other) == -1)
            return NULL;
    }
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static int set_difference_update_internal ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1478 of file setobject.c.

{
    if ((PyObject *)so == other)
        return set_clear_internal(so);

    if (PyAnySet_Check(other)) {
        setentry *entry;
        Py_ssize_t pos = 0;

        while (set_next((PySetObject *)other, &pos, &entry))
            if (set_discard_entry(so, entry) == -1)
                return -1;
    } else {
        PyObject *key, *it;
        it = PyObject_GetIter(other);
        if (it == NULL)
            return -1;

        while ((key = PyIter_Next(it)) != NULL) {
            if (set_discard_key(so, key) == -1) {
                Py_DECREF(it);
                Py_DECREF(key);
                return -1;
            }
            Py_DECREF(key);
        }
        Py_DECREF(it);
        if (PyErr_Occurred())
            return -1;
    }
    /* If more than 1/5 are dummies, then resize them away. */
    if ((so->fill - so->used) * 5 < so->mask)
        return 0;
    return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_direct_contains ( PySetObject *  so,
PyObject key 
) [static]

Definition at line 1887 of file setobject.c.

{
    long result;

    result = set_contains(so, key);
    if (result == -1)
        return NULL;
    return PyBool_FromLong(result);
}

Here is the call graph for this function:

static PyObject* set_discard ( PySetObject *  so,
PyObject key 
) [static]

Definition at line 1932 of file setobject.c.

{
    PyObject *tmpkey, *result;
    int rv;

    rv = set_discard_key(so, key);
    if (rv == -1) {
        if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError))
            return NULL;
        PyErr_Clear();
        tmpkey = make_new_set(&PyFrozenSet_Type, key);
        if (tmpkey == NULL)
            return NULL;
        result = set_discard(so, tmpkey);
        Py_DECREF(tmpkey);
        return result;
    }
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static int set_discard_entry ( PySetObject *  so,
setentry oldentry 
) [static]

Definition at line 410 of file setobject.c.

{       register setentry *entry;
    PyObject *old_key;

    entry = (so->lookup)(so, oldentry->key, oldentry->hash);
    if (entry == NULL)
        return -1;
    if (entry->key == NULL  ||  entry->key == dummy)
        return DISCARD_NOTFOUND;
    old_key = entry->key;
    Py_INCREF(dummy);
    entry->key = dummy;
    so->used--;
    Py_DECREF(old_key);
    return DISCARD_FOUND;
}

Here is the caller graph for this function:

static int set_discard_key ( PySetObject *  so,
PyObject key 
) [static]

Definition at line 428 of file setobject.c.

{
    register Py_hash_t hash;
    register setentry *entry;
    PyObject *old_key;

    assert (PyAnySet_Check(so));

    if (!PyUnicode_CheckExact(key) ||
        (hash = ((PyUnicodeObject *) key)->hash) == -1) {
        hash = PyObject_Hash(key);
        if (hash == -1)
            return -1;
    }
    entry = (so->lookup)(so, key, hash);
    if (entry == NULL)
        return -1;
    if (entry->key == NULL  ||  entry->key == dummy)
        return DISCARD_NOTFOUND;
    old_key = entry->key;
    Py_INCREF(dummy);
    entry->key = dummy;
    so->used--;
    Py_DECREF(old_key);
    return DISCARD_FOUND;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_iand ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1394 of file setobject.c.

{
    PyObject *result;

    if (!PyAnySet_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    result = set_intersection_update(so, other);
    if (result == NULL)
        return NULL;
    Py_DECREF(result);
    Py_INCREF(so);
    return (PyObject *)so;
}

Here is the call graph for this function:

static int set_init ( PySetObject *  self,
PyObject args,
PyObject kwds 
) [static]

Definition at line 1997 of file setobject.c.

{
    PyObject *iterable = NULL;

    if (!PyAnySet_Check(self))
        return -1;
    if (PySet_Check(self) && !_PyArg_NoKeywords("set()", kwds))
        return -1;
    if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable))
        return -1;
    set_clear_internal(self);
    self->hash = -1;
    if (iterable == NULL)
        return 0;
    return set_update_internal(self, iterable);
}

Here is the call graph for this function:

static void set_insert_clean ( register PySetObject *  so,
PyObject key,
Py_hash_t  hash 
) [static]

Definition at line 251 of file setobject.c.

{
    register size_t i;
    register size_t perturb;
    register size_t mask = (size_t)so->mask;
    setentry *table = so->table;
    register setentry *entry;

    i = hash & mask;
    entry = &table[i];
    for (perturb = hash; entry->key != NULL; perturb >>= PERTURB_SHIFT) {
        i = (i << 2) + i + perturb + 1;
        entry = &table[i & mask];
    }
    so->fill++;
    entry->key = key;
    entry->hash = hash;
    so->used++;
}

Here is the caller graph for this function:

static int set_insert_key ( register PySetObject *  so,
PyObject key,
Py_hash_t  hash 
) [static]

Definition at line 214 of file setobject.c.

{
    register setentry *entry;
    typedef setentry *(*lookupfunc)(PySetObject *, PyObject *, Py_hash_t);

    assert(so->lookup != NULL);
    entry = so->lookup(so, key, hash);
    if (entry == NULL)
        return -1;
    if (entry->key == NULL) {
        /* UNUSED */
        so->fill++;
        entry->key = key;
        entry->hash = hash;
        so->used++;
    } else if (entry->key == dummy) {
        /* DUMMY */
        entry->key = key;
        entry->hash = hash;
        so->used++;
        Py_DECREF(dummy);
    } else {
        /* ACTIVE */
        Py_DECREF(key);
    }
    return 0;
}

Here is the caller graph for this function:

static PyObject* set_intersection ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1244 of file setobject.c.

{
    PySetObject *result;
    PyObject *key, *it, *tmp;

    if ((PyObject *)so == other)
        return set_copy(so);

    result = (PySetObject *)make_new_set_basetype(Py_TYPE(so), NULL);
    if (result == NULL)
        return NULL;

    if (PyAnySet_Check(other)) {
        Py_ssize_t pos = 0;
        setentry *entry;

        if (PySet_GET_SIZE(other) > PySet_GET_SIZE(so)) {
            tmp = (PyObject *)so;
            so = (PySetObject *)other;
            other = tmp;
        }

        while (set_next((PySetObject *)other, &pos, &entry)) {
            int rv = set_contains_entry(so, entry);
            if (rv == -1) {
                Py_DECREF(result);
                return NULL;
            }
            if (rv) {
                if (set_add_entry(result, entry) == -1) {
                    Py_DECREF(result);
                    return NULL;
                }
            }
        }
        return (PyObject *)result;
    }

    it = PyObject_GetIter(other);
    if (it == NULL) {
        Py_DECREF(result);
        return NULL;
    }

    while ((key = PyIter_Next(it)) != NULL) {
        int rv;
        setentry entry;
        Py_hash_t hash = PyObject_Hash(key);

        if (hash == -1) {
            Py_DECREF(it);
            Py_DECREF(result);
            Py_DECREF(key);
            return NULL;
        }
        entry.hash = hash;
        entry.key = key;
        rv = set_contains_entry(so, &entry);
        if (rv == -1) {
            Py_DECREF(it);
            Py_DECREF(result);
            Py_DECREF(key);
            return NULL;
        }
        if (rv) {
            if (set_add_entry(result, &entry) == -1) {
                Py_DECREF(it);
                Py_DECREF(result);
                Py_DECREF(key);
                return NULL;
            }
        }
        Py_DECREF(key);
    }
    Py_DECREF(it);
    if (PyErr_Occurred()) {
        Py_DECREF(result);
        return NULL;
    }
    return (PyObject *)result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_intersection_multi ( PySetObject *  so,
PyObject args 
) [static]

Definition at line 1327 of file setobject.c.

{
    Py_ssize_t i;
    PyObject *result = (PyObject *)so;

    if (PyTuple_GET_SIZE(args) == 0)
        return set_copy(so);

    Py_INCREF(so);
    for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
        PyObject *other = PyTuple_GET_ITEM(args, i);
        PyObject *newresult = set_intersection((PySetObject *)result, other);
        if (newresult == NULL) {
            Py_DECREF(result);
            return NULL;
        }
        Py_DECREF(result);
        result = newresult;
    }
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_intersection_update ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1355 of file setobject.c.

{
    PyObject *tmp;

    tmp = set_intersection(so, other);
    if (tmp == NULL)
        return NULL;
    set_swap_bodies(so, (PySetObject *)tmp);
    Py_DECREF(tmp);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_intersection_update_multi ( PySetObject *  so,
PyObject args 
) [static]

Definition at line 1368 of file setobject.c.

{
    PyObject *tmp;

    tmp = set_intersection_multi(so, args);
    if (tmp == NULL)
        return NULL;
    set_swap_bodies(so, (PySetObject *)tmp);
    Py_DECREF(tmp);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* set_ior ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1231 of file setobject.c.

{
    if (!PyAnySet_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    if (set_update_internal(so, other) == -1)
        return NULL;
    Py_INCREF(so);
    return (PyObject *)so;
}

Here is the call graph for this function:

static PyObject* set_isdisjoint ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1411 of file setobject.c.

{
    PyObject *key, *it, *tmp;

    if ((PyObject *)so == other) {
        if (PySet_GET_SIZE(so) == 0)
            Py_RETURN_TRUE;
        else
            Py_RETURN_FALSE;
    }

    if (PyAnySet_CheckExact(other)) {
        Py_ssize_t pos = 0;
        setentry *entry;

        if (PySet_GET_SIZE(other) > PySet_GET_SIZE(so)) {
            tmp = (PyObject *)so;
            so = (PySetObject *)other;
            other = tmp;
        }
        while (set_next((PySetObject *)other, &pos, &entry)) {
            int rv = set_contains_entry(so, entry);
            if (rv == -1)
                return NULL;
            if (rv)
                Py_RETURN_FALSE;
        }
        Py_RETURN_TRUE;
    }

    it = PyObject_GetIter(other);
    if (it == NULL)
        return NULL;

    while ((key = PyIter_Next(it)) != NULL) {
        int rv;
        setentry entry;
        Py_hash_t hash = PyObject_Hash(key);

        if (hash == -1) {
            Py_DECREF(key);
            Py_DECREF(it);
            return NULL;
        }
        entry.hash = hash;
        entry.key = key;
        rv = set_contains_entry(so, &entry);
        Py_DECREF(key);
        if (rv == -1) {
            Py_DECREF(it);
            return NULL;
        }
        if (rv) {
            Py_DECREF(it);
            Py_RETURN_FALSE;
        }
    }
    Py_DECREF(it);
    if (PyErr_Occurred())
        return NULL;
    Py_RETURN_TRUE;
}

Here is the call graph for this function:

static PyObject* set_issubset ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1764 of file setobject.c.

{
    setentry *entry;
    Py_ssize_t pos = 0;

    if (!PyAnySet_Check(other)) {
        PyObject *tmp, *result;
        tmp = make_new_set(&PySet_Type, other);
        if (tmp == NULL)
            return NULL;
        result = set_issubset(so, tmp);
        Py_DECREF(tmp);
        return result;
    }
    if (PySet_GET_SIZE(so) > PySet_GET_SIZE(other))
        Py_RETURN_FALSE;

    while (set_next(so, &pos, &entry)) {
        int rv = set_contains_entry((PySetObject *)other, entry);
        if (rv == -1)
            return NULL;
        if (!rv)
            Py_RETURN_FALSE;
    }
    Py_RETURN_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_issuperset ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1794 of file setobject.c.

{
    PyObject *tmp, *result;

    if (!PyAnySet_Check(other)) {
        tmp = make_new_set(&PySet_Type, other);
        if (tmp == NULL)
            return NULL;
        result = set_issuperset(so, tmp);
        Py_DECREF(tmp);
        return result;
    }
    return set_issubset((PySetObject *)other, (PyObject *)so);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_isub ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1636 of file setobject.c.

{
    if (!PyAnySet_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    if (set_difference_update_internal(so, other) == -1)
        return NULL;
    Py_INCREF(so);
    return (PyObject *)so;
}

Here is the call graph for this function:

static PyObject* set_iter ( PySetObject *  so) [static]

Definition at line 907 of file setobject.c.

{
    setiterobject *si = PyObject_GC_New(setiterobject, &PySetIter_Type);
    if (si == NULL)
        return NULL;
    Py_INCREF(so);
    si->si_set = so;
    si->si_used = so->used;
    si->si_pos = 0;
    si->len = so->used;
    _PyObject_GC_TRACK(si);
    return (PyObject *)si;
}
static PyObject* set_ixor ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1747 of file setobject.c.

{
    PyObject *result;

    if (!PyAnySet_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    result = set_symmetric_difference_update(so, other);
    if (result == NULL)
        return NULL;
    Py_DECREF(result);
    Py_INCREF(so);
    return (PyObject *)so;
}

Here is the call graph for this function:

static void set_key_error ( PyObject arg) [static]

Definition at line 18 of file setobject.c.

{
    PyObject *tup;
    tup = PyTuple_Pack(1, arg);
    if (!tup)
        return; /* caller will expect error to be set anyway */
    PyErr_SetObject(PyExc_KeyError, tup);
    Py_DECREF(tup);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Py_ssize_t set_len ( PyObject so) [static]

Definition at line 633 of file setobject.c.

{
    return ((PySetObject *)so)->used;
}
static setentry* set_lookkey ( PySetObject *  so,
PyObject key,
register Py_hash_t  hash 
) [static]

Definition at line 78 of file setobject.c.

{
    register Py_ssize_t i;
    register size_t perturb;
    register setentry *freeslot;
    register size_t mask = so->mask;
    setentry *table = so->table;
    register setentry *entry;
    register int cmp;
    PyObject *startkey;

    i = hash & mask;
    entry = &table[i];
    if (entry->key == NULL || entry->key == key)
        return entry;

    if (entry->key == dummy)
        freeslot = entry;
    else {
        if (entry->hash == hash) {
            startkey = entry->key;
            Py_INCREF(startkey);
            cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
            Py_DECREF(startkey);
            if (cmp < 0)
                return NULL;
            if (table == so->table && entry->key == startkey) {
                if (cmp > 0)
                    return entry;
            }
            else {
                /* The compare did major nasty stuff to the
                 * set:  start over.
                 */
                return set_lookkey(so, key, hash);
            }
        }
        freeslot = NULL;
    }

    /* In the loop, key == dummy is by far (factor of 100s) the
       least likely outcome, so test for that last. */
    for (perturb = hash; ; perturb >>= PERTURB_SHIFT) {
        i = (i << 2) + i + perturb + 1;
        entry = &table[i & mask];
        if (entry->key == NULL) {
            if (freeslot != NULL)
                entry = freeslot;
            break;
        }
        if (entry->key == key)
            break;
        if (entry->hash == hash && entry->key != dummy) {
            startkey = entry->key;
            Py_INCREF(startkey);
            cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
            Py_DECREF(startkey);
            if (cmp < 0)
                return NULL;
            if (table == so->table && entry->key == startkey) {
                if (cmp > 0)
                    break;
            }
            else {
                /* The compare did major nasty stuff to the
                 * set:  start over.
                 */
                return set_lookkey(so, key, hash);
            }
        }
        else if (entry->key == dummy && freeslot == NULL)
            freeslot = entry;
    }
    return entry;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static setentry* set_lookkey_unicode ( PySetObject *  so,
PyObject key,
register Py_hash_t  hash 
) [static]

Definition at line 160 of file setobject.c.

{
    register Py_ssize_t i;
    register size_t perturb;
    register setentry *freeslot;
    register size_t mask = so->mask;
    setentry *table = so->table;
    register setentry *entry;

    /* Make sure this function doesn't have to handle non-unicode keys,
       including subclasses of str; e.g., one reason to subclass
       strings is to override __eq__, and for speed we don't cater to
       that here. */
    if (!PyUnicode_CheckExact(key)) {
        so->lookup = set_lookkey;
        return set_lookkey(so, key, hash);
    }
    i = hash & mask;
    entry = &table[i];
    if (entry->key == NULL || entry->key == key)
        return entry;
    if (entry->key == dummy)
        freeslot = entry;
    else {
        if (entry->hash == hash && unicode_eq(entry->key, key))
            return entry;
        freeslot = NULL;
    }

    /* In the loop, key == dummy is by far (factor of 100s) the
       least likely outcome, so test for that last. */
    for (perturb = hash; ; perturb >>= PERTURB_SHIFT) {
        i = (i << 2) + i + perturb + 1;
        entry = &table[i & mask];
        if (entry->key == NULL)
            return freeslot == NULL ? entry : freeslot;
        if (entry->key == key
            || (entry->hash == hash
            && entry->key != dummy
            && unicode_eq(entry->key, key)))
            return entry;
        if (entry->key == dummy && freeslot == NULL)
            freeslot = entry;
    }
    assert(0);          /* NOT REACHED */
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int set_merge ( PySetObject *  so,
PyObject otherset 
) [static]

Definition at line 639 of file setobject.c.

{
    PySetObject *other;
    PyObject *key;
    Py_hash_t hash;
    register Py_ssize_t i;
    register setentry *entry;

    assert (PyAnySet_Check(so));
    assert (PyAnySet_Check(otherset));

    other = (PySetObject*)otherset;
    if (other == so || other->used == 0)
        /* a.update(a) or a.update({}); nothing to do */
        return 0;
    /* Do one big resize at the start, rather than
     * incrementally resizing as we insert new keys.  Expect
     * that there will be no (or few) overlapping keys.
     */
    if ((so->fill + other->used)*3 >= (so->mask+1)*2) {
       if (set_table_resize(so, (so->used + other->used)*2) != 0)
           return -1;
    }
    for (i = 0; i <= other->mask; i++) {
        entry = &other->table[i];
        key = entry->key;
        hash = entry->hash;
        if (key != NULL &&
            key != dummy) {
            Py_INCREF(key);
            if (set_insert_key(so, key, hash) == -1) {
                Py_DECREF(key);
                return -1;
            }
        }
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_new ( PyTypeObject type,
PyObject args,
PyObject kwds 
) [static]

Definition at line 1094 of file setobject.c.

{
    if (type == &PySet_Type && !_PyArg_NoKeywords("set()", kwds))
        return NULL;

    return make_new_set(type, NULL);
}

Here is the call graph for this function:

static int set_next ( PySetObject *  so,
Py_ssize_t pos_ptr,
setentry **  entry_ptr 
) [static]

Definition at line 533 of file setobject.c.

{
    Py_ssize_t i;
    Py_ssize_t mask;
    register setentry *table;

    assert (PyAnySet_Check(so));
    i = *pos_ptr;
    assert(i >= 0);
    table = so->table;
    mask = so->mask;
    while (i <= mask && (table[i].key == NULL || table[i].key == dummy))
        i++;
    *pos_ptr = i+1;
    if (i > mask)
        return 0;
    assert(table[i].key != NULL);
    *entry_ptr = &table[i];
    return 1;
}

Here is the caller graph for this function:

static PyObject* set_or ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1209 of file setobject.c.

{
    PySetObject *result;

    if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    result = (PySetObject *)set_copy(so);
    if (result == NULL)
        return NULL;
    if ((PyObject *)so == other)
        return (PyObject *)result;
    if (set_update_internal(result, other) == -1) {
        Py_DECREF(result);
        return NULL;
    }
    return (PyObject *)result;
}

Here is the call graph for this function:

static PyObject* set_pop ( PySetObject *  so) [static]

Definition at line 711 of file setobject.c.

{
    register Py_ssize_t i = 0;
    register setentry *entry;
    PyObject *key;

    assert (PyAnySet_Check(so));
    if (so->used == 0) {
        PyErr_SetString(PyExc_KeyError, "pop from an empty set");
        return NULL;
    }

    /* Set entry to "the first" unused or dummy set entry.  We abuse
     * the hash field of slot 0 to hold a search finger:
     * If slot 0 has a value, use slot 0.
     * Else slot 0 is being used to hold a search finger,
     * and we use its hash value as the first index to look.
     */
    entry = &so->table[0];
    if (entry->key == NULL || entry->key == dummy) {
        i = entry->hash;
        /* The hash field may be a real hash value, or it may be a
         * legit search finger, or it may be a once-legit search
         * finger that's out of bounds now because it wrapped around
         * or the table shrunk -- simply make sure it's in bounds now.
         */
        if (i > so->mask || i < 1)
            i = 1;              /* skip slot 0 */
        while ((entry = &so->table[i])->key == NULL || entry->key==dummy) {
            i++;
            if (i > so->mask)
                i = 1;
        }
    }
    key = entry->key;
    Py_INCREF(dummy);
    entry->key = dummy;
    so->used--;
    so->table[0].hash = i + 1;  /* next place to start */
    return key;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_reduce ( PySetObject *  so) [static]

Definition at line 1958 of file setobject.c.

{
    PyObject *keys=NULL, *args=NULL, *result=NULL, *dict=NULL;

    keys = PySequence_List((PyObject *)so);
    if (keys == NULL)
        goto done;
    args = PyTuple_Pack(1, keys);
    if (args == NULL)
        goto done;
    dict = PyObject_GetAttrString((PyObject *)so, "__dict__");
    if (dict == NULL) {
        PyErr_Clear();
        dict = Py_None;
        Py_INCREF(dict);
    }
    result = PyTuple_Pack(3, Py_TYPE(so), args, dict);
done:
    Py_XDECREF(args);
    Py_XDECREF(keys);
    Py_XDECREF(dict);
    return result;
}

Here is the call graph for this function:

static PyObject* set_remove ( PySetObject *  so,
PyObject key 
) [static]

Definition at line 1900 of file setobject.c.

{
    PyObject *tmpkey;
    int rv;

    rv = set_discard_key(so, key);
    if (rv == -1) {
        if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError))
            return NULL;
        PyErr_Clear();
        tmpkey = make_new_set(&PyFrozenSet_Type, key);
        if (tmpkey == NULL)
            return NULL;
        rv = set_discard_key(so, tmpkey);
        Py_DECREF(tmpkey);
        if (rv == -1)
            return NULL;
    }

    if (rv == DISCARD_NOTFOUND) {
        set_key_error(key);
        return NULL;
    }
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* set_repr ( PySetObject *  so) [static]

Definition at line 580 of file setobject.c.

{
    PyObject *keys, *result=NULL;
    Py_UNICODE *u;
    int status = Py_ReprEnter((PyObject*)so);
    PyObject *listrepr;
    Py_ssize_t newsize;

    if (status != 0) {
        if (status < 0)
            return NULL;
        return PyUnicode_FromFormat("%s(...)", Py_TYPE(so)->tp_name);
    }

    /* shortcut for the empty set */
    if (!so->used) {
        Py_ReprLeave((PyObject*)so);
        return PyUnicode_FromFormat("%s()", Py_TYPE(so)->tp_name);
    }

    keys = PySequence_List((PyObject *)so);
    if (keys == NULL)
        goto done;

    listrepr = PyObject_Repr(keys);
    Py_DECREF(keys);
    if (listrepr == NULL)
        goto done;
    newsize = PyUnicode_GET_SIZE(listrepr);
    result = PyUnicode_FromUnicode(NULL, newsize);
    if (result) {
        u = PyUnicode_AS_UNICODE(result);
        *u++ = '{';
        /* Omit the brackets from the listrepr */
        Py_UNICODE_COPY(u, PyUnicode_AS_UNICODE(listrepr)+1,
                           PyUnicode_GET_SIZE(listrepr)-2);
        u += newsize-2;
        *u++ = '}';
    }
    Py_DECREF(listrepr);
    if (Py_TYPE(so) != &PySet_Type) {
        PyObject *tmp = PyUnicode_FromFormat("%s(%U)",
                                             Py_TYPE(so)->tp_name,
                                             result);
        Py_DECREF(result);
        result = tmp;
    }
done:
    Py_ReprLeave((PyObject*)so);
    return result;
}

Here is the call graph for this function:

static PyObject* set_richcompare ( PySetObject *  v,
PyObject w,
int  op 
) [static]

Definition at line 1812 of file setobject.c.

{
    PyObject *r1, *r2;

    if(!PyAnySet_Check(w)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    switch (op) {
    case Py_EQ:
        if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w))
            Py_RETURN_FALSE;
        if (v->hash != -1  &&
            ((PySetObject *)w)->hash != -1 &&
            v->hash != ((PySetObject *)w)->hash)
            Py_RETURN_FALSE;
        return set_issubset(v, w);
    case Py_NE:
        r1 = set_richcompare(v, w, Py_EQ);
        if (r1 == NULL)
            return NULL;
        r2 = PyBool_FromLong(PyObject_Not(r1));
        Py_DECREF(r1);
        return r2;
    case Py_LE:
        return set_issubset(v, w);
    case Py_GE:
        return set_issuperset(v, w);
    case Py_LT:
        if (PySet_GET_SIZE(v) >= PySet_GET_SIZE(w))
            Py_RETURN_FALSE;
        return set_issubset(v, w);
    case Py_GT:
        if (PySet_GET_SIZE(v) <= PySet_GET_SIZE(w))
            Py_RETURN_FALSE;
        return set_issuperset(v, w);
    }
    Py_INCREF(Py_NotImplemented);
    return Py_NotImplemented;
}

Here is the call graph for this function:

static PyObject* set_sizeof ( PySetObject *  so) [static]

Definition at line 1985 of file setobject.c.

{
    Py_ssize_t res;

    res = sizeof(PySetObject);
    if (so->table != so->smalltable)
        res = res + (so->mask + 1) * sizeof(setentry);
    return PyLong_FromSsize_t(res);
}
static PyObject* set_sub ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1626 of file setobject.c.

{
    if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    return set_difference(so, other);
}

Here is the call graph for this function:

static void set_swap_bodies ( PySetObject *  a,
PySetObject *  b 
) [static]

Definition at line 1116 of file setobject.c.

{
    Py_ssize_t t;
    setentry *u;
    setentry *(*f)(PySetObject *so, PyObject *key, Py_ssize_t hash);
    setentry tab[PySet_MINSIZE];
    Py_hash_t h;

    t = a->fill;     a->fill   = b->fill;        b->fill  = t;
    t = a->used;     a->used   = b->used;        b->used  = t;
    t = a->mask;     a->mask   = b->mask;        b->mask  = t;

    u = a->table;
    if (a->table == a->smalltable)
        u = b->smalltable;
    a->table  = b->table;
    if (b->table == b->smalltable)
        a->table = a->smalltable;
    b->table = u;

    f = a->lookup;   a->lookup = b->lookup;      b->lookup = f;

    if (a->table == a->smalltable || b->table == b->smalltable) {
        memcpy(tab, a->smalltable, sizeof(tab));
        memcpy(a->smalltable, b->smalltable, sizeof(tab));
        memcpy(b->smalltable, tab, sizeof(tab));
    }

    if (PyType_IsSubtype(Py_TYPE(a), &PyFrozenSet_Type)  &&
        PyType_IsSubtype(Py_TYPE(b), &PyFrozenSet_Type)) {
        h = a->hash;     a->hash = b->hash;  b->hash = h;
    } else {
        a->hash = -1;
        b->hash = -1;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_symmetric_difference ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1716 of file setobject.c.

{
    PyObject *rv;
    PySetObject *otherset;

    otherset = (PySetObject *)make_new_set_basetype(Py_TYPE(so), other);
    if (otherset == NULL)
        return NULL;
    rv = set_symmetric_difference_update(otherset, (PyObject *)so);
    if (rv == NULL)
        return NULL;
    Py_DECREF(rv);
    return (PyObject *)otherset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_symmetric_difference_update ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1649 of file setobject.c.

{
    PySetObject *otherset;
    PyObject *key;
    Py_ssize_t pos = 0;
    setentry *entry;

    if ((PyObject *)so == other)
        return set_clear(so);

    if (PyDict_CheckExact(other)) {
        PyObject *value;
        int rv;
        Py_hash_t hash;
        while (_PyDict_Next(other, &pos, &key, &value, &hash)) {
            setentry an_entry;

            Py_INCREF(key);
            an_entry.hash = hash;
            an_entry.key = key;

            rv = set_discard_entry(so, &an_entry);
            if (rv == -1) {
                Py_DECREF(key);
                return NULL;
            }
            if (rv == DISCARD_NOTFOUND) {
                if (set_add_entry(so, &an_entry) == -1) {
                    Py_DECREF(key);
                    return NULL;
                }
            }
            Py_DECREF(key);
        }
        Py_RETURN_NONE;
    }

    if (PyAnySet_Check(other)) {
        Py_INCREF(other);
        otherset = (PySetObject *)other;
    } else {
        otherset = (PySetObject *)make_new_set_basetype(Py_TYPE(so), other);
        if (otherset == NULL)
            return NULL;
    }

    while (set_next(otherset, &pos, &entry)) {
        int rv = set_discard_entry(so, entry);
        if (rv == -1) {
            Py_DECREF(otherset);
            return NULL;
        }
        if (rv == DISCARD_NOTFOUND) {
            if (set_add_entry(so, entry) == -1) {
                Py_DECREF(otherset);
                return NULL;
            }
        }
    }
    Py_DECREF(otherset);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int set_table_resize ( PySetObject *  so,
Py_ssize_t  minused 
) [static]

Definition at line 277 of file setobject.c.

{
    Py_ssize_t newsize;
    setentry *oldtable, *newtable, *entry;
    Py_ssize_t i;
    int is_oldtable_malloced;
    setentry small_copy[PySet_MINSIZE];

    assert(minused >= 0);

    /* Find the smallest table size > minused. */
    for (newsize = PySet_MINSIZE;
         newsize <= minused && newsize > 0;
         newsize <<= 1)
        ;
    if (newsize <= 0) {
        PyErr_NoMemory();
        return -1;
    }

    /* Get space for a new table. */
    oldtable = so->table;
    assert(oldtable != NULL);
    is_oldtable_malloced = oldtable != so->smalltable;

    if (newsize == PySet_MINSIZE) {
        /* A large table is shrinking, or we can't get any smaller. */
        newtable = so->smalltable;
        if (newtable == oldtable) {
            if (so->fill == so->used) {
                /* No dummies, so no point doing anything. */
                return 0;
            }
            /* We're not going to resize it, but rebuild the
               table anyway to purge old dummy entries.
               Subtle:  This is *necessary* if fill==size,
               as set_lookkey needs at least one virgin slot to
               terminate failing searches.  If fill < size, it's
               merely desirable, as dummies slow searches. */
            assert(so->fill > so->used);
            memcpy(small_copy, oldtable, sizeof(small_copy));
            oldtable = small_copy;
        }
    }
    else {
        newtable = PyMem_NEW(setentry, newsize);
        if (newtable == NULL) {
            PyErr_NoMemory();
            return -1;
        }
    }

    /* Make the set empty, using the new table. */
    assert(newtable != oldtable);
    so->table = newtable;
    so->mask = newsize - 1;
    memset(newtable, 0, sizeof(setentry) * newsize);
    so->used = 0;
    i = so->fill;
    so->fill = 0;

    /* Copy the data over; this is refcount-neutral for active entries;
       dummy entries aren't copied over, of course */
    for (entry = oldtable; i > 0; entry++) {
        if (entry->key == NULL) {
            /* UNUSED */
            ;
        } else if (entry->key == dummy) {
            /* DUMMY */
            --i;
            assert(entry->key == dummy);
            Py_DECREF(entry->key);
        } else {
            /* ACTIVE */
            --i;
            set_insert_clean(so, entry->key, entry->hash);
        }
    }

    if (is_oldtable_malloced)
        PyMem_DEL(oldtable);
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int set_traverse ( PySetObject *  so,
visitproc  visit,
void arg 
) [static]

Definition at line 757 of file setobject.c.

{
    Py_ssize_t pos = 0;
    setentry *entry;

    while (set_next(so, &pos, &entry))
        Py_VISIT(entry->key);
    return 0;
}

Here is the call graph for this function:

static PyObject* set_union ( PySetObject *  so,
PyObject args 
) [static]

Definition at line 1181 of file setobject.c.

{
    PySetObject *result;
    PyObject *other;
    Py_ssize_t i;

    result = (PySetObject *)set_copy(so);
    if (result == NULL)
        return NULL;

    for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
        other = PyTuple_GET_ITEM(args, i);
        if ((PyObject *)so == other)
            continue;
        if (set_update_internal(result, other) == -1) {
            Py_DECREF(result);
            return NULL;
        }
    }
    return (PyObject *)result;
}

Here is the call graph for this function:

static PyObject* set_update ( PySetObject *  so,
PyObject args 
) [static]

Definition at line 975 of file setobject.c.

{
    Py_ssize_t i;

    for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
        PyObject *other = PyTuple_GET_ITEM(args, i);
        if (set_update_internal(so, other) == -1)
            return NULL;
    }
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static int set_update_internal ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 922 of file setobject.c.

{
    PyObject *key, *it;

    if (PyAnySet_Check(other))
        return set_merge(so, other);

    if (PyDict_CheckExact(other)) {
        PyObject *value;
        Py_ssize_t pos = 0;
        Py_hash_t hash;
        Py_ssize_t dictsize = PyDict_Size(other);

        /* Do one big resize at the start, rather than
        * incrementally resizing as we insert new keys.  Expect
        * that there will be no (or few) overlapping keys.
        */
        if (dictsize == -1)
            return -1;
        if ((so->fill + dictsize)*3 >= (so->mask+1)*2) {
            if (set_table_resize(so, (so->used + dictsize)*2) != 0)
                return -1;
        }
        while (_PyDict_Next(other, &pos, &key, &value, &hash)) {
            setentry an_entry;

            an_entry.hash = hash;
            an_entry.key = key;
            if (set_add_entry(so, &an_entry) == -1)
                return -1;
        }
        return 0;
    }

    it = PyObject_GetIter(other);
    if (it == NULL)
        return -1;

    while ((key = PyIter_Next(it)) != NULL) {
        if (set_add_key(so, key) == -1) {
            Py_DECREF(it);
            Py_DECREF(key);
            return -1;
        }
        Py_DECREF(key);
    }
    Py_DECREF(it);
    if (PyErr_Occurred())
        return -1;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_xor ( PySetObject *  so,
PyObject other 
) [static]

Definition at line 1737 of file setobject.c.

{
    if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    return set_symmetric_difference(so, other);
}

Here is the call graph for this function:

static void setiter_dealloc ( setiterobject si) [static]

Definition at line 806 of file setobject.c.

Here is the call graph for this function:

static PyObject* setiter_iternext ( setiterobject si) [static]

Definition at line 835 of file setobject.c.

{
    PyObject *key;
    register Py_ssize_t i, mask;
    register setentry *entry;
    PySetObject *so = si->si_set;

    if (so == NULL)
        return NULL;
    assert (PyAnySet_Check(so));

    if (si->si_used != so->used) {
        PyErr_SetString(PyExc_RuntimeError,
                        "Set changed size during iteration");
        si->si_used = -1; /* Make this state sticky */
        return NULL;
    }

    i = si->si_pos;
    assert(i>=0);
    entry = so->table;
    mask = so->mask;
    while (i <= mask && (entry[i].key == NULL || entry[i].key == dummy))
        i++;
    si->si_pos = i+1;
    if (i > mask)
        goto fail;
    si->len--;
    key = entry[i].key;
    Py_INCREF(key);
    return key;

fail:
    Py_DECREF(so);
    si->si_set = NULL;
    return NULL;
}

Here is the call graph for this function:

static PyObject* setiter_len ( setiterobject si) [static]

Definition at line 820 of file setobject.c.

{
    Py_ssize_t len = 0;
    if (si->si_set != NULL && si->si_used == si->si_set->used)
        len = si->len;
    return PyLong_FromSsize_t(len);
}
static int setiter_traverse ( setiterobject si,
visitproc  visit,
void arg 
) [static]

Definition at line 813 of file setobject.c.

{
    Py_VISIT(si->si_set);
    return 0;
}

Variable Documentation

PyObject* dummy = NULL [static]

Definition at line 32 of file setobject.c.

Definition at line 1045 of file setobject.c.

PySetObject* free_list[PySet_MAXFREELIST] [static]

Definition at line 58 of file setobject.c.

Initial value:
 {
    0,                                  
    (binaryfunc)set_sub,                
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    (binaryfunc)set_and,                
    (binaryfunc)set_xor,                
    (binaryfunc)set_or,                 
}

Definition at line 2193 of file setobject.c.

Initial value:
 {
    {"__contains__",(PyCFunction)set_direct_contains,           METH_O | METH_COEXIST,
     contains_doc},
    {"copy",            (PyCFunction)frozenset_copy,    METH_NOARGS,
     copy_doc},
    {"difference",      (PyCFunction)set_difference_multi,      METH_VARARGS,
     difference_doc},
    {"intersection",(PyCFunction)set_intersection_multi,        METH_VARARGS,
     intersection_doc},
    {"isdisjoint",      (PyCFunction)set_isdisjoint,    METH_O,
     isdisjoint_doc},
    {"issubset",        (PyCFunction)set_issubset,      METH_O,
     issubset_doc},
    {"issuperset",      (PyCFunction)set_issuperset,    METH_O,
     issuperset_doc},
    {"__reduce__",      (PyCFunction)set_reduce,        METH_NOARGS,
     reduce_doc},
    {"__sizeof__",      (PyCFunction)set_sizeof,        METH_NOARGS,
     sizeof_doc},
    {"symmetric_difference",(PyCFunction)set_symmetric_difference,      METH_O,
     symmetric_difference_doc},
    {"union",           (PyCFunction)set_union,         METH_VARARGS,
     union_doc},
    {NULL,              NULL}   
}

Definition at line 2167 of file setobject.c.

int numfree = 0 [static]

Definition at line 59 of file setobject.c.

Definition at line 2218 of file setobject.c.

Definition at line 2120 of file setobject.c.

Definition at line 873 of file setobject.c.

Definition at line 2082 of file setobject.c.

Initial value:
 {
    set_len,                            
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    0,                                  
    (objobjproc)set_contains,           
}

Definition at line 2014 of file setobject.c.

Definition at line 2034 of file setobject.c.

Initial value:
 {
    {"__length_hint__", (PyCFunction)setiter_len, METH_NOARGS, length_hint_doc},
    {NULL,              NULL}           
}

Definition at line 830 of file setobject.c.