Lines Matching defs:keys

63     Only string (unicode) keys are allowed.
66 DK_ENTRIES(keys)[index] if index >= 0):
102 As a consequence of this, split keys have a maximum size of 16.
161 the list [i << 16 for i in range(20000)] as a set of keys. Since ints are
182 actually *good* in the common cases where hash keys are consecutive. In an
191 is the *same* as the order consecutive keys are likely to arrive. But it's
305 static void free_keys_object(PyDictKeysObject *keys);
330 dictkeys_get_index(const PyDictKeysObject *keys, Py_ssize_t i)
332 int log2size = DK_LOG_SIZE(keys);
336 const int8_t *indices = (const int8_t*)(keys->dk_indices);
340 const int16_t *indices = (const int16_t*)(keys->dk_indices);
345 const int64_t *indices = (const int64_t*)(keys->dk_indices);
350 const int32_t *indices = (const int32_t*)(keys->dk_indices);
359 dictkeys_set_index(PyDictKeysObject *keys, Py_ssize_t i, Py_ssize_t ix)
361 int log2size = DK_LOG_SIZE(keys);
364 assert(keys->dk_version == 0);
367 int8_t *indices = (int8_t*)(keys->dk_indices);
372 int16_t *indices = (int16_t*)(keys->dk_indices);
378 int64_t *indices = (int64_t*)(keys->dk_indices);
383 int32_t *indices = (int32_t*)(keys->dk_indices);
511 PyDictKeysObject *keys = mp->ma_keys;
513 Py_ssize_t usable = USABLE_FRACTION(DK_SIZE(keys));
516 CHECK(0 <= keys->dk_usable && keys->dk_usable <= usable);
517 CHECK(0 <= keys->dk_nentries && keys->dk_nentries <= usable);
518 CHECK(keys->dk_usable + keys->dk_nentries <= usable);
522 CHECK(keys->dk_kind != DICT_KEYS_SPLIT);
523 CHECK(keys->dk_refcnt == 1 || keys == Py_EMPTY_KEYS);
526 CHECK(keys->dk_kind == DICT_KEYS_SPLIT);
531 for (Py_ssize_t i=0; i < DK_SIZE(keys); i++) {
532 Py_ssize_t ix = dictkeys_get_index(keys, i);
536 if (keys->dk_kind == DICT_KEYS_GENERAL) {
537 PyDictKeyEntry *entries = DK_ENTRIES(keys);
555 PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(keys);
656 free_keys_object(PyDictKeysObject *keys)
658 assert(keys != Py_EMPTY_KEYS);
659 if (DK_IS_UNICODE(keys)) {
660 PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(keys);
662 for (i = 0, n = keys->dk_nentries; i < n; i++) {
668 PyDictKeyEntry *entries = DK_ENTRIES(keys);
670 for (i = 0, n = keys->dk_nentries; i < n; i++) {
681 if (DK_LOG_SIZE(keys) == PyDict_LOG_MINSIZE
683 && DK_IS_UNICODE(keys)) {
684 state->keys_free_list[state->keys_numfree++] = keys;
689 PyObject_Free(keys);
715 /* Consumes a reference to the keys object */
717 new_dict(PyDictKeysObject *keys, PyDictValues *values, Py_ssize_t used, int free_values_on_failure)
720 assert(keys != NULL);
739 dictkeys_decref(keys);
746 mp->ma_keys = keys;
755 shared_keys_usable_size(PyDictKeysObject *keys)
757 return keys->dk_nentries + keys->dk_usable;
760 /* Consumes a reference to the keys object */
762 new_dict_with_shared_keys(PyDictKeysObject *keys)
767 size = shared_keys_usable_size(keys);
770 dictkeys_decref(keys);
777 return new_dict(keys, values, 0, 1);
790 PyDictKeysObject *keys = PyObject_Malloc(keys_size);
791 if (keys == NULL) {
796 memcpy(keys, orig->ma_keys, keys_size);
799 keys and values and they are about to be co-owned by a
804 PyDictUnicodeEntry *ep0 = DK_UNICODE_ENTRIES(keys);
810 PyDictKeyEntry *ep0 = DK_ENTRIES(keys);
816 Py_ssize_t n = keys->dk_nentries;
827 /* Since we copied the keys table we now have an extra reference
830 keys->dk_refcnt is already set to 1 (after memcpy). */
834 return keys;
1001 /* Lookup a string in a (all unicode) dict keys.
1003 * or if the dict keys is not all strings.
1004 * If the keys is present then return the index of key.
1165 find_empty_slot(PyDictKeysObject *keys, Py_hash_t hash)
1167 assert(keys != NULL);
1169 const size_t mask = DK_MASK(keys);
1171 Py_ssize_t ix = dictkeys_get_index(keys, i);
1175 ix = dictkeys_get_index(keys, i);
1187 insert_into_dictkeys(PyDictKeysObject *keys, PyObject *name)
1198 Py_ssize_t ix = unicodekeys_lookup_unicode(keys, name, hash);
1200 if (keys->dk_usable <= 0) {
1205 keys->dk_version = 0;
1206 Py_ssize_t hashpos = find_empty_slot(keys, hash);
1207 ix = keys->dk_nentries;
1208 PyDictUnicodeEntry *ep = &DK_UNICODE_ENTRIES(keys)[ix];
1209 dictkeys_set_index(keys, hashpos, ix);
1212 keys->dk_usable--;
1213 keys->dk_nentries++;
1360 build_indices_generic(PyDictKeysObject *keys, PyDictKeyEntry *ep, Py_ssize_t n)
1362 size_t mask = DK_MASK(keys);
1366 for (size_t perturb = hash; dictkeys_get_index(keys, i) != DKIX_EMPTY;) {
1370 dictkeys_set_index(keys, i, ix);
1375 build_indices_unicode(PyDictKeysObject *keys, PyDictUnicodeEntry *ep, Py_ssize_t n)
1377 size_t mask = DK_MASK(keys);
1382 for (size_t perturb = hash; dictkeys_get_index(keys, i) != DKIX_EMPTY;) {
1386 dictkeys_set_index(keys, i, ix);
1394 If a table is split (its keys and hashes are shared, its values are not),
1442 * We must incref keys; we can transfer values.
1601 _PyDict_FromItems(PyObject *const *keys, Py_ssize_t keys_offset,
1606 PyObject *const *ks = keys;
1621 ks = keys;
1639 * that may occur (originally dicts supported only string keys, and exceptions
1643 * (suppressed) occurred when comparing keys in the dict's internal probe
1892 * and occasionally replace a value -- but you can't insert new keys or
2098 /* ...then clear the keys and values */
2196 * the values associated with the keys (but doesn't insert new keys or
2197 * delete keys), via PyDict_SetItem().
2363 PyDictKeysObject *keys = mp->ma_keys;
2374 dictkeys_decref(keys);
2376 else if (keys != NULL) {
2377 assert(keys->dk_refcnt == 1 || keys == Py_EMPTY_KEYS);
2378 dictkeys_decref(keys);
2658 Create a new dictionary with keys from iterable and values set to value.
2676 if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) {
2850 PyDictKeysObject *keys = clone_combined_dict_keys(other);
2851 if (keys == NULL) {
2856 mp->ma_keys = keys;
2876 * that there will be no (or few) overlapping keys.
2930 PyObject *keys = PyMapping_Keys(b);
2935 if (keys == NULL)
2936 /* Docstring says this is equivalent to E.keys() so
2937 * if E doesn't have a .keys() method we want
2943 iter = PyObject_GetIter(keys);
2944 Py_DECREF(keys);
3070 do fast-copy only if it has at most 1/3 non-used keys.
3077 PyDictKeysObject *keys = clone_combined_dict_keys(mp);
3078 if (keys == NULL) {
3081 PyDictObject *new = (PyDictObject *)new_dict(keys, NULL, 0, 0);
3084 cleaning up `keys`. */
3535 PyDictKeysObject *keys = mp->ma_keys;
3536 Py_ssize_t i, n = keys->dk_nentries;
3538 if (DK_IS_UNICODE(keys)) {
3545 PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(keys);
3552 PyDictKeyEntry *entries = DK_ENTRIES(keys);
3581 /* If the dictionary is split, the keys portion is accounted-for
3590 _PyDict_KeysSize(PyDictKeysObject *keys)
3592 size_t es = keys->dk_kind == DICT_KEYS_GENERAL
3595 + ((size_t)1 << keys->dk_log2_index_bytes)
3596 + USABLE_FRACTION(DK_SIZE(keys)) * es);
3639 If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]\n\
3640 If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v\n\
3655 "D.keys() -> a set-like object providing a view on D's keys");
3671 {"keys", dictkeys_new, METH_NOARGS,
4096 "dictionary keys changed during iteration");
4196 "dictionary keys changed during iteration");
4299 "dictionary keys changed during iteration");
4491 Return a reverse iterator over the dict keys.
4542 /* View objects for keys(), items(), values(). */
5082 "Return a reverse iterator over the dict keys.");
5333 PyDictKeysObject *keys = new_keys_object(NEXT_LOG2_SHARED_KEYS_MAX_SIZE, 1);
5334 if (keys == NULL) {
5338 assert(keys->dk_nentries == 0);
5340 keys->dk_usable = SHARED_KEYS_MAX_SIZE;
5341 keys->dk_kind = DICT_KEYS_SPLIT;
5343 return keys;
5354 PyDictKeysObject *keys = CACHED_KEYS(tp);
5355 assert(keys != NULL);
5356 if (keys->dk_usable > 1) {
5357 keys->dk_usable--;
5359 Py_ssize_t size = shared_keys_usable_size(keys);
5403 make_dict_from_instance_attributes(PyDictKeysObject *keys, PyDictValues *values)
5405 dictkeys_incref(keys);
5408 for (Py_ssize_t i = 0; i < shared_keys_usable_size(keys); i++) {
5415 PyObject *res = new_dict(keys, values, used, 0);
5426 PyDictKeysObject *keys = CACHED_KEYS(Py_TYPE(obj));
5428 return make_dict_from_instance_attributes(keys, values);
5435 PyDictKeysObject *keys = CACHED_KEYS(Py_TYPE(obj));
5436 assert(keys != NULL);
5441 ix = insert_into_dictkeys(keys, name);
5446 if (shared_keys_usable_size(keys) == SHARED_KEYS_MAX_SIZE) {
5457 PyObject *dict = make_dict_from_instance_attributes(keys, values);
5496 PyDictKeysObject *keys = CACHED_KEYS(Py_TYPE(obj));
5497 assert(keys != NULL);
5498 Py_ssize_t ix = _PyDictKeys_StringLookup(keys, name);
5518 PyDictKeysObject *keys = CACHED_KEYS(tp);
5519 for (Py_ssize_t i = 0; i < keys->dk_nentries; i++) {
5548 PyDictKeysObject *keys = CACHED_KEYS(tp);
5549 for (Py_ssize_t i = 0; i < keys->dk_nentries; i++) {
5564 PyDictKeysObject *keys = CACHED_KEYS(tp);
5565 for (Py_ssize_t i = 0; i < keys->dk_nentries; i++) {
5581 PyDictKeysObject *keys = CACHED_KEYS(tp);
5582 for (Py_ssize_t i = 0; i < keys->dk_nentries; i++) {
5678 _PyDictKeys_DecRef(PyDictKeysObject *keys)
5680 dictkeys_decref(keys);