From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Add-native-hashtable-helper-functions Date: Wed, 27 Mar 2013 08:47:19 +0800 Message-ID: References: <1364294433.2730.2.camel@Renee-desktop.suse> <874nfxvn4u.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8fb200fa60a27d04d8dd61d6 X-Trace: ger.gmane.org 1364345243 21032 80.91.229.3 (27 Mar 2013 00:47:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Mar 2013 00:47:23 +0000 (UTC) Cc: guile-devel To: =?UTF-8?Q?Ludovic_Court=C3=A8s?= Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Mar 27 01:47:49 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UKeWr-0001bc-2A for guile-devel@m.gmane.org; Wed, 27 Mar 2013 01:47:49 +0100 Original-Received: from localhost ([::1]:60093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKeWT-000705-61 for guile-devel@m.gmane.org; Tue, 26 Mar 2013 20:47:25 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKeWQ-000700-3P for guile-devel@gnu.org; Tue, 26 Mar 2013 20:47:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKeWO-0007os-T9 for guile-devel@gnu.org; Tue, 26 Mar 2013 20:47:22 -0400 Original-Received: from mail-ob0-x236.google.com ([2607:f8b0:4003:c01::236]:45179) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKeWO-0007oe-OA; Tue, 26 Mar 2013 20:47:20 -0400 Original-Received: by mail-ob0-f182.google.com with SMTP id ef5so5104739obb.13 for ; Tue, 26 Mar 2013 17:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=QACY7TWczjleduVSsFr04xCDV5fJna95oMhcGa+r6rs=; b=nMDLNRpVS/22OUhWLHxpdbB/+96f5+wPqiYorE1gFQHbjNUy+skkaA1PdGibCO1Tgm UjxAwgSdL2/hWfkXexFsR5bwFssCM6hxZVrQx2KagFBEnxBbzBKZgTCf3+eoe6oDrtZI QluwRyYIu+zMr3QUe710ISoh4Fhx76/rsJkvgJWfU7XFUZhTNMI8bOF2hNHR6Jv4xnYz ehu8TQhzS/z5kIjNpT7hCOH68YvMLD3n6Nab1fpyZAH1L/bn+Q5sv40Up80mEQzf2vqR auk29D9+HNnrOsm3dOX6SSSs797AI85n32pYGhFo0AlWu9ML7KLjjUDKXWJWF/gXIKzc vAIA== X-Received: by 10.60.29.161 with SMTP id l1mr14851571oeh.111.1364345239935; Tue, 26 Mar 2013 17:47:19 -0700 (PDT) Original-Received: by 10.182.109.99 with HTTP; Tue, 26 Mar 2013 17:47:19 -0700 (PDT) Original-Received: by 10.182.109.99 with HTTP; Tue, 26 Mar 2013 17:47:19 -0700 (PDT) In-Reply-To: <874nfxvn4u.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::236 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16011 Archived-At: --e89a8fb200fa60a27d04d8dd61d6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable =E5=9C=A8 2013-3-27 AM5:59=EF=BC=8C"Ludovic Court=C3=A8s" =E5= =86=99=E9=81=93=EF=BC=9A > > Nala Ginrut skribis: > > > * hash-items: get the amount of items in the hash table > > There=E2=80=99s already =E2=80=98hash-count=E2=80=99, 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=E2=80=99t 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=E2=80=99. > > --e89a8fb200fa60a27d04d8dd61d6 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


=E5=9C=A8 2013-3-27 AM5:59=EF=BC=8C"Ludovic Court=C3=A8s" <ludo@gnu.org>=E5=86=99=E9=81=93=EF=BC= =9A
>
> Nala Ginrut <nalaginrut@gma= il.com> skribis:
>
> > * hash-items: get the amount of items in the hash table
>
> There=E2=80=99s already =E2=80=98hash-count=E2=80=99, recently added.<= br> >

If I need to check the amount of items
each time in the loop, hash-count will do redundant visit for all items. Bu= t hash-items is efficient.

> > +SCM_DEFINE (scm_hash_size, "hash-size",= 1, 0, 0,
> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(SCM table),
> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"Get the size of = this hash table.")
> > +#define FUNC_NAME s_scm_hash_size
> > +{
> > + =C2=A0SCM_VALIDATE_HASHTABLE (1, table);
> > + =C2=A0return scm_from_uint (SCM_SIMPLE_VECTOR_LENGTH (SCM_HASHT= ABLE_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 f= or some statistic.

> > +(define (hash-keys table)
> > + =C2=A0"Return all the keys from hash table."
> > + =C2=A0(hash-map->list (lambda (x y) x) table))
>
> That doesn=E2=80=99t seem sufficiently common to warrant a new procedu= re. =C2=A0WDYT?
>

I add it because I do need it when I wrote artanis, but Rack= et provides it.
So I think it's useful.

> Thanks,
> Ludo=E2=80=99.
>
>

--e89a8fb200fa60a27d04d8dd61d6--