Re: Case Insensitive Hash but still preserve cases of original keys [message #84598] |
Tue, 15 July 2014 19:44  |
SonicKenking
Messages: 51 Registered: October 2010
|
Member |
|
|
On Tuesday, July 15, 2014 10:32:30 PM UTC+10, fawltyl...@gmail.com wrote:
> On Tuesday, July 15, 2014 1:11:06 PM UTC+2, SonicKenking wrote:
>
>
>
>> What I am confused is how PRINT gets the value for the key "X"? It seems to me that it should call something like self["X"], i.e. SpecialHash::_overloadBracketsRightSide. However it is not the case and this can be verified by setting a breakpoint as well.
>
>
>
> There is an undocumented function hash::get:
>
>
>
> IDL> print, (hash(0,0))[0]
>
> 0
>
> IDL> .comp hash_get
>
> % Compiled module: HASH::GET.
>
> IDL> print, (hash(0,0))[0]
>
> HASH::GET called: 0
>
> 0
>
> IDL>
>
>
>
> hash_get.pro is:
>
>
>
> function hash::get, key, _extra=ext
>
> print, 'HASH::GET called: ', key
>
> return, 0
>
> end
>
>
>
> PRINT probably calls self.get(...), so you can try to add a SpecialHash::Get function.
>
>
>
> regards,
>
> Lajos
Thanks Lajos. Override the Get() function solves the problem!
Inspired by your answer, I dug a bit more into the HASH internals. So HASH sometimes works off the internal data structure (e.g. TABLE_DATA) without consulting the public APIs. This creates problem for subclasses that alter the behaviors of public APIs.
One more example is that the FOREACH loop of SpecialHash display the key 'x' in lowercase, while it really should be in uppercase.
IDL> foreach v,h, k do print, k, v
x 1337
My guess is that Hash's foreach implementation gets the keys directly from the internal self.TABLE_DATA structure. The keys() function hence never gets called and doesn't have the chance to provide the correct case of key 'X'
|
|
|
|
Re: Case Insensitive Hash but still preserve cases of original keys [message #89032 is a reply to message #89029] |
Wed, 16 July 2014 17:34   |
SonicKenking
Messages: 51 Registered: October 2010
|
Member |
|
|
On Thursday, July 17, 2014 7:28:22 AM UTC+10, Chris Torrence wrote:
> Hi all,
>
>
>
> Just FYI, in IDL 8.4 the HASH and ORDEREDHASH will have a new FOLD_CASE keyword. This will make the Hash and OrderedHash be case insensitive but still preserve the case of the keys, which I believe is exactly what you want.
>
>
>
> Cheers,
>
> Chris
Hi Chris,
That's a great news. Can't wait to see other new features in 8.4! Is there an estimated release date?
Thanks a lot for the response.
Cheers,
Yang
|
|
|
Re: Case Insensitive Hash but still preserve cases of original keys [message #89039 is a reply to message #89032] |
Thu, 17 July 2014 09:26   |
chris_torrence@NOSPAM
Messages: 528 Registered: March 2007
|
Senior Member |
|
|
On Wednesday, July 16, 2014 6:34:18 PM UTC-6, SonicKenking wrote:
> On Thursday, July 17, 2014 7:28:22 AM UTC+10, Chris Torrence wrote:
>
>> Hi all,
>
>>
>
>>
>
>>
>
>> Just FYI, in IDL 8.4 the HASH and ORDEREDHASH will have a new FOLD_CASE keyword. This will make the Hash and OrderedHash be case insensitive but still preserve the case of the keys, which I believe is exactly what you want.
>
>>
>
>>
>
>>
>
>> Cheers,
>
>>
>
>> Chris
>
>
>
> Hi Chris,
>
>
>
> That's a great news. Can't wait to see other new features in 8.4! Is there an estimated release date?
>
>
>
> Thanks a lot for the response.
>
>
>
> Cheers,
>
> Yang
Should be right around November. Lots of cool features, including code coverage, big integers, lambda functions, and static methods for variables...
-Chris
|
|
|
|
|
|
|
|
Re: Case Insensitive Hash but still preserve cases of original keys [message #89062 is a reply to message #89044] |
Mon, 21 July 2014 09:38  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
On 07/17/14 17:36, Michael Galloy wrote:
> On 7/17/14, 10:26 AM, Chris Torrence wrote:
>> Should be right around November. Lots of cool features, including
>> code coverage, big integers, lambda functions, and static methods for
>> variables... -Chris
>>
> Code coverage? Like which lines of a routine have been executed? That
> would be an awesome feature for mgunit; I would be able to report back a
> lot of useful information about the coverage of a test suite.
As an avid user of mgunit, that would be marvyplate. I am a lazy
unit-test writer... (downcast eyes) ...but isn't everyone? :o/
cheers,
paulv
|
|
|