all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Hash-table elements
Date: Tue, 29 Sep 2009 15:17:08 +0200	[thread overview]
Message-ID: <7c7hvhki0b.fsf@pbourguignon.lefevre.anevia.com> (raw)
In-Reply-To: 0c37c5b5-6683-4705-a2e4-e0c5ccb34614@e12g2000yqi.googlegroups.com

Nordlöw <per.nordlow@gmail.com> writes:

> Can hash-tables contain references other "global" structures?
>
> I have a hash-table that maps filenames to their metadata,file-scan-
> hits/misses.
> I don't want to pull-change-push the whole meta-data value whenever I
> change parts of these metadata/hits.
>
> Is this possible somehow?

Yes.  Only do not modify the keys!  You wouldn't be able to retrieve
them, since changing the state of a key would probably change its hash
value, and therefore the bucket where the hash-table stored it.
But you can do whatever you want on the value.

(require 'cl)
(let ((h (make-hash-table)))

   (let ((value (list 1 2 3))
         (key   :my-list))

      (setf (gethash key h) value)
      (setf (car value) 0
            (cdr value) 'z)
      (gethash key h)))
--> (0 . z)

     
-- 
__Pascal Bourguignon__


  reply	other threads:[~2009-09-29 13:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-29  9:52 Hash-table elements Nordlöw
2009-09-29 13:17 ` Pascal J. Bourguignon [this message]
2009-10-01 14:52   ` Nordlöw
2009-10-01 15:18     ` Pascal J. Bourguignon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7c7hvhki0b.fsf@pbourguignon.lefevre.anevia.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.