Skip to content

Pack small hash tables (up to 6 entries) #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
st: add test for size of numhash and delete_safe
  • Loading branch information
funny-falcon committed Mar 8, 2012
commit 638344c316a289b98a9e5b5f7ba9f4cd36ab6ac9
19 changes: 19 additions & 0 deletions ext/-test-/st/numhash/numhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ numhash_update(VALUE self, VALUE key)
return Qfalse;
}

static VALUE
numhash_size(VALUE self)
{
return LONG2FIX(((st_table*)DATA_PTR(self))->num_entries);
}

static VALUE
numhash_delete_safe(VALUE self, VALUE key)
{
VALUE val;
if (st_delete_safe((st_table*)DATA_PTR(self),
(st_data_t*)&key, (st_data_t*)&val, (st_data_t)-1)) {
return val;
}
return Qnil;
}

void
Init_numhash(void)
{
Expand All @@ -91,5 +108,7 @@ Init_numhash(void)
rb_define_method(st, "[]=", numhash_aset, 2);
rb_define_method(st, "each", numhash_each, 0);
rb_define_method(st, "update", numhash_update, 1);
rb_define_method(st, "size", numhash_size, 0);
rb_define_method(st, "delete_safe", numhash_delete_safe, 1);
}

9 changes: 9 additions & 0 deletions test/-ext-/st/test_numhash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ def test_update
assert_equal(:x, @tbl[0])
assert_equal(:x, @tbl[5])
end

def test_size_after_delete_safe
10.downto(1) do |up|
tbl = Bug::StNumHash.new
1.upto(up){|i| tbl[i] = i}
assert_equal(1, tbl.delete_safe(1))
assert_equal(up - 1, tbl.size, "delete_safe doesn't change size from #{up} to #{up-1}")
end
end
end
end
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy