[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Hash-table elements
From: |
Pascal J. Bourguignon |
Subject: |
Re: Hash-table elements |
Date: |
Tue, 29 Sep 2009 15:17:08 +0200 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux) |
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__