unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* hash tables
@ 2008-03-27 14:48 David Roderick
  2008-03-28  1:15 ` Barry Margolin
  0 siblings, 1 reply; 2+ messages in thread
From: David Roderick @ 2008-03-27 14:48 UTC (permalink / raw)
  To: help-gnu-emacs

7.3 Defining Hash Comparisons
=============================

You can define new methods of key lookup by means of
`define-hash-table-test'.  In order to use this feature, you need to
understand how hash tables work, and what a "hash code" means.

   You can think of a hash table conceptually as a large array of many
slots, each capable of holding one association.  To look up a key,
`gethash' first computes an integer, the hash code, from the key.  It
reduces this integer modulo the length of the array, to produce an
index in the array.  Then it looks in that slot, and if necessary in
other nearby slots, to see if it has found the key being sought.

   Thus, to define a new method of key lookup, you need to specify both
a function to compute the hash code from a key, and a function to
compare two keys directly.


" It
reduces this integer modulo the length of the array,"

So does this mean that the integer must be times greater than the length
of the array, otherwise the integer is returned?

What happens if the hash table increases in size and this happens?
-- 
from 
David Roderick


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: hash tables
  2008-03-27 14:48 hash tables David Roderick
@ 2008-03-28  1:15 ` Barry Margolin
  0 siblings, 0 replies; 2+ messages in thread
From: Barry Margolin @ 2008-03-28  1:15 UTC (permalink / raw)
  To: help-gnu-emacs

In article <uiqz8w7db.fsf@tiscali.co.uk>,
 David Roderick <angel_ov_north@tiscali.co.uk> wrote:

> 7.3 Defining Hash Comparisons
> =============================
> 
> You can define new methods of key lookup by means of
> `define-hash-table-test'.  In order to use this feature, you need to
> understand how hash tables work, and what a "hash code" means.
> 
>    You can think of a hash table conceptually as a large array of many
> slots, each capable of holding one association.  To look up a key,
> `gethash' first computes an integer, the hash code, from the key.  It
> reduces this integer modulo the length of the array, to produce an
> index in the array.  Then it looks in that slot, and if necessary in
> other nearby slots, to see if it has found the key being sought.
> 
>    Thus, to define a new method of key lookup, you need to specify both
> a function to compute the hash code from a key, and a function to
> compare two keys directly.
> 
> 
> " It
> reduces this integer modulo the length of the array,"
> 
> So does this mean that the integer must be times greater than the length
> of the array, otherwise the integer is returned?

Yes.  Hash codes should generally be very large integers.

> What happens if the hash table increases in size and this happens?

When a hash table changes size, all the elements have to be rehashed and 
moved to the new locations.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-03-28  1:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-27 14:48 hash tables David Roderick
2008-03-28  1:15 ` Barry Margolin

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).