diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-04-19 16:02:36 -0400 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-05-17 09:19:40 -0400 |
commit | 0938964ba1af3924cf969fb809fc3598892bc20d (patch) | |
tree | c87a84dcbec890a0e35a4a84c96a0892653dbbc0 /st.c | |
parent | 5199f2aaf9527c97e6ec371e19748d0c2ac7a70e (diff) | |
download | ruby-0938964ba1af3924cf969fb809fc3598892bc20d.tar.gz |
Implement Hash ST tables on VWA
Diffstat (limited to 'st.c')
-rw-r--r-- | st.c | 36 |
1 files changed, 26 insertions, 10 deletions
@@ -509,13 +509,9 @@ stat_col(void) } #endif -/* Create and return table with TYPE which can hold at least SIZE - entries. The real number of entries which the table can hold is - the nearest power of two for SIZE. */ st_table * -st_init_table_with_size(const struct st_hash_type *type, st_index_t size) +st_init_existing_table_with_size(st_table *tab, const struct st_hash_type *type, st_index_t size) { - st_table *tab; int n; #ifdef HASH_LOG @@ -536,11 +532,7 @@ st_init_table_with_size(const struct st_hash_type *type, st_index_t size) if (n < 0) return NULL; #endif - tab = (st_table *) malloc(sizeof (st_table)); -#ifndef RUBY - if (tab == NULL) - return NULL; -#endif + tab->type = type; tab->entry_power = n; tab->bin_power = features[n].bin_power; @@ -569,6 +561,30 @@ st_init_table_with_size(const struct st_hash_type *type, st_index_t size) return tab; } +/* Create and return table with TYPE which can hold at least SIZE + entries. The real number of entries which the table can hold is + the nearest power of two for SIZE. */ +st_table * +st_init_table_with_size(const struct st_hash_type *type, st_index_t size) +{ + st_table *tab = malloc(sizeof(st_table)); +#ifndef RUBY + if (tab == NULL) + return NULL; +#endif + +#ifdef RUBY + st_init_existing_table_with_size(tab, type, size); +#else + if (st_init_existing_table_with_size(tab, type, size) == NULL) { + free(tab); + return NULL; + } +#endif + + return tab; +} + size_t st_table_size(const struct st_table *tbl) { |