Re: How best to implement a hash table in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg125105] Re: How best to implement a hash table in Mathematica
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Tue, 21 Feb 2012 06:17: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>
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. 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. -- Szabolcs Horvát Visit Mathematica.SE: http://mathematica.stackexchange.com/