Accessing dict in C

Lee's icon

Hi, I've got a dict which contains an array of number as the value for the key, e.g.

{
    "11000004" : [ 1, 4 ],
    "11000911" : [ 18, 1 ],
    "11000161" : [ 1464, 1 ],
    "11000171" : [ 1465, 1 ],
    "11000321" : [ 3, 1 ],
....
}

I'm trying to walk through the dict and then process the number list for each entry. Have the walking done and retrieving the value as a t_object, but then not sure what to do at that point.. Any help? thx

hashtab_getkeys( m_p_sysex_dict->d_hashtab, &num_keys, &keys );

for( int i = 0; i < num_keys; i++ ) {
t_symbol *key = keys[ i ];
t_object *p_val = nullptr;

hashtab_lookup( m_p_sysex_dict->d_hashtab, keys[ i ], &p_val );

if ( p_val ) {
// how do I get the array of numbers here?
}

Luigi Castelli's icon

Hi there,

first and foremost you don't want to access the struct fields of a dictionary directly. There is an API for this.
To retrieve all of the key names stored in a dictionary, use the dictionary_getkeys() and dictionary_freekeys() functions.

If you want to implement a customized way of processing each entry in a dictionary, use the following technique:
call the function dictionary_funall() and implement your own callback method.
The dictionary_entry_getkey(), dictionary_entry_getvalue() and dictionary_entry_getvalues() functions might be of help in the implementation of your customized callback method.

If you read the ext_dictionary.h file part of the Max SDK you'll find more information and even some example code that will make your life easier for sure.

Hope this helps.

- Luigi

Lee's icon

Hi - thanks for the info - will check that out!

Lee's icon

all good now, thanks!