SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => SlickEdit User Macros => Topic started by: jporkkahtc on September 06, 2016, 01:45:51 am

Title: HashTables and isempty and null pointers
Post by: jporkkahtc on September 06, 2016, 01:45:51 am

Can you explain how Slick manages hashtables and arrays?




How do you ask if a hashtable has a specific entry without creating the entry?
What is the difference between a "null" object and an "_isempty" object?




&s_nameIndex:["Two"]
returns a pointer to the "Two" element - fine.
But, what about when you look up elements that don't exist?

 
&s_nameIndex:["Four"]

In the debugger, when this statement is executed s_nameIndex grows from 3 to 4 elements.
The new element is shown as "null", yet what is the thing returned by taking the address of a "null" object?
Even though the debugger shows the entry in the hashtable as null, when I reference it it seems like an object because the pointer doesn't compare= to null, but it _isempty() is true.




Whereas this statement

 
    NameIndex *x = &s_nameIndex._el("Four"); x->m_name="newName"; 

Apparently allocates a NameIndex - as the entry in the hashtable changes from null to a valid NameIndex.


See the attached code.

Title: Re: HashTables and isempty and null pointers
Post by: Bamsen on September 06, 2016, 07:35:47 am
From one of my scripts:
Code: [Select]
if (Linjer:[sTemp] == null) { Linjer:[sTemp]=AddValue; } else { Linjer:[sTemp]+=AddValue; }
This creates the hash variable with a specific value if it does not exist.
If it does exist, it adds the value to the existing one.
Title: Re: HashTables and isempty and null pointers
Post by: jporkkahtc on September 06, 2016, 06:43:33 pm
Yes, but when you do that it creates new entries in the hash table.
Just doing this:
if (Linjer:["foo"] == null)
will insert a null "foo" entry and increase the size of the hashtable by 1.

Title: Re: HashTables and isempty and null pointers
Post by: Clark on September 07, 2016, 03:26:09 am
To avoid adding entries to a hash table, use the _indexin() method.

if (hashtab._indexin('abc') && hashtab:['abc']==null) ...