Skip to content

Commit

Permalink
Packed hashes now promote to compact hashes instead of bucket hashes,…
Browse files Browse the repository at this point in the history
… bucket hash store could be deleted.

EachEntryCallback must receive sequential indices, fixed.

cleanup, profiling
  • Loading branch information
moste00 committed Oct 4, 2023
1 parent 4ec8e4d commit 7902d72
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 96 deletions.
18 changes: 16 additions & 2 deletions spec/ruby/core/hash/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,35 @@
it "allows removing a key while iterating" do
h = { a: 1, b: 2 }
visited = []
h.each_pair { |k,v|
h.each_pair { |k, v|
visited << k
h.delete(k)
}
visited.should == [:a, :b]
h.should == {}
end

it "allows removing a key while iterating for big hashes" do
h = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10,
k: 11, l: 12, m: 13, n: 14, o: 15, p: 16, q: 17, r: 18, s: 19, t: 20,
u: 21, v: 22, w: 23, x: 24, y: 25, z: 26 }
visited = []
h.each_pair { |k, v|
visited << k
h.delete(k)
}
visited.should == [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l, :m,
:n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z]
h.should == {}
end

it "accepts keys with private #hash method" do
key = HashSpecs::KeyWithPrivateHash.new
{ key => 5 }.delete(key).should == 5
end

it "raises a FrozenError if called on a frozen instance" do
-> { HashSpecs.frozen_hash.delete("foo") }.should raise_error(FrozenError)
-> { HashSpecs.frozen_hash.delete("foo") }.should raise_error(FrozenError)
-> { HashSpecs.empty_frozen_hash.delete("foo") }.should raise_error(FrozenError)
end
end
Loading

0 comments on commit 7902d72

Please sign in to comment.