在 2013-3-27 AM5:59,"Ludovic Courtès" 写道: > > Nala Ginrut skribis: > > > * hash-items: get the amount of items in the hash table > > There’s already ‘hash-count’, recently added. > If I need to check the amount of items each time in the loop, hash-count will do redundant visit for all items. But hash-items is efficient. > > +SCM_DEFINE (scm_hash_size, "hash-size", 1, 0, 0, > > + (SCM table), > > + "Get the size of this hash table.") > > +#define FUNC_NAME s_scm_hash_size > > +{ > > + SCM_VALIDATE_HASHTABLE (1, table); > > + return scm_from_uint (SCM_SIMPLE_VECTOR_LENGTH (SCM_HASHTABLE_VECTOR (table))); > > That returns the number of buckets, which is an internal detail, and > probably not a useful one. > Yes, maybe, but I think we'd better provide it since we can see the size in the REPL, people may want to get this info in program for some statistic. > > +(define (hash-keys table) > > + "Return all the keys from hash table." > > + (hash-map->list (lambda (x y) x) table)) > > That doesn’t seem sufficiently common to warrant a new procedure. WDYT? > I add it because I do need it when I wrote artanis, but Racket provides it. So I think it's useful. > Thanks, > Ludo’. > >