diff options
| author | KOBAYASHI Shuji <[email protected]> | 2021-01-18 21:32:10 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2021-01-18 21:32:10 +0900 |
| commit | dd81de49a6114dc725a1991d052a056dc5b53649 (patch) | |
| tree | bc85d11b7f60e83a5d74cd892bd05cf522771292 /src/array.c | |
| parent | e4fc42ea115a481845b68b8fd6d8dca95c81a17c (diff) | |
| download | mruby-dd81de49a6114dc725a1991d052a056dc5b53649.tar.gz mruby-dd81de49a6114dc725a1991d052a056dc5b53649.zip | |
Fix that Hash may not contain any empty buckets
The Hash implementation assumed that there were always empty buckets, but
sometimes there were only active or deleted buckets (no empty buckets).
Therefore, fix it so that this situation does not occur.
### Example
```ruby
# example.rb
class A
attr_reader :v
def initialize(v) @v = v end
def ==(o) @v == o.v end
def hash; @v end
def to_s; "#{self.class}[#{@v}]" end
alias eql? ==
alias inspect to_s
end
keys = (0..31).map{A.new(_1)}
h = {}
(0..16).each{h[keys[_1]] = _1}
(17..31).each do
k = keys[_1]
h[k] = _1
h.delete(k)
end
p h.keys
```
#### Before this patch:
```console
$ bin/mruby example.rb
[A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[8], A[9], A[10], A[11], A[12], A[13], A[14], A[15], A[16], A[30], A[31]]
```
#### After this patch:
```console
$ bin/mruby example.rb
[A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[8], A[9], A[10], A[11], A[12], A[13], A[14], A[15], A[16]]
```
Diffstat (limited to 'src/array.c')
0 files changed, 0 insertions, 0 deletions
