aboutsummaryrefslogtreecommitdiffstats
path: root/st.c
diff options
context:
space:
mode:
Diffstat (limited to 'st.c')
-rw-r--r--st.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/st.c b/st.c
index 6e3df628a7..43e2d71d24 100644
--- a/st.c
+++ b/st.c
@@ -1091,6 +1091,37 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
return 0;
}
+VALUE
+st_keys(st_table *table)
+{
+ st_table_entry *ptr = NULL;
+ st_data_t key, never = (st_data_t)Qundef;
+ VALUE keys = rb_ary_new_capa(table->num_entries);
+
+ if (table->entries_packed) {
+ st_index_t i;
+
+ for (i = 0; i < table->real_entries; i++) {
+ key = PKEY(table, i);
+ if (key == never) continue;
+ rb_ary_push(keys, (VALUE)key);
+ }
+ }
+ else {
+ ptr = table->head;
+ }
+
+ if (ptr != 0) {
+ do {
+ key = ptr->key;
+ if (key != never) rb_ary_push(keys, (VALUE)key);
+ ptr = ptr->fore;
+ } while (ptr && table->head);
+ }
+
+ return keys;
+}
+
#if 0 /* unused right now */
int
st_reverse_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)