* Hash-tables containing references to hash-tables
@ 2009-11-23 11:12 Nordlöw
2009-11-23 12:41 ` tomas
2009-11-23 14:10 ` Pascal J. Bourguignon
0 siblings, 2 replies; 3+ messages in thread
From: Nordlöw @ 2009-11-23 11:12 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Hash-tables containing references to hash-tables
2009-11-23 11:12 Hash-tables containing references to hash-tables Nordlöw
@ 2009-11-23 12:41 ` tomas
2009-11-23 14:10 ` Pascal J. Bourguignon
1 sibling, 0 replies; 3+ messages in thread
From: tomas @ 2009-11-23 12:41 UTC (permalink / raw)
To: Nordlöw; +Cc: help-gnu-emacs
-----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-----
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Hash-tables containing references to hash-tables
2009-11-23 11:12 Hash-tables containing references to hash-tables Nordlöw
2009-11-23 12:41 ` tomas
@ 2009-11-23 14:10 ` Pascal J. Bourguignon
1 sibling, 0 replies; 3+ messages in thread
From: Pascal J. Bourguignon @ 2009-11-23 14:10 UTC (permalink / raw)
To: help-gnu-emacs
Nordlöw <per.nordlow@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__
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-11-23 14:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-23 11:12 Hash-tables containing references to hash-tables Nordlöw
2009-11-23 12:41 ` tomas
2009-11-23 14:10 ` Pascal J. Bourguignon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).