Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4887a12

Browse files
committed
Add notes from python-dev about readonly dictionaries.
1 parent c7bc0b9 commit 4887a12

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Objects/dictnotes.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,24 @@ sizes and access patterns, the user may be able to provide useful hints.
197197
cache locality, and a simplified search routine. It also eliminates
198198
the need to test for dummy entries on each probe. The preconditions
199199
for this strategy arise in symbol tables and in the builtin dictionary.
200+
201+
202+
Readonly Dictionaries
203+
---------------------
204+
Some dictionary use cases pass through a build stage and then move to a
205+
more heavily exercised lookup stage with no further changes to the
206+
dictionary.
207+
208+
An idea that emerged on python-dev is to be able to convert a dictionary
209+
to a read-only state. This can help prevent programming errors and also
210+
provide knowledge that can be exploited for lookup optimization.
211+
212+
The dictionary can be immediately rebuilt (eliminating dummy entries),
213+
resized (to an appropriate level of sparseness), and the keys can be
214+
jostled (to minimize collisions). The lookdict() routine can then
215+
eliminate the test for dummy entries (saving about 1/4 of the time
216+
spend in the collision resolution loop).
217+
218+
An additional possibility is to insert links into the empty spaces
219+
so that dictionary iteration can proceed in len(d) steps instead of
220+
(mp->mask + 1) steps.

0 commit comments

Comments
 (0)