Bug #16676 » bugs_16676_patch_for_2_6.patch
| hash.c (作業コピー) | ||
|---|---|---|
|
{
|
||
|
st_table *new_tab;
|
||
|
ar_table_entry *entry;
|
||
|
const unsigned size = RHASH_AR_TABLE_SIZE(hash);
|
||
|
unsigned size;
|
||
|
st_index_t i;
|
||
|
if (!RHASH_AR_TABLE_P(hash) || size < RHASH_AR_TABLE_MAX_SIZE) {
|
||
|
if (!RHASH_AR_TABLE_P(hash)) return;
|
||
|
size = RHASH_AR_TABLE_SIZE(hash);
|
||
|
if (size < RHASH_AR_TABLE_MAX_SIZE) {
|
||
|
return;
|
||
|
}
|
||
| ... | ... | |
|
st_data_t value = 0, old_key;
|
||
|
st_hash_t hash_value = do_hash(key);
|
||
|
if (UNLIKELY(!RHASH_AR_TABLE_P(hash))) {
|
||
|
/* `#hash` changes ar_table -> st_table */
|
||
|
return -1;
|
||
|
}
|
||
|
if (RHASH_AR_TABLE_SIZE(hash) > 0) {
|
||
|
bin = find_entry(hash, hash_value, key);
|
||
|
existing = (bin != RHASH_AR_TABLE_MAX_BOUND) ? TRUE : FALSE;
|
||
| ... | ... | |
|
unsigned bin = RHASH_AR_TABLE_BOUND(hash);
|
||
|
st_hash_t hash_value = do_hash(key);
|
||
|
if (UNLIKELY(!RHASH_AR_TABLE_P(hash))) {
|
||
|
/* `#hash` changes ar_table -> st_table */
|
||
|
return -1;
|
||
|
}
|
||
|
hash_ar_table(hash); /* prepare ltbl */
|
||
|
bin = find_entry(hash, hash_value, key);
|
||
| ... | ... | |
|
ar_lookup(VALUE hash, st_data_t key, st_data_t *value)
|
||
|
{
|
||
|
st_hash_t hash_value = do_hash(key);
|
||
|
unsigned bin = find_entry(hash, hash_value, key);
|
||
|
unsigned bin;
|
||
|
if (UNLIKELY(!RHASH_AR_TABLE_P(hash))) {
|
||
|
/* `#hash` changes ar_table -> st_table */
|
||
|
return st_lookup(RHASH_ST_TABLE(hash), key, value);
|
||
|
}
|
||
|
bin = find_entry(hash, hash_value, key);
|
||
|
if (bin == RHASH_AR_TABLE_MAX_BOUND) {
|
||
|
return 0;
|
||
| ... | ... | |
|
unsigned bin;
|
||
|
st_hash_t hash_value = do_hash(*key);
|
||
|
if (UNLIKELY(!RHASH_AR_TABLE_P(hash))) {
|
||
|
/* `#hash` changes ar_table -> st_table */
|
||
|
return st_delete(RHASH_ST_TABLE(hash), key, value);
|
||
|
}
|
||
|
bin = find_entry(hash, hash_value, *key);
|
||
| test/ruby/test_hash.rb (作業コピー) | ||
|---|---|---|
|
super
|
||
|
end
|
||
|
end
|
||
|
def test_ar2st
|
||
|
# insert
|
||
|
obj = Object.new
|
||
|
obj.instance_variable_set(:@h, h = {})
|
||
|
def obj.hash
|
||
|
10.times{|i| @h[i] = i}
|
||
|
0
|
||
|
end
|
||
|
def obj.inspect
|
||
|
'test'
|
||
|
end
|
||
|
h[obj] = true
|
||
|
assert_equal '{0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, test=>true}', h.inspect
|
||
|
# delete
|
||
|
obj = Object.new
|
||
|
obj.instance_variable_set(:@h, h = {})
|
||
|
def obj.hash
|
||
|
10.times{|i| @h[i] = i}
|
||
|
0
|
||
|
end
|
||
|
def obj.inspect
|
||
|
'test'
|
||
|
end
|
||
|
def obj.eql? other
|
||
|
other.class == Object
|
||
|
end
|
||
|
obj2 = Object.new
|
||
|
def obj2.hash
|
||
|
0
|
||
|
end
|
||
|
h[obj2] = true
|
||
|
h.delete obj
|
||
|
assert_equal '{0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9}', h.inspect
|
||
|
# lookup
|
||
|
obj = Object.new
|
||
|
obj.instance_variable_set(:@h, h = {})
|
||
|
def obj.hash
|
||
|
10.times{|i| @h[i] = i}
|
||
|
0
|
||
|
end
|
||
|
def obj.inspect
|
||
|
'test'
|
||
|
end
|
||
|
def obj.eql? other
|
||
|
other.class == Object
|
||
|
end
|
||
|
obj2 = Object.new
|
||
|
def obj2.hash
|
||
|
0
|
||
|
end
|
||
|
h[obj2] = true
|
||
|
assert_equal true, h[obj]
|
||
|
end
|
||
|
end
|
||