From fcd748480a76b3fef7586483b29fc5281e405e1f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 1 Nov 2019 20:26:32 -0700 Subject: hash: expose new iterator interface. * hash.c (struct hash): Declaration removed from here. (hash_iter_init, us_hash_iter_init, hash_iter_next, hash_iter_peek): Functions switched to external linkage. * hash.h (struct hash): Declared here now. (hash_iter_init, us_hash_iter_init, hash_iter_next, hash_iter_peek): Declared. --- hash.c | 15 ++++----------- hash.h | 11 +++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/hash.c b/hash.c index bc3bcbde..03c03436 100644 --- a/hash.c +++ b/hash.c @@ -84,13 +84,6 @@ struct hash { struct hash_ops *hops; }; -struct hash_iter { - struct hash_iter *next; - val hash; - cnum chain; - val cons; -}; - #define hash_seed (deref(lookup_var_l(nil, hash_seed_s))) static_forward(struct hash_ops hash_eq_ops); @@ -1052,7 +1045,7 @@ static struct cobj_ops hash_iter_ops = cobj_ops_init(eq, hash_iter_mark, cobj_eq_hash_op); -static void hash_iter_init(struct hash_iter *hi, val hash, val self) +void hash_iter_init(struct hash_iter *hi, val hash, val self) { struct hash *h = coerce(struct hash *, cobj_handle(self, hash, hash_s)); hi->next = 0; @@ -1062,7 +1055,7 @@ static void hash_iter_init(struct hash_iter *hi, val hash, val self) h->usecount++; } -static void us_hash_iter_init(struct hash_iter *hi, val hash) +void us_hash_iter_init(struct hash_iter *hi, val hash) { struct hash *h = coerce(struct hash *, hash->co.handle); hi->next = 0; @@ -1092,12 +1085,12 @@ static val hash_iter_next_impl(struct hash_iter *hi, val iter) return us_car(hi->cons); } -static val hash_iter_next(struct hash_iter *hi) +val hash_iter_next(struct hash_iter *hi) { return hash_iter_next_impl(hi, 0); } -static val hash_iter_peek(struct hash_iter *hi) +val hash_iter_peek(struct hash_iter *hi) { val hash = hi->hash; struct hash *h = hash ? coerce(struct hash *, hash->co.handle) : 0; diff --git a/hash.h b/hash.h index 84045156..20f1040c 100644 --- a/hash.h +++ b/hash.h @@ -25,6 +25,13 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +struct hash_iter { + struct hash_iter *next; + val hash; + cnum chain; + val cons; +}; + extern val weak_keys_k, weak_vals_k, userdata_k; extern val equal_based_k, eql_based_k, eq_based_k; @@ -49,6 +56,10 @@ val get_hash_userdata(val hash); val set_hash_userdata(val hash, val data); val hashp(val obj); val maphash(val func, val hash); +void hash_iter_init(struct hash_iter *hi, val hash, val self); +void us_hash_iter_init(struct hash_iter *hi, val hash); +val hash_iter_next(struct hash_iter *hi); +val hash_iter_peek(struct hash_iter *hi); val hash_begin(val hash); val hash_next(val iter); val hash_peek(val iter); -- cgit v1.2.3