Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hash-tables containing references to hash-tables

0 views
Skip to first unread message

Nordlöw

unread,
Nov 23, 2009, 6:12:22 AM11/23/09
to
Is it possible for a hash-table to contain a *reference* to another
hash-table, similar to how we can build arbitrary graphs using conses/
lists and setf?
If so how? If not, is there reason for being so or is it just an emacs
todo?

If we have
(puthash parent-key (make-hash-table : size CHILD-SIZE) parent-hash)
then I want
(gethash parent-key parent-hash)
to return a *reference* to hash-table contained in parent-hash.

I already have a working code for this but I am uncertain how this
will perform when CHILD-SIZE is really large.

/Nordlöw

to...@tuxteam.de

unread,
Nov 23, 2009, 7:41:00 AM11/23/09
to Nordlöw, help-gn...@gnu.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Nov 23, 2009 at 03:12:22AM -0800, Nordlöw wrote:
> Is it possible for a hash-table to contain a *reference* to another
> hash-table, similar to how we can build arbitrary graphs using conses/
> lists and setf?

Yes, it is -- in a way.

> If so how? If not, is there reason for being so or is it just an emacs
> todo?
>
> If we have
> (puthash parent-key (make-hash-table : size CHILD-SIZE) parent-hash)
> then I want
> (gethash parent-key parent-hash)
> to return a *reference* to hash-table contained in parent-hash.

It already does. In Lisp, you _always_ get a reference for anything
beyond simple data types (as integers and friends).

> I already have a working code for this but I am uncertain how this
> will perform when CHILD-SIZE is really large.

Ah, it's performance you are worried about. No -- gethash isn't
returning a copy of the child table, but "the child table itself".
Change it and you'll see...

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFLCoLcBcgs9XrR2kYRAtlJAJ9t4UrnbsYeZTFatyV4qykL5zJ9bwCdGwGq
P2MC1udxN7bCG3zGScDgmJI=
=kXCM
-----END PGP SIGNATURE-----


Pascal J. Bourguignon

unread,
Nov 23, 2009, 9:10:44 AM11/23/09
to
Nordl�w <per.n...@gmail.com> writes:

> Is it possible for a hash-table to contain a *reference* to another
> hash-table, similar to how we can build arbitrary graphs using conses/
> lists and setf?

Yes.


There is not automatic copy ever done in lisp. You have to
explicitely copy the structures (such as cons, copy-list,
copy-hash-table, copy-my-struct, etc) you use if you want copies (or
use a function that explicitely copies the input data like append does
for all lists but the last). And for some types, there are even no
predefined copier function!


--
__Pascal Bourguignon__

0 new messages