Closed jtmueller closed 5 years ago
This appears to be more serious than I previously thought. It's not specific to ValueTuple keys. Instead, it appears to be any time there is more than 1 and less than 8 items in the dictionary, the lookup fails.
The cause of this bug was an optimization I put into Resize: In this scenario, we're going from a capacity of 3 to a capacity of 7, but the underlying array we got from the ArrayPool is actually a 16-element array. In an attempt to short-circuit the "allocate new array, copy everything, and sort the entries into the new set of buckets" code, I failed to do the "sort the entries into the new set of buckets" part.
Revised code skips over the "allocate new arrays and copy everything" part when the underlying array is large enough for the new capacity, but it now correctly sorts the entries into the new set of buckets, so lookups succeed when they should.
Describe the bug Lookups fail in a
PooledDictionary<(int, int), string>
but succeed in aDictionary<(int, int), string>
.To Reproduce
Expected behavior
We should get the same results from both dictionary types, without having to specify custom comparers.