Re: How best to implement a hash table in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg125121] Re: How best to implement a hash table in Mathematica
- From: Joseph Gwinn <joegwinn at comcast.net>
- Date: Wed, 22 Feb 2012 05:33:15 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jho21j$5sb$1@smc.vnet.net> <jhqmrr$fbq$1@smc.vnet.net> <jhstsv$nk0$1@smc.vnet.net> <jhvuoi$891$1@smc.vnet.net>
In article <jhvuoi$891$1 at smc.vnet.net>, Szabolcs Horvát <szhorvat at gmail.com> wrote: > On 2/20/2012 9:48 AM, Joseph Gwinn wrote: > > > > The reason to initialize the hashtable in advance is so a later probe to > > an empty table element yields {}, versus repeating the question back. > > > > > > I probably don't understand your question completely, but why can't you > just make definition like > > hashtable[_] = {} > > ? This will ensure that {} is returned for "undefined" keys. I'll have to try this and related approaches, but it's not the entire hashtable that's empty, it's this or that element of said hashtable. > Also, please avoid using symbols that start with a capital letter. > HashTable is a built-in symbol and if you define it (as you did in the > example code you sent), it is likely to break stuff. Well, I use initial (and embedded) caps all the time, for readable symbols, and Mathematica does sometimes balk, so I make the symbol a word longer. As for HashTable, Mathematica complained, so I changed it to BigHashTable, and peace was restored. Joe Gwinn