mirror of
https://github.com/apple/swift-collections
synced 2026-11-30 05:18:44 +00:00
[BasicContainers] Scramble small hashed containers
Don’t just append new items to the end of storage — it misleads clients into assuming that the containers preserve insertion order, when they most certainly don’t do that. Instead, insert new items into the middle of storage, using an extra swap.
This commit is contained in:
2 files changed
+24
-6
No files matched your search
@@ -18,7 +18,10 @@ extension _HTable {
|
||||
swapper: (Bucket) -> Void,
|
||||
) -> Bucket {
|
||||
assert(isSmall)
|
||||
// FIXME: Scramble order by swapping things in some way
|
||||
if _count > 0 {
|
||||
// Scramble order by swapping the new item in the middle of the table.
|
||||
swapper(Bucket(offset: _count / 2))
|
||||
}
|
||||
let r = Bucket(offset: _count)
|
||||
_count &+= 1
|
||||
_maxProbeLength = _count
|
||||
|
||||
Reference in new issue
Block a user