Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
ce85acff
Kaydet (Commit)
ce85acff
authored
Tem 10, 2016
tarafından
R David Murray
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge: #20647: Update dictobject.c comments to account for randomized string hashes.
üst
20bd3b07
537ad7ad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
8 deletions
+5
-8
dictobject.c
Objects/dictobject.c
+5
-8
No files found.
Objects/dictobject.c
Dosyayı görüntüle @
ce85acff
...
@@ -88,20 +88,17 @@ it's USABLE_FRACTION (currently two-thirds) full.
...
@@ -88,20 +88,17 @@ it's USABLE_FRACTION (currently two-thirds) full.
/*
/*
Major subtleties ahead: Most hash schemes depend on having a "good" hash
Major subtleties ahead: Most hash schemes depend on having a "good" hash
function, in the sense of simulating randomness. Python doesn't: its most
function, in the sense of simulating randomness. Python doesn't: its most
important hash functions (for
strings and
ints) are very regular in common
important hash functions (for ints) are very regular in common
cases:
cases:
>>>
map(hash, (0, 1, 2, 3))
>>>
[hash(i) for i in range(4)]
[0, 1, 2, 3]
[0, 1, 2, 3]
>>> map(hash, ("namea", "nameb", "namec", "named"))
[-1658398457, -1658398460, -1658398459, -1658398462]
>>>
This isn't necessarily bad! To the contrary, in a table of size 2**i, taking
This isn't necessarily bad! To the contrary, in a table of size 2**i, taking
the low-order i bits as the initial table index is extremely fast, and there
the low-order i bits as the initial table index is extremely fast, and there
are no collisions at all for dicts indexed by a contiguous range of ints.
are no collisions at all for dicts indexed by a contiguous range of ints.
So
The same is approximately true when keys are "consecutive" strings. So this
this gives better-than-random behavior in common cases, and that's very
gives better-than-random behavior in common cases, and that's very
desirable.
desirable.
OTOH, when collisions occur, the tendency to fill contiguous slices of the
OTOH, when collisions occur, the tendency to fill contiguous slices of the
hash table makes a good collision resolution strategy crucial. Taking only
hash table makes a good collision resolution strategy crucial. Taking only
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment