aboutsummaryrefslogtreecommitdiffstats
path: root/st.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-04-19 16:02:36 -0400
committerPeter Zhu <peter@peterzhu.ca>2023-05-17 09:19:40 -0400
commit0938964ba1af3924cf969fb809fc3598892bc20d (patch)
treec87a84dcbec890a0e35a4a84c96a0892653dbbc0 /st.c
parent5199f2aaf9527c97e6ec371e19748d0c2ac7a70e (diff)
downloadruby-0938964ba1af3924cf969fb809fc3598892bc20d.tar.gz
Implement Hash ST tables on VWA
Diffstat (limited to 'st.c')
-rw-r--r--st.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/st.c b/st.c
index 411237d13b..b8ad6ab6c2 100644
--- a/st.c
+++ b/st.c
@@ -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)
{