MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

keys in a hash table (aka, all assigned indices in an array): awful hack

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13281] keys in a hash table (aka, all assigned indices in an array): awful hack
  • From: Daniel Reeves <dreeves at flip.eecs.umich.edu>
  • Date: Fri, 17 Jul 1998 03:18:30 -0400
  • Organization: University of Michigan EECS
  • Sender: owner-wri-mathgroup at wolfram.com

suppose I make some assignments like this:
  fruits[apple]= crunchy
  fruits[lemon]= sour

I'm treating fruits like a hash table and now I would like a list of all
the keys.  In this case {apple,lemon}.

It seems like there should be an easy way to do this. All I came up with
was the following hack:

keys[hash_]:= 
  DownValues[hash] /. {RuleDelayed->(#&), hash->(#&)} //ReleaseHold


the hash values will be simple; we can just do fruits/@keys[fruits]

Thanks,
Daniel

--
Daniel Reeves  dreeves at umich.edu  http://interlabs.bradley.edu/~daniel

"Computer Science is no more about computers than astronomy is about
telescopes."  -- E W Dijkstra



  • Prev by Date: differences between math and mathematica
  • Next by Date: Re: 3DGraphics color problem
  • Previous by thread: Re: differences between math and mathematica
  • Next by thread: Re: keys in a hash table (aka, all assigned indices in an array): awful hack