Lines Matching full:so
11 * tuple automatically so that tuple keys are not unpacked as the
38 #define INIT_NONZERO_SET_SLOTS(so) do { \ argument
39 (so)->table = (so)->smalltable; \
40 (so)->mask = PySet_MINSIZE - 1; \
41 (so)->hash = -1; \
44 #define EMPTY_TO_MINSIZE(so) do { \ argument
45 memset((so)->smalltable, 0, sizeof((so)->smalltable)); \
46 (so)->used = (so)->fill = 0; \
47 INIT_NONZERO_SET_SLOTS(so); \
73 set_lookkey(PySetObject *so, PyObject *key, register long hash) in set_lookkey() argument
78 register size_t mask = so->mask; in set_lookkey()
79 setentry *table = so->table; in set_lookkey()
99 if (table == so->table && entry->key == startkey) { in set_lookkey()
107 return set_lookkey(so, key, hash); in set_lookkey()
114 least likely outcome, so test for that last. */ in set_lookkey()
132 if (table == so->table && entry->key == startkey) { in set_lookkey()
140 return set_lookkey(so, key, hash); in set_lookkey()
155 set_lookkey_string(PySetObject *so, PyObject *key, register long hash) in set_lookkey_string() argument
160 register size_t mask = so->mask; in set_lookkey_string()
161 setentry *table = so->table; in set_lookkey_string()
169 so->lookup = set_lookkey; in set_lookkey_string()
170 return set_lookkey(so, key, hash); in set_lookkey_string()
185 least likely outcome, so test for that last. */ in set_lookkey_string()
209 set_insert_key(register PySetObject *so, PyObject *key, long hash) in set_insert_key() argument
213 assert(so->lookup != NULL); in set_insert_key()
214 entry = so->lookup(so, key, hash); in set_insert_key()
219 so->fill++; in set_insert_key()
222 so->used++; in set_insert_key()
227 so->used++; in set_insert_key()
245 set_insert_clean(register PySetObject *so, PyObject *key, long hash) in set_insert_clean() argument
249 register size_t mask = (size_t)so->mask; in set_insert_clean()
250 setentry *table = so->table; in set_insert_clean()
259 so->fill++; in set_insert_clean()
262 so->used++; in set_insert_clean()
271 set_table_resize(PySetObject *so, Py_ssize_t minused) in set_table_resize() argument
292 oldtable = so->table; in set_table_resize()
294 is_oldtable_malloced = oldtable != so->smalltable; in set_table_resize()
298 newtable = so->smalltable; in set_table_resize()
300 if (so->fill == so->used) { in set_table_resize()
301 /* No dummies, so no point doing anything. */ in set_table_resize()
310 assert(so->fill > so->used); in set_table_resize()
325 so->table = newtable; in set_table_resize()
326 so->mask = newsize - 1; in set_table_resize()
328 so->used = 0; in set_table_resize()
329 i = so->fill; in set_table_resize()
330 so->fill = 0; in set_table_resize()
346 set_insert_clean(so, entry->key, entry->hash); in set_table_resize()
358 set_add_entry(register PySetObject *so, setentry *entry) in set_add_entry() argument
364 assert(so->fill <= so->mask); /* at least one empty slot */ in set_add_entry()
365 n_used = so->used; in set_add_entry()
367 if (set_insert_key(so, key, hash) == -1) { in set_add_entry()
371 if (!(so->used > n_used && so->fill*3 >= (so->mask+1)*2)) in set_add_entry()
373 return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4); in set_add_entry()
377 set_add_key(register PySetObject *so, PyObject *key) in set_add_key() argument
388 assert(so->fill <= so->mask); /* at least one empty slot */ in set_add_key()
389 n_used = so->used; in set_add_key()
391 if (set_insert_key(so, key, hash) == -1) { in set_add_key()
395 if (!(so->used > n_used && so->fill*3 >= (so->mask+1)*2)) in set_add_key()
397 return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4); in set_add_key()
404 set_discard_entry(PySetObject *so, setentry *oldentry) in set_discard_entry() argument
408 entry = (so->lookup)(so, oldentry->key, oldentry->hash); in set_discard_entry()
416 so->used--; in set_discard_entry()
422 set_discard_key(PySetObject *so, PyObject *key) in set_discard_key() argument
428 assert (PyAnySet_Check(so)); in set_discard_key()
435 entry = (so->lookup)(so, key, hash); in set_discard_key()
443 so->used--; in set_discard_key()
449 set_clear_internal(PySetObject *so) in set_clear_internal() argument
457 assert (PyAnySet_Check(so)); in set_clear_internal()
459 n = so->mask + 1; in set_clear_internal()
463 table = so->table; in set_clear_internal()
465 table_is_malloced = table != so->smalltable; in set_clear_internal()
470 * clearing the slots, and never refer to anything via so->ref while in set_clear_internal()
473 fill = so->fill; in set_clear_internal()
475 EMPTY_TO_MINSIZE(so); in set_clear_internal()
484 EMPTY_TO_MINSIZE(so); in set_clear_internal()
490 * has unique access to it, so decref side-effects can't alter it. in set_clear_internal()
513 * Iterate over a set table. Use like so:
526 set_next(PySetObject *so, Py_ssize_t *pos_ptr, setentry **entry_ptr) in set_next() argument
532 assert (PyAnySet_Check(so)); in set_next()
535 table = so->table; in set_next()
536 mask = so->mask; in set_next()
548 set_dealloc(PySetObject *so) in set_dealloc() argument
551 Py_ssize_t fill = so->fill; in set_dealloc()
553 PyObject_GC_UnTrack(so); in set_dealloc()
554 Py_TRASHCAN_SAFE_BEGIN(so) in set_dealloc()
555 if (so->weakreflist != NULL) in set_dealloc()
556 PyObject_ClearWeakRefs((PyObject *) so); in set_dealloc()
558 for (entry = so->table; fill > 0; entry++) { in set_dealloc()
564 if (so->table != so->smalltable) in set_dealloc()
565 PyMem_DEL(so->table); in set_dealloc()
566 if (numfree < PySet_MAXFREELIST && PyAnySet_CheckExact(so)) in set_dealloc()
567 free_list[numfree++] = so; in set_dealloc()
569 Py_TYPE(so)->tp_free(so); in set_dealloc()
570 Py_TRASHCAN_SAFE_END(so) in set_dealloc()
574 set_tp_print(PySetObject *so, FILE *fp, int flags) in set_tp_print() argument
580 int status = Py_ReprEnter((PyObject*)so); in set_tp_print()
586 fprintf(fp, "%s(...)", Py_TYPE(so)->tp_name); in set_tp_print()
592 fprintf(fp, "%s([", Py_TYPE(so)->tp_name); in set_tp_print()
594 while (set_next(so, &pos, &entry)) { in set_tp_print()
600 Py_ReprLeave((PyObject*)so); in set_tp_print()
607 Py_ReprLeave((PyObject*)so); in set_tp_print()
612 set_repr(PySetObject *so) in set_repr() argument
615 int status = Py_ReprEnter((PyObject*)so); in set_repr()
620 return PyString_FromFormat("%s(...)", Py_TYPE(so)->tp_name); in set_repr()
623 keys = PySequence_List((PyObject *)so); in set_repr()
631 result = PyString_FromFormat("%s(%s)", Py_TYPE(so)->tp_name, in set_repr()
635 Py_ReprLeave((PyObject*)so); in set_repr()
640 set_len(PyObject *so) in set_len() argument
642 return ((PySetObject *)so)->used; in set_len()
646 set_merge(PySetObject *so, PyObject *otherset) in set_merge() argument
654 assert (PyAnySet_Check(so)); in set_merge()
658 if (other == so || other->used == 0) in set_merge()
665 if ((so->fill + other->used)*3 >= (so->mask+1)*2) { in set_merge()
666 if (set_table_resize(so, (so->used + other->used)*2) != 0) in set_merge()
676 if (set_insert_key(so, key, hash) == -1) { in set_merge()
686 set_contains_key(PySetObject *so, PyObject *key) in set_contains_key() argument
697 entry = (so->lookup)(so, key, hash); in set_contains_key()
705 set_contains_entry(PySetObject *so, setentry *entry) in set_contains_entry() argument
710 lu_entry = (so->lookup)(so, entry->key, entry->hash); in set_contains_entry()
718 set_pop(PySetObject *so) in set_pop() argument
724 assert (PyAnySet_Check(so)); in set_pop()
725 if (so->used == 0) { in set_pop()
736 entry = &so->table[0]; in set_pop()
744 if (i > so->mask || i < 1) in set_pop()
746 while ((entry = &so->table[i])->key == NULL || entry->key==dummy) { in set_pop()
748 if (i > so->mask) in set_pop()
755 so->used--; in set_pop()
756 so->table[0].hash = i + 1; /* next place to start */ in set_pop()
764 set_traverse(PySetObject *so, visitproc visit, void *arg) in set_traverse() argument
769 while (set_next(so, &pos, &entry)) in set_traverse()
777 PySetObject *so = (PySetObject *)self; in frozenset_hash() local
782 if (so->hash != -1) in frozenset_hash()
783 return so->hash; in frozenset_hash()
786 while (set_next(so, &pos, &entry)) { in frozenset_hash()
790 hashes so that many distinct combinations collapse to only in frozenset_hash()
798 so->hash = hash; in frozenset_hash()
849 PySetObject *so = si->si_set; in setiter_iternext() local
851 if (so == NULL) in setiter_iternext()
853 assert (PyAnySet_Check(so)); in setiter_iternext()
855 if (si->si_used != so->used) { in setiter_iternext()
864 entry = so->table; in setiter_iternext()
865 mask = so->mask; in setiter_iternext()
878 Py_DECREF(so); in setiter_iternext()
916 set_iter(PySetObject *so) in set_iter() argument
921 Py_INCREF(so); in set_iter()
922 si->si_set = so; in set_iter()
923 si->si_used = so->used; in set_iter()
925 si->len = so->used; in set_iter()
931 set_update_internal(PySetObject *so, PyObject *other) in set_update_internal() argument
936 return set_merge(so, other); in set_update_internal()
950 if ((so->fill + dictsize)*3 >= (so->mask+1)*2) { in set_update_internal()
951 if (set_table_resize(so, (so->used + dictsize)*2) != 0) in set_update_internal()
959 if (set_add_entry(so, &an_entry) == -1) in set_update_internal()
970 if (set_add_key(so, key) == -1) { in set_update_internal()
984 set_update(PySetObject *so, PyObject *args) in set_update() argument
990 if (set_update_internal(so, other) == -1) in set_update()
1002 register PySetObject *so = NULL; in make_new_set() local
1013 so = free_list[--numfree]; in make_new_set()
1014 assert (so != NULL && PyAnySet_CheckExact(so)); in make_new_set()
1015 Py_TYPE(so) = type; in make_new_set()
1016 _Py_NewReference((PyObject *)so); in make_new_set()
1017 EMPTY_TO_MINSIZE(so); in make_new_set()
1018 PyObject_GC_Track(so); in make_new_set()
1020 so = (PySetObject *)type->tp_alloc(type, 0); in make_new_set()
1021 if (so == NULL) in make_new_set()
1024 assert(so->table == NULL && so->fill == 0 && so->used == 0); in make_new_set()
1025 INIT_NONZERO_SET_SLOTS(so); in make_new_set()
1028 so->lookup = set_lookkey_string; in make_new_set()
1029 so->weakreflist = NULL; in make_new_set()
1032 if (set_update_internal(so, iterable) == -1) { in make_new_set()
1033 Py_DECREF(so); in make_new_set()
1038 return (PyObject *)so; in make_new_set()
1079 PySetObject *so; in PySet_Fini() local
1083 so = free_list[numfree]; in PySet_Fini()
1084 PyObject_GC_Del(so); in PySet_Fini()
1117 setentry *(*f)(PySetObject *so, PyObject *key, long hash); in set_swap_bodies()
1151 set_copy(PySetObject *so) in set_copy() argument
1153 return make_new_set(Py_TYPE(so), (PyObject *)so); in set_copy()
1157 frozenset_copy(PySetObject *so) in frozenset_copy() argument
1159 if (PyFrozenSet_CheckExact(so)) { in frozenset_copy()
1160 Py_INCREF(so); in frozenset_copy()
1161 return (PyObject *)so; in frozenset_copy()
1163 return set_copy(so); in frozenset_copy()
1169 set_clear(PySetObject *so) in set_clear() argument
1171 set_clear_internal(so); in set_clear()
1178 set_union(PySetObject *so, PyObject *args) in set_union() argument
1184 result = (PySetObject *)set_copy(so); in set_union()
1190 if ((PyObject *)so == other) in set_union()
1206 set_or(PySetObject *so, PyObject *other) in set_or() argument
1210 if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) { in set_or()
1215 result = (PySetObject *)set_copy(so); in set_or()
1218 if ((PyObject *)so == other) in set_or()
1228 set_ior(PySetObject *so, PyObject *other) in set_ior() argument
1234 if (set_update_internal(so, other) == -1) in set_ior()
1236 Py_INCREF(so); in set_ior()
1237 return (PyObject *)so; in set_ior()
1241 set_intersection(PySetObject *so, PyObject *other) in set_intersection() argument
1246 if ((PyObject *)so == other) in set_intersection()
1247 return set_copy(so); in set_intersection()
1249 result = (PySetObject *)make_new_set(Py_TYPE(so), NULL); in set_intersection()
1257 if (PySet_GET_SIZE(other) > PySet_GET_SIZE(so)) { in set_intersection()
1258 tmp = (PyObject *)so; in set_intersection()
1259 so = (PySetObject *)other; in set_intersection()
1264 int rv = set_contains_entry(so, entry); in set_intersection()
1298 rv = set_contains_entry(so, &entry); in set_intersection()
1324 set_intersection_multi(PySetObject *so, PyObject *args) in set_intersection_multi() argument
1327 PyObject *result = (PyObject *)so; in set_intersection_multi()
1330 return set_copy(so); in set_intersection_multi()
1332 Py_INCREF(so); in set_intersection_multi()
1352 set_intersection_update(PySetObject *so, PyObject *other) in set_intersection_update() argument
1356 tmp = set_intersection(so, other); in set_intersection_update()
1359 set_swap_bodies(so, (PySetObject *)tmp); in set_intersection_update()
1365 set_intersection_update_multi(PySetObject *so, PyObject *args) in set_intersection_update_multi() argument
1369 tmp = set_intersection_multi(so, args); in set_intersection_update_multi()
1372 set_swap_bodies(so, (PySetObject *)tmp); in set_intersection_update_multi()
1381 set_and(PySetObject *so, PyObject *other) in set_and() argument
1383 if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) { in set_and()
1387 return set_intersection(so, other); in set_and()
1391 set_iand(PySetObject *so, PyObject *other) in set_iand() argument
1399 result = set_intersection_update(so, other); in set_iand()
1403 Py_INCREF(so); in set_iand()
1404 return (PyObject *)so; in set_iand()
1408 set_isdisjoint(PySetObject *so, PyObject *other) in set_isdisjoint() argument
1412 if ((PyObject *)so == other) { in set_isdisjoint()
1413 if (PySet_GET_SIZE(so) == 0) in set_isdisjoint()
1423 if (PySet_GET_SIZE(other) > PySet_GET_SIZE(so)) { in set_isdisjoint()
1424 tmp = (PyObject *)so; in set_isdisjoint()
1425 so = (PySetObject *)other; in set_isdisjoint()
1429 int rv = set_contains_entry(so, entry); in set_isdisjoint()
1454 rv = set_contains_entry(so, &entry); in set_isdisjoint()
1475 set_difference_update_internal(PySetObject *so, PyObject *other) in set_difference_update_internal() argument
1477 if ((PyObject *)so == other) in set_difference_update_internal()
1478 return set_clear_internal(so); in set_difference_update_internal()
1485 if (set_discard_entry(so, entry) == -1) in set_difference_update_internal()
1494 if (set_discard_key(so, key) == -1) { in set_difference_update_internal()
1506 if ((so->fill - so->used) * 5 < so->mask) in set_difference_update_internal()
1508 return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4); in set_difference_update_internal()
1512 set_difference_update(PySetObject *so, PyObject *args) in set_difference_update() argument
1518 if (set_difference_update_internal(so, other) == -1) in set_difference_update()
1528 set_difference(PySetObject *so, PyObject *other) in set_difference() argument
1535 result = set_copy(so); in set_difference()
1544 result = make_new_set(Py_TYPE(so), NULL); in set_difference()
1549 while (set_next(so, &pos, &entry)) { in set_difference()
1569 while (set_next(so, &pos, &entry)) { in set_difference()
1586 set_difference_multi(PySetObject *so, PyObject *args) in set_difference_multi() argument
1592 return set_copy(so); in set_difference_multi()
1595 result = set_difference(so, other); in set_difference_multi()
1614 set_sub(PySetObject *so, PyObject *other) in set_sub() argument
1616 if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) { in set_sub()
1620 return set_difference(so, other); in set_sub()
1624 set_isub(PySetObject *so, PyObject *other) in set_isub() argument
1630 if (set_difference_update_internal(so, other) == -1) in set_isub()
1632 Py_INCREF(so); in set_isub()
1633 return (PyObject *)so; in set_isub()
1637 set_symmetric_difference_update(PySetObject *so, PyObject *other) in set_symmetric_difference_update() argument
1644 if ((PyObject *)so == other) in set_symmetric_difference_update()
1645 return set_clear(so); in set_symmetric_difference_update()
1658 rv = set_discard_entry(so, &an_entry); in set_symmetric_difference_update()
1664 if (set_add_entry(so, &an_entry) == -1) { in set_symmetric_difference_update()
1678 otherset = (PySetObject *)make_new_set(Py_TYPE(so), other); in set_symmetric_difference_update()
1684 int rv = set_discard_entry(so, entry); in set_symmetric_difference_update()
1690 if (set_add_entry(so, entry) == -1) { in set_symmetric_difference_update()
1704 set_symmetric_difference(PySetObject *so, PyObject *other) in set_symmetric_difference() argument
1709 otherset = (PySetObject *)make_new_set(Py_TYPE(so), other); in set_symmetric_difference()
1712 rv = set_symmetric_difference_update(otherset, (PyObject *)so); in set_symmetric_difference()
1727 set_xor(PySetObject *so, PyObject *other) in set_xor() argument
1729 if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) { in set_xor()
1733 return set_symmetric_difference(so, other); in set_xor()
1737 set_ixor(PySetObject *so, PyObject *other) in set_ixor() argument
1745 result = set_symmetric_difference_update(so, other); in set_ixor()
1749 Py_INCREF(so); in set_ixor()
1750 return (PyObject *)so; in set_ixor()
1754 set_issubset(PySetObject *so, PyObject *other) in set_issubset() argument
1764 result = set_issubset(so, tmp); in set_issubset()
1768 if (PySet_GET_SIZE(so) > PySet_GET_SIZE(other)) in set_issubset()
1771 while (set_next(so, &pos, &entry)) { in set_issubset()
1784 set_issuperset(PySetObject *so, PyObject *other) in set_issuperset() argument
1792 result = set_issuperset(so, tmp); in set_issuperset()
1796 return set_issubset((PySetObject *)other, (PyObject *)so); in set_issuperset()
1854 set_add(PySetObject *so, PyObject *key) in set_add() argument
1856 if (set_add_key(so, key) == -1) in set_add()
1867 set_contains(PySetObject *so, PyObject *key) in set_contains() argument
1872 rv = set_contains_key(so, key); in set_contains()
1880 rv = set_contains_key(so, tmpkey); in set_contains()
1887 set_direct_contains(PySetObject *so, PyObject *key) in set_direct_contains() argument
1891 result = set_contains(so, key); in set_direct_contains()
1900 set_remove(PySetObject *so, PyObject *key) in set_remove() argument
1905 rv = set_discard_key(so, key); in set_remove()
1913 rv = set_discard_key(so, tmpkey); in set_remove()
1932 set_discard(PySetObject *so, PyObject *key) in set_discard() argument
1937 rv = set_discard_key(so, key); in set_discard()
1945 rv = set_discard_key(so, tmpkey); in set_discard()
1959 set_reduce(PySetObject *so) in set_reduce() argument
1963 keys = PySequence_List((PyObject *)so); in set_reduce()
1969 dict = PyObject_GetAttrString((PyObject *)so, "__dict__"); in set_reduce()
1975 result = PyTuple_Pack(3, Py_TYPE(so), args, dict); in set_reduce()
1986 set_sizeof(PySetObject *so) in set_sizeof() argument
1990 res = _PyObject_SIZE(Py_TYPE(so)); in set_sizeof()
1991 if (so->table != so->smalltable) in set_sizeof()
1992 res = res + (so->mask + 1) * sizeof(setentry); in set_sizeof()
2029 static PyObject *test_c_api(PySetObject *so);
2399 test_c_api(PySetObject *so) in test_c_api() argument
2405 PyObject *ob = (PyObject *)so; in test_c_api()
2413 /* so.clear(); so |= set("abc"); */ in test_c_api()
2417 set_clear_internal(so); in test_c_api()
2418 if (set_update_internal(so, str) == -1) { in test_c_api()