add ar_ prefix for ar_table functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
89cbf307b5
commit
70caae18f2
69
hash.c
69
hash.c
@ -352,14 +352,14 @@ rb_hash_ar_table_size(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline st_hash_t
|
static inline st_hash_t
|
||||||
do_hash(st_data_t key)
|
ar_do_hash(st_data_t key)
|
||||||
{
|
{
|
||||||
st_hash_t hash = (st_hash_t)rb_any_hash(key);
|
st_hash_t hash = (st_hash_t)rb_any_hash(key);
|
||||||
return (RESERVED_HASH_VAL == hash) ? RESERVED_HASH_SUBSTITUTION_VAL : hash;
|
return (RESERVED_HASH_VAL == hash) ? RESERVED_HASH_SUBSTITUTION_VAL : hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_entry(ar_table_entry *entry, st_data_t key, st_data_t val, st_hash_t hash)
|
ar_set_entry(ar_table_entry *entry, st_data_t key, st_data_t val, st_hash_t hash)
|
||||||
{
|
{
|
||||||
SET_HASH(entry, hash);
|
SET_HASH(entry, hash);
|
||||||
SET_KEY(entry, key);
|
SET_KEY(entry, key);
|
||||||
@ -367,7 +367,7 @@ set_entry(ar_table_entry *entry, st_data_t key, st_data_t val, st_hash_t hash)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
clear_entry(ar_table_entry* entry)
|
ar_clear_entry(ar_table_entry* entry)
|
||||||
{
|
{
|
||||||
SET_KEY(entry, Qundef);
|
SET_KEY(entry, Qundef);
|
||||||
SET_RECORD(entry, Qundef);
|
SET_RECORD(entry, Qundef);
|
||||||
@ -375,7 +375,7 @@ clear_entry(ar_table_entry* entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
empty_entry(ar_table_entry *entry)
|
ar_empty_entry(ar_table_entry *entry)
|
||||||
{
|
{
|
||||||
return entry->hash == RESERVED_HASH_VAL;
|
return entry->hash == RESERVED_HASH_VAL;
|
||||||
}
|
}
|
||||||
@ -413,7 +413,7 @@ rb_hash_dump(VALUE hash)
|
|||||||
ar_table_entry *cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
ar_table_entry *cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
||||||
st_data_t k, v;
|
st_data_t k, v;
|
||||||
|
|
||||||
if (!empty_entry(cur_entry)) {
|
if (!ar_empty_entry(cur_entry)) {
|
||||||
char b1[0x100], b2[0x100];
|
char b1[0x100], b2[0x100];
|
||||||
/* h = cur_entry->hash; */
|
/* h = cur_entry->hash; */
|
||||||
k = cur_entry->key;
|
k = cur_entry->key;
|
||||||
@ -441,7 +441,7 @@ hash_verify_(VALUE hash, const char *file, int line)
|
|||||||
for (i=0; i<bound; i++) {
|
for (i=0; i<bound; i++) {
|
||||||
ar_table_entry *cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
ar_table_entry *cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
||||||
st_data_t h, k, v;
|
st_data_t h, k, v;
|
||||||
if (!empty_entry(cur_entry)) {
|
if (!ar_empty_entry(cur_entry)) {
|
||||||
h = cur_entry->hash;
|
h = cur_entry->hash;
|
||||||
k = cur_entry->key;
|
k = cur_entry->key;
|
||||||
v = cur_entry->record;
|
v = cur_entry->record;
|
||||||
@ -596,7 +596,7 @@ ar_alloc_table(VALUE hash)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unsigned
|
static unsigned
|
||||||
find_entry(VALUE hash, st_hash_t hash_value, st_data_t key)
|
ar_find_entry(VALUE hash, st_hash_t hash_value, st_data_t key)
|
||||||
{
|
{
|
||||||
unsigned i, bound = RHASH_AR_TABLE_BOUND(hash);
|
unsigned i, bound = RHASH_AR_TABLE_BOUND(hash);
|
||||||
|
|
||||||
@ -679,7 +679,7 @@ ar_force_convert_table(VALUE hash, const char *file, int line)
|
|||||||
|
|
||||||
for (i = 0; i < bound; i++) {
|
for (i = 0; i < bound; i++) {
|
||||||
entry = RHASH_AR_TABLE_REF(hash, i);
|
entry = RHASH_AR_TABLE_REF(hash, i);
|
||||||
if (empty_entry(entry)) continue;
|
if (ar_empty_entry(entry)) continue;
|
||||||
|
|
||||||
st_add_direct_with_hash(new_tab, entry->key, entry->record, entry->hash);
|
st_add_direct_with_hash(new_tab, entry->key, entry->record, entry->hash);
|
||||||
}
|
}
|
||||||
@ -716,12 +716,12 @@ ar_compact_table(VALUE hash)
|
|||||||
ar_table_entry *entries = RHASH_AR_TABLE_REF(hash, 0);
|
ar_table_entry *entries = RHASH_AR_TABLE_REF(hash, 0);
|
||||||
|
|
||||||
for (i=0; i<bound; i++) {
|
for (i=0; i<bound; i++) {
|
||||||
if (empty_entry(&entries[i])) {
|
if (ar_empty_entry(&entries[i])) {
|
||||||
if (j <= i) j = i+1;
|
if (j <= i) j = i+1;
|
||||||
for (; j<bound; j++) {
|
for (; j<bound; j++) {
|
||||||
if (!empty_entry(&entries[j])) {
|
if (!ar_empty_entry(&entries[j])) {
|
||||||
entries[i] = entries[j];
|
entries[i] = entries[j];
|
||||||
clear_entry(&entries[j]);
|
ar_clear_entry(&entries[j]);
|
||||||
j++;
|
j++;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
@ -744,8 +744,6 @@ static int
|
|||||||
ar_add_direct_with_hash(VALUE hash, st_data_t key, st_data_t val, st_hash_t hash_value)
|
ar_add_direct_with_hash(VALUE hash, st_data_t key, st_data_t val, st_hash_t hash_value)
|
||||||
{
|
{
|
||||||
unsigned bin = RHASH_AR_TABLE_BOUND(hash);
|
unsigned bin = RHASH_AR_TABLE_BOUND(hash);
|
||||||
ar_table *tab = RHASH_AR_TABLE(hash);
|
|
||||||
ar_table_entry *entry;
|
|
||||||
|
|
||||||
if (RHASH_AR_TABLE_SIZE(hash) >= RHASH_AR_TABLE_MAX_SIZE) {
|
if (RHASH_AR_TABLE_SIZE(hash) >= RHASH_AR_TABLE_MAX_SIZE) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -757,8 +755,7 @@ ar_add_direct_with_hash(VALUE hash, st_data_t key, st_data_t val, st_hash_t hash
|
|||||||
}
|
}
|
||||||
HASH_ASSERT(bin < RHASH_AR_TABLE_MAX_BOUND);
|
HASH_ASSERT(bin < RHASH_AR_TABLE_MAX_BOUND);
|
||||||
|
|
||||||
entry = &tab->entries[bin];
|
ar_set_entry(RHASH_AR_TABLE_REF(hash, bin), key, val, hash_value);
|
||||||
set_entry(entry, key, val, hash_value);
|
|
||||||
RHASH_AR_TABLE_BOUND_SET(hash, bin+1);
|
RHASH_AR_TABLE_BOUND_SET(hash, bin+1);
|
||||||
RHASH_AR_TABLE_SIZE_INC(hash);
|
RHASH_AR_TABLE_SIZE_INC(hash);
|
||||||
return 0;
|
return 0;
|
||||||
@ -774,7 +771,7 @@ ar_foreach(VALUE hash, int (*func)(ANYARGS), st_data_t arg)
|
|||||||
for (i = 0; i < bound; i++) {
|
for (i = 0; i < bound; i++) {
|
||||||
enum st_retval retval;
|
enum st_retval retval;
|
||||||
ar_table_entry *cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
ar_table_entry *cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
||||||
if (empty_entry(cur_entry)) continue;
|
if (ar_empty_entry(cur_entry)) continue;
|
||||||
retval = (*func)(cur_entry->key, cur_entry->record, arg, 0);
|
retval = (*func)(cur_entry->key, cur_entry->record, arg, 0);
|
||||||
/* cur_entry is not valid after that */
|
/* cur_entry is not valid after that */
|
||||||
|
|
||||||
@ -785,7 +782,7 @@ ar_foreach(VALUE hash, int (*func)(ANYARGS), st_data_t arg)
|
|||||||
case ST_STOP:
|
case ST_STOP:
|
||||||
return 0;
|
return 0;
|
||||||
case ST_DELETE:
|
case ST_DELETE:
|
||||||
clear_entry(RHASH_AR_TABLE_REF(hash, i));
|
ar_clear_entry(RHASH_AR_TABLE_REF(hash, i));
|
||||||
RHASH_AR_TABLE_SIZE_DEC(hash);
|
RHASH_AR_TABLE_SIZE_DEC(hash);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -807,7 +804,7 @@ ar_foreach_check(VALUE hash, int (*func)(ANYARGS), st_data_t arg,
|
|||||||
|
|
||||||
for (i = 0; i < bound; i++) {
|
for (i = 0; i < bound; i++) {
|
||||||
cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
||||||
if (empty_entry(cur_entry))
|
if (ar_empty_entry(cur_entry))
|
||||||
continue;
|
continue;
|
||||||
key = cur_entry->key;
|
key = cur_entry->key;
|
||||||
hash_value = cur_entry->hash;
|
hash_value = cur_entry->hash;
|
||||||
@ -821,7 +818,7 @@ ar_foreach_check(VALUE hash, int (*func)(ANYARGS), st_data_t arg,
|
|||||||
case ST_CHECK: {
|
case ST_CHECK: {
|
||||||
if (cur_entry->key == never && cur_entry->hash == RESERVED_HASH_VAL)
|
if (cur_entry->key == never && cur_entry->hash == RESERVED_HASH_VAL)
|
||||||
break;
|
break;
|
||||||
ret = find_entry(hash, hash_value, key);
|
ret = ar_find_entry(hash, hash_value, key);
|
||||||
if (ret == RHASH_AR_TABLE_MAX_BOUND) {
|
if (ret == RHASH_AR_TABLE_MAX_BOUND) {
|
||||||
retval = (*func)(0, 0, arg, 1);
|
retval = (*func)(0, 0, arg, 1);
|
||||||
return 2;
|
return 2;
|
||||||
@ -832,8 +829,8 @@ ar_foreach_check(VALUE hash, int (*func)(ANYARGS), st_data_t arg,
|
|||||||
case ST_STOP:
|
case ST_STOP:
|
||||||
return 0;
|
return 0;
|
||||||
case ST_DELETE: {
|
case ST_DELETE: {
|
||||||
if (!empty_entry(cur_entry)) {
|
if (!ar_empty_entry(cur_entry)) {
|
||||||
clear_entry(cur_entry);
|
ar_clear_entry(cur_entry);
|
||||||
RHASH_AR_TABLE_SIZE_DEC(hash);
|
RHASH_AR_TABLE_SIZE_DEC(hash);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -851,10 +848,10 @@ ar_update(VALUE hash, st_data_t key,
|
|||||||
int retval, existing;
|
int retval, existing;
|
||||||
unsigned bin = RHASH_AR_TABLE_MAX_BOUND;
|
unsigned bin = RHASH_AR_TABLE_MAX_BOUND;
|
||||||
st_data_t value = 0, old_key;
|
st_data_t value = 0, old_key;
|
||||||
st_hash_t hash_value = do_hash(key);
|
st_hash_t hash_value = ar_do_hash(key);
|
||||||
|
|
||||||
if (RHASH_AR_TABLE_SIZE(hash) > 0) {
|
if (RHASH_AR_TABLE_SIZE(hash) > 0) {
|
||||||
bin = find_entry(hash, hash_value, key);
|
bin = ar_find_entry(hash, hash_value, key);
|
||||||
existing = (bin != RHASH_AR_TABLE_MAX_BOUND) ? TRUE : FALSE;
|
existing = (bin != RHASH_AR_TABLE_MAX_BOUND) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -887,7 +884,7 @@ ar_update(VALUE hash, st_data_t key,
|
|||||||
break;
|
break;
|
||||||
case ST_DELETE:
|
case ST_DELETE:
|
||||||
if (existing) {
|
if (existing) {
|
||||||
clear_entry(RHASH_AR_TABLE_REF(hash, bin));
|
ar_clear_entry(RHASH_AR_TABLE_REF(hash, bin));
|
||||||
RHASH_AR_TABLE_SIZE_DEC(hash);
|
RHASH_AR_TABLE_SIZE_DEC(hash);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -899,11 +896,11 @@ static int
|
|||||||
ar_insert(VALUE hash, st_data_t key, st_data_t value)
|
ar_insert(VALUE hash, st_data_t key, st_data_t value)
|
||||||
{
|
{
|
||||||
unsigned bin = RHASH_AR_TABLE_BOUND(hash);
|
unsigned bin = RHASH_AR_TABLE_BOUND(hash);
|
||||||
st_hash_t hash_value = do_hash(key);
|
st_hash_t hash_value = ar_do_hash(key);
|
||||||
|
|
||||||
hash_ar_table(hash); /* prepare ltbl */
|
hash_ar_table(hash); /* prepare ltbl */
|
||||||
|
|
||||||
bin = find_entry(hash, hash_value, key);
|
bin = ar_find_entry(hash, hash_value, key);
|
||||||
if (bin == RHASH_AR_TABLE_MAX_BOUND) {
|
if (bin == RHASH_AR_TABLE_MAX_BOUND) {
|
||||||
if (RHASH_AR_TABLE_SIZE(hash) >= RHASH_AR_TABLE_MAX_SIZE) {
|
if (RHASH_AR_TABLE_SIZE(hash) >= RHASH_AR_TABLE_MAX_SIZE) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -914,7 +911,7 @@ ar_insert(VALUE hash, st_data_t key, st_data_t value)
|
|||||||
}
|
}
|
||||||
HASH_ASSERT(bin < RHASH_AR_TABLE_MAX_BOUND);
|
HASH_ASSERT(bin < RHASH_AR_TABLE_MAX_BOUND);
|
||||||
|
|
||||||
set_entry(RHASH_AR_TABLE_REF(hash, bin), key, value, hash_value);
|
ar_set_entry(RHASH_AR_TABLE_REF(hash, bin), key, value, hash_value);
|
||||||
RHASH_AR_TABLE_BOUND_SET(hash, bin+1);
|
RHASH_AR_TABLE_BOUND_SET(hash, bin+1);
|
||||||
RHASH_AR_TABLE_SIZE_INC(hash);
|
RHASH_AR_TABLE_SIZE_INC(hash);
|
||||||
return 0;
|
return 0;
|
||||||
@ -932,8 +929,8 @@ ar_lookup(VALUE hash, st_data_t key, st_data_t *value)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
st_hash_t hash_value = do_hash(key);
|
st_hash_t hash_value = ar_do_hash(key);
|
||||||
unsigned bin = find_entry(hash, hash_value, key);
|
unsigned bin = ar_find_entry(hash, hash_value, key);
|
||||||
|
|
||||||
if (bin == RHASH_AR_TABLE_MAX_BOUND) {
|
if (bin == RHASH_AR_TABLE_MAX_BOUND) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -952,10 +949,10 @@ static int
|
|||||||
ar_delete(VALUE hash, st_data_t *key, st_data_t *value)
|
ar_delete(VALUE hash, st_data_t *key, st_data_t *value)
|
||||||
{
|
{
|
||||||
unsigned bin;
|
unsigned bin;
|
||||||
st_hash_t hash_value = do_hash(*key);
|
st_hash_t hash_value = ar_do_hash(*key);
|
||||||
|
|
||||||
|
|
||||||
bin = find_entry(hash, hash_value, *key);
|
bin = ar_find_entry(hash, hash_value, *key);
|
||||||
|
|
||||||
if (bin == RHASH_AR_TABLE_MAX_BOUND) {
|
if (bin == RHASH_AR_TABLE_MAX_BOUND) {
|
||||||
if (value != 0) *value = 0;
|
if (value != 0) *value = 0;
|
||||||
@ -964,7 +961,7 @@ ar_delete(VALUE hash, st_data_t *key, st_data_t *value)
|
|||||||
else {
|
else {
|
||||||
ar_table_entry *entry = RHASH_AR_TABLE_REF(hash, bin);
|
ar_table_entry *entry = RHASH_AR_TABLE_REF(hash, bin);
|
||||||
if (value != 0) *value = entry->record;
|
if (value != 0) *value = entry->record;
|
||||||
clear_entry(entry);
|
ar_clear_entry(entry);
|
||||||
RHASH_AR_TABLE_SIZE_DEC(hash);
|
RHASH_AR_TABLE_SIZE_DEC(hash);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -979,10 +976,10 @@ ar_shift(VALUE hash, st_data_t *key, st_data_t *value)
|
|||||||
|
|
||||||
for (i = 0; i < bound; i++) {
|
for (i = 0; i < bound; i++) {
|
||||||
entry = &entries[i];
|
entry = &entries[i];
|
||||||
if (!empty_entry(entry)) {
|
if (!ar_empty_entry(entry)) {
|
||||||
if (value != 0) *value = entry->record;
|
if (value != 0) *value = entry->record;
|
||||||
*key = entry->key;
|
*key = entry->key;
|
||||||
clear_entry(entry);
|
ar_clear_entry(entry);
|
||||||
RHASH_AR_TABLE_SIZE_DEC(hash);
|
RHASH_AR_TABLE_SIZE_DEC(hash);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1004,7 +1001,7 @@ ar_keys(VALUE hash, st_data_t *keys, st_index_t size)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ar_table_entry *cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
ar_table_entry *cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
||||||
if (!empty_entry(cur_entry))
|
if (!ar_empty_entry(cur_entry))
|
||||||
*keys++ = cur_entry->key;
|
*keys++ = cur_entry->key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1024,7 +1021,7 @@ ar_values(VALUE hash, st_data_t *values, st_index_t size)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ar_table_entry *cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
ar_table_entry *cur_entry = RHASH_AR_TABLE_REF(hash, i);
|
||||||
if (!empty_entry(cur_entry))
|
if (!ar_empty_entry(cur_entry))
|
||||||
*values++ = cur_entry->record;
|
*values++ = cur_entry->record;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user