@@ -13,78 +13,20 @@ extern "C" {
1313 tuning dictionaries, and several ideas for possible optimizations.
1414*/
1515
16- /*
17- There are three kinds of slots in the table:
18-
19- 1. Unused. me_key == me_value == NULL
20- Does not hold an active (key, value) pair now and never did. Unused can
21- transition to Active upon key insertion. This is the only case in which
22- me_key is NULL, and is each slot's initial state.
23-
24- 2. Active. me_key != NULL and me_key != dummy and me_value != NULL
25- Holds an active (key, value) pair. Active can transition to Dummy upon
26- key deletion. This is the only case in which me_value != NULL.
27-
28- 3. Dummy. me_key == dummy and me_value == NULL
29- Previously held an active (key, value) pair, but that was deleted and an
30- active pair has not yet overwritten the slot. Dummy can transition to
31- Active upon key insertion. Dummy slots cannot be made Unused again
32- (cannot have me_key set to NULL), else the probe sequence in case of
33- collision would have no way to know they were once active.
34-
35- Note: .popitem() abuses the me_hash field of an Unused or Dummy slot to
36- hold a search finger. The me_hash field of Unused or Dummy slots has no
37- meaning otherwise.
38- */
39-
40- /* PyDict_MINSIZE is the minimum size of a dictionary. This many slots are
41- * allocated directly in the dict object (in the ma_smalltable member).
42- * It must be a power of 2, and at least 4. 8 allows dicts with no more
43- * than 5 active entries to live in ma_smalltable (and so avoid an
44- * additional malloc); instrumentation suggested this suffices for the
45- * majority of dicts (consisting mostly of usually-small instance dicts and
46- * usually-small dicts created to pass keyword arguments).
47- */
4816#ifndef Py_LIMITED_API
49- #define PyDict_MINSIZE 8
5017
18+ typedef struct _dictkeysobject PyDictKeysObject ;
19+
20+ /* The ma_values pointer is NULL for a combined table
21+ * or points to an array of PyObject* for a split table
22+ */
5123typedef struct {
52- /* Cached hash code of me_key. */
53- Py_hash_t me_hash ;
54- PyObject * me_key ;
55- PyObject * me_value ;
56- } PyDictEntry ;
57-
58- /*
59- To ensure the lookup algorithm terminates, there must be at least one Unused
60- slot (NULL key) in the table.
61- The value ma_fill is the number of non-NULL keys (sum of Active and Dummy);
62- ma_used is the number of non-NULL, non-dummy keys (== the number of non-NULL
63- values == the number of Active items).
64- To avoid slowing down lookups on a near-full table, we resize the table when
65- it's two-thirds full.
66- */
67- typedef struct _dictobject PyDictObject ;
68- struct _dictobject {
6924 PyObject_HEAD
70- Py_ssize_t ma_fill ; /* # Active + # Dummy */
71- Py_ssize_t ma_used ; /* # Active */
72-
73- /* The table contains ma_mask + 1 slots, and that's a power of 2.
74- * We store the mask instead of the size because the mask is more
75- * frequently needed.
76- */
77- Py_ssize_t ma_mask ;
78-
79- /* ma_table points to ma_smalltable for small tables, else to
80- * additional malloc'ed memory. ma_table is never NULL! This rule
81- * saves repeated runtime null-tests in the workhorse getitem and
82- * setitem calls.
83- */
84- PyDictEntry * ma_table ;
85- PyDictEntry * (* ma_lookup )(PyDictObject * mp , PyObject * key , Py_hash_t hash );
86- PyDictEntry ma_smalltable [PyDict_MINSIZE ];
87- };
25+ Py_ssize_t ma_used ;
26+ PyDictKeysObject * ma_keys ;
27+ PyObject * * ma_values ;
28+ } PyDictObject ;
29+
8830#endif /* Py_LIMITED_API */
8931
9032PyAPI_DATA (PyTypeObject ) PyDict_Type ;
@@ -117,6 +59,8 @@ PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);
11759PyAPI_FUNC (int ) PyDict_Next (
11860 PyObject * mp , Py_ssize_t * pos , PyObject * * key , PyObject * * value );
11961#ifndef Py_LIMITED_API
62+ PyDictKeysObject * _PyDict_NewKeysForClass (void );
63+ PyAPI_FUNC (PyObject * ) PyObject_GenericGetDict (PyObject * , void * );
12064PyAPI_FUNC (int ) _PyDict_Next (
12165 PyObject * mp , Py_ssize_t * pos , PyObject * * key , PyObject * * value , Py_hash_t * hash );
12266#endif
@@ -131,6 +75,7 @@ PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash);
13175PyAPI_FUNC (PyObject * ) _PyDict_NewPresized (Py_ssize_t minused );
13276PyAPI_FUNC (void ) _PyDict_MaybeUntrack (PyObject * mp );
13377PyAPI_FUNC (int ) _PyDict_HasOnlyStringKeys (PyObject * mp );
78+ #define _PyDict_HasSplitTable (d ) ((d)->ma_values != NULL)
13479
13580PyAPI_FUNC (int ) PyDict_ClearFreeList (void );
13681#endif
@@ -162,6 +107,11 @@ PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *it
162107PyAPI_FUNC (int ) _PyDict_SetItemId (PyObject * dp , struct _Py_Identifier * key , PyObject * item );
163108PyAPI_FUNC (int ) PyDict_DelItemString (PyObject * dp , const char * key );
164109
110+ #ifndef Py_LIMITED_API
111+ int _PyObjectDict_SetItem (PyTypeObject * tp , PyObject * * dictptr , PyObject * name , PyObject * value );
112+ PyObject * _PyDict_LoadGlobal (PyDictObject * , PyDictObject * , PyObject * );
113+ #endif
114+
165115#ifdef __cplusplus
166116}
167117#endif
0 commit comments