|
1 | 1 |
|
2 | 2 | /* set object implementation |
| 3 | +
|
3 | 4 | Written and maintained by Raymond D. Hettinger <[email protected]> |
4 | 5 | Derived from Lib/sets.py and Objects/dictobject.c. |
5 | 6 |
|
6 | 7 | Copyright (c) 2003-2013 Python Software Foundation. |
7 | 8 | All rights reserved. |
| 9 | +
|
| 10 | + The basic lookup function used by all operations. |
| 11 | + This is based on Algorithm D from Knuth Vol. 3, Sec. 6.4. |
| 12 | +
|
| 13 | + The initial probe index is computed as hash mod the table size. |
| 14 | + Subsequent probe indices are computed as explained in Objects/dictobject.c. |
| 15 | +
|
| 16 | + To improve cache locality, each probe inspects a series of consecutive |
| 17 | + nearby entries before moving on to probes elsewhere in memory. This leaves |
| 18 | + us with a hybrid of linear probing and open addressing. The linear probing |
| 19 | + reduces the cost of hash collisions because consecutive memory accesses |
| 20 | + tend to be much cheaper than scattered probes. After LINEAR_PROBES steps, |
| 21 | + we then use open addressing with the upper bits from the hash value. This |
| 22 | + helps break-up long chains of collisions. |
| 23 | +
|
| 24 | + All arithmetic on hash should ignore overflow. |
| 25 | +
|
| 26 | + Unlike the dictionary implementation, the lookkey functions can return |
| 27 | + NULL if the rich comparison returns an error. |
8 | 28 | */ |
9 | 29 |
|
10 | 30 | #include "Python.h" |
@@ -44,28 +64,6 @@ PyObject *_PySet_Dummy = dummy; |
44 | 64 | static PySetObject *free_list[PySet_MAXFREELIST]; |
45 | 65 | static int numfree = 0; |
46 | 66 |
|
47 | | - |
48 | | -/* |
49 | | -The basic lookup function used by all operations. |
50 | | -This is based on Algorithm D from Knuth Vol. 3, Sec. 6.4. |
51 | | -
|
52 | | -The initial probe index is computed as hash mod the table size. |
53 | | -Subsequent probe indices are computed as explained in Objects/dictobject.c. |
54 | | -
|
55 | | -To improve cache locality, each probe inspects a series of consecutive |
56 | | -nearby entries before moving on to probes elsewhere in memory. This leaves |
57 | | -us with a hybrid of linear probing and open addressing. The linear probing |
58 | | -reduces the cost of hash collisions because consecutive memory accesses |
59 | | -tend to be much cheaper than scattered probes. After LINEAR_PROBES steps, |
60 | | -we then use open addressing with the upper bits from the hash value. This |
61 | | -helps break-up long chains of collisions. |
62 | | -
|
63 | | -All arithmetic on hash should ignore overflow. |
64 | | -
|
65 | | -Unlike the dictionary implementation, the lookkey functions can return |
66 | | -NULL if the rich comparison returns an error. |
67 | | -*/ |
68 | | - |
69 | 67 | static setentry * |
70 | 68 | set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash) |
71 | 69 | { |
|
0 commit comments