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

Skip to content

Commit ae7b00e

Browse files
committed
Move the overview comment to the top of the file.
1 parent 7b47699 commit ae7b00e

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

Objects/setobject.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11

22
/* set object implementation
3+
34
Written and maintained by Raymond D. Hettinger <[email protected]>
45
Derived from Lib/sets.py and Objects/dictobject.c.
56
67
Copyright (c) 2003-2013 Python Software Foundation.
78
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.
828
*/
929

1030
#include "Python.h"
@@ -44,28 +64,6 @@ PyObject *_PySet_Dummy = dummy;
4464
static PySetObject *free_list[PySet_MAXFREELIST];
4565
static int numfree = 0;
4666

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-
6967
static setentry *
7068
set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
7169
{

0 commit comments

Comments
 (0)