Accessing dict in C


    Dec 22 2016 | 2:31 pm
    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? }

    • Dec 23 2016 | 1:03 pm
      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
    • Dec 23 2016 | 10:50 pm
      Hi - thanks for the info - will check that out!
    • Dec 27 2016 | 4:28 pm
      all good now, thanks!