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_DEF_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_( str_c( "Germany" ), str_c( "Deutschland" ) ),
      i_( str_c( "Spain" ), str_c( "Spanien" ) ),
      i_( str_c( "France" ), str_c( "Frankreich" ) ),
      i_( str_c( "Germany" ), str_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}", string_cstr_c( key ), string_cstr_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.

cMeta const C_DictionaryMeta;
/* create */
CDictionary* make_dictionary_c( int64_t size, float maxLoad );
CDictionary* new_dictionary_c();
/* manage */
cMapInfo const* info_of_dictionary_c( CDictionary const* map );
bool resize_dictionary_c( CDictionary* map, int64_t cap );
bool set_max_load_of_dictionary_c( CDictionary* map, float maxLoad );
/* iterate */
bool next_in_dictionary_c( CDictionary const* map, cMapItr itr[static 1] );
bool next_var_in_dictionary_c( CDictionary* map, cVarMapItr itr[static 1] );
/* api */
int64_t const* get_from_dictionary_c( CDictionary const* map, int64_t const* key );
bool in_dictionary_c( CDictionary const* map, int64_t const* key );
bool remove_from_dictionary_c( CDictionary* map, int64_t const* key );
bool set_on_dictionary_c( CDictionary* map, int64_t const* key, int64_t const* 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.