CDictionary

Overview

Module that defines the CDictionary and the associated functions.

Example
#include "clingo/io/print.h"
#include "clingo/lang/expect.h"
#include "clingo/string/CDictionary.h"

TEMP_SLICE_C_(
   input,
   {
      CString* k;
      CString* v;
   }
)
#define i_( ... ) ((input){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   CDictionary* dict = retain_c( make_dictionary_c( 4, 0.5f ) );

   inputSlice inputs = slice_c_( input,
      i_( lit_c( "Germany" ), lit_c( "Deutschland" ) ),
      i_( lit_c( "Spain" ), lit_c( "Spanien" ) ),
      i_( lit_c( "France" ), lit_c( "Frankreich" ) ),
      i_( lit_c( "Germany" ), lit_c( "Alemania" ) )
   );
   for_each_c_( input const* ,i, inputs )
   {
      require_c_( i->k and i->v );
      require_c_( set_on_dictionary_c( dict, i->k, i->v ) );
   }

   CString const* key;
   CString const* val;
   iterate_map_c_( itr, key, val, dict, next_in_dictionary_c )
   {
      cRecorder* rec = &recorder_c_( 128 );
      write_c_( rec, "{s} -> {s}", scstr_c( key ), scstr_c( val ) );
      println_recorded_c( rec );
   }

   require_c_( remove_via_cstr_from_dictionary_c( dict, "France" ) );

   release_c( dict );

   return finish_tap_c_();
}

Types and Definitions

Generated

CDictionary

struct CDictionary;
typedef struct CDictionary CDictionary;

Via the macros OBJ_OBJ_MAP_DEF_C_ and OBJ_OBJ_MAP_IMPL_C_ declared and implemented struct. The macros declare and implement also the following globals and functions.

/* create */
CDictionary* make_dictionary_c( int64_t size, float maxLoad );
CDictionary* new_dictionary_c( void );
/* manage */
cMapInfo const* info_of_dictionary_c( CDictionary const* map );
bool resize_dictionary_c( {ValMap-MapType}* map, int64_t cap );
bool set_max_load_of_dictionary_c( CDictionary* map, float maxLoad );
/* iterate */
cMapItr next_in_dictionary_c( CDictionary const* map,
                             cMapItr itr,
                             CString const* key[static 1],
                             CString const* val[static 1 ]);
cMapItr next_var_in_dictionary_c( CDictionary* map,
                                 cMapItr itr,
                                 CString const* key[static 1],
                                 CString* val[static 1 ]);
/* api */
CString* get_from_dictionary_c( CDictionary const* map, {ValMap-KeyType} const* key );
bool in_dictionary_c( CDictionary const* map, CString const* key );
bool remove_from_dictionary_c( CDictionary* map, CString const* key );
bool set_on_dictionary_c( CDictionary* map,
                         CString* key,
                         CString* val );

Functions

wrap

chars_in_dictionary_c

bool chars_in_dictionary_c( CDictionary* dict, cChars key );

Util function that wraps in_dictionary_c.

cstr_in_dictionary_c

bool cstr_in_dictionary_c( CDictionary* dict, char const key[static 1] );

Util function that wraps in_dictionary_c.

get_via_chars_from_dictionary_c

CString* get_via_chars_from_dictionary_c( CDictionary* dict, cChars key );

Util function that wraps get_from_dictionary_c.

get_via_cstr_from_dictionary_c

CString* get_via_cstr_from_dictionary_c( CDictionary* dict,
                                         char const key[static 1] );

Util function that wraps get_from_dictionary_c.

remove_via_chars_from_dictionary_c

bool remove_via_chars_from_dictionary_c( CDictionary* dict, cChars key );

Util function that wraps remove_from_dictionary_c.

remove_via_cstr_from_dictionary_c

bool remove_via_cstr_from_dictionary_c( CDictionary* dict,
                                        char const key[static 1] );

Util function that wraps remove_from_dictionary_c.

set_chars_on_dictionary_c

bool set_chars_on_dictionary_c( CDictionary* dict, cChars key, cChars val );

Util function that wraps set_on_dictionary_c.

set_cstr_on_dictionary_c

bool set_cstr_on_dictionary_c( CDictionary* dict,
                               char const key[static 1],
                               char const val[static 1] );

Util function that wraps set_on_dictionary_c.