set
Overview
Module that defines the macros to generate set types.
Type and Definitions
cSetInfo
struct cSetItr
{
int64_t count;
int64_t size;
float maxLoad;
};
typedef struct cSetItr cSetItr;
cSetInfo stores the properties of the set. The count value tells how much elements are stored in the set. The size shows how much memory is allocated, the maxLoad says how much percent of the size can be used without to grow.
cSetItr
typedef struct
{
int64_t _v;
} cSetItr;
Struct to iterate over the entries in a set.
Code Generation Macros
NEXT_IN_SET_C_
#define NEXT_IN_SET_C_( \
FuncSuffix, SetType, RowType, ValType, DoRefVal \
)
Generates a function that gets a pointer to the next value in the set after the iterator position. The generated function has the following common signatures:
cSetItr next_in_FuncSuffix( SetTyoe const* set,
cSetItr itr,
ValType const* val[static 1] );
)
The function gives only read access to the value. The returned iterator is invalid if no next value exist.
SET_STRUCTS_C_
#define SET_STRUCTS_C_( \
SetType, RowType, ValType \
)
Generates the structs that all functions in this module use.
struct RowType \
{ \
int32_t dist; \
union \
{ \
ValType k; \
ValType v; \
}; \
}; \
typedef struct RowType RowType; \
\
struct SetType \
{ \
RowType* array; \
uint8_t shift; \
cSetInfo i; \
}; \
typedef struct SetType SetType;
OBJ_SET_DEF_C_
#define OBJ_SET_DEF_C_( \
SetType, ObjType, FuncSuffix, Meta \
)
Generates the definition of a set to store objects from type ObjType for a .h file.
struct SetType;
typedef struct SetType SetType;
extern cMeta const Meta;
/**************************************/
SetType* make_FuncSuffix( int64_t size, float maxLoad );
SetType* new_FuncSuffix();
/**************************************/
cSetInfo const* info_of_##FuncSuffix( SetType const* set );
bool resize_FuncSuffix( SetType* set, int64_t size );
bool set_max_load_of_FuncSuffix( SetType* set, float maxLoad );
/**************************************/
bool in_FuncSuffix( SetType const* set, ObjType const* obj );
cSetItr next_in_FuncSuffix( SetType const* set,
cSetItr itr,
ObjType const* obj[static 1] );
bool remove_from_FuncSuffix( SetType* set, ObjType const* obj );
bool set_on_FuncSuffix( SetType* set, ObjType* obj );
OBJ_SET_IMPL_C_
#define OBJ_OBJ_MAP_IMPL_C_( \
Static, SetType, RowType, ObjType, FuncSuffix, Meta, HashFunc, CmpFunc \
)
Generates the implementation of a set to store objects from type ObjType for a .c file. The Static value can be used to define the visibility of the functions.
struct SetType;
typedef struct SetType SetType;
struct RowType;
typedef RowType RowType;
extern cMeta const Meta;
/**************************************/
SetType* make_FuncSuffix( int64_t size, float maxLoad );
SetType* new_FuncSuffix();
/**************************************/
cSetInfo const* info_of_##FuncSuffix( SetType const* set );
bool resize_FuncSuffix( SetType* set, int64_t size );
bool set_max_load_of_FuncSuffix( SetType* set, float maxLoad );
/**************************************/
bool in_FuncSuffix( SetType const* set, ObjType const* obj );
cSetItr next_in_FuncSuffix( SetType const* set,
cSetItr itr,
ObjType const* obj[static 1] );
bool remove_from_FuncSuffix( SetType* set, ObjType const* obj );
bool set_on_FuncSuffix( SetType* set, ObjType* obj );
/**************************************/
bool intl_erase_in_FuncSuffix( SetType* set, int64_t index, RowType* oldRow );
int64_t intl_index_in_FuncSuffix( SetType* set, uint64_t hash, KeyType key );
bool intl_set_on_FuncSuffix( SetType* set,
uint64_t hash,
RowType* row,
RowType* out );
VAL_SET_DEF_C_
#define VAL_SET_DEF_C_( \
SetType, ValType, FuncSuffix, Meta \
)
Generates the definition of a set to store values from type ValType for a .h file.
struct SetType;
typedef struct SetType SetType;
extern cMeta const Meta;
/**************************************/
SetType* make_FuncSuffix( int64_t size, float maxLoad );
SetType* new_FuncSuffix();
/**************************************/
cSetInfo const* info_of_FuncSuffx( SetType const* set );
bool resize_FuncSuffix( SetType* set, int64_t size );
bool set_max_load_of_FuncSuffix( SetType* set, float maxLoad );
/**************************************/
bool in_FuncSuffix( SetType const* set, ValType val );
cSetItr next_in_FuncSuffix( SetType const* set,
cSetItr itr,
ValType const* val[static 1] );
bool remove_from_FuncSuffix( SetType* set, ValType val );
bool set_on_FuncSuffix( SetType* set, ValType val );
VAL_SET_IMPL_C_
#define VAL_SET_IMPL_C_( \
Static, SetType, RowType, ValType, \
FuncSuffix, Meta, HashFunc, CmpFunc, DoRef \
)
Generates the implementation of a set to store values from type ValType for a .c file. The Static value can be used to define the visibility of the functions.
struct SetType;
typedef struct SetType SetType;
struct RowType;
typedef struct RowType RowType;
extern cMeta const Meta;
/**************************************/
SetType* make_FuncSuffix( int64_t size, float maxLoad );
SetType* new_FuncSuffix();
/**************************************/
cSetInfo const* info_of_FuncSuffx( SetType const* set );
bool resize_FuncSuffix( SetType* set, int64_t size );
bool set_max_load_of_FuncSuffix( SetType* set, float maxLoad );
/**************************************/
bool in_FuncSuffix( SetType const* set, ValType val );
cSetItr next_in_FuncSuffix( SetType const* set,
cSetItr itr,
ValType const* val[static 1] );
bool remove_from_FuncSuffix( SetType* set, ValType val );
bool set_on_FuncSuffix( SetType* set, ValType val );
/**************************************/
bool intl_erase_in_FuncSuffix( SetType* set, int64_t index, RowType* oldRow );
int64_t intl_index_in_FuncSuffix( SetType* set, uint64_t hash, KeyType key );
bool intl_set_on_FuncSuffix( SetType* set,
uint64_t hash,
RowType* row,
RowType* out );
Functions
info
set_cap_c
int64_t set_cap_c( cSetInfo const info[static 1] );
Returns the capacity of a set.
set_load_c
float set_load_c( cSetInfo const info[static 1] );
Returns the load factor of a set.
set_is_empty_c
bool set_is_empty_c( cSetInfo const info[static 1] );
Returns true if a set is empty, otherwise false.
itr
iterate_set_c_
#define iterate_set_c_( Itr, ValPtr, Set, Func )
Macro function to define a for statement to iterate over all elements in a map.
#include "clingo/lang/expect.h"
#include "clingo/container/CInt64Set.h"
int main( void )
{
init_tap_c_();
CInt64Set* set = retain_c( new_int64_set_c() );
{
set_on_int64_set_c( set, 1000 );
set_on_int64_set_c( set, 200 );
set_on_int64_set_c( set, 30 );
set_on_int64_set_c( set, 4 );
}
int64_t res = 0;
int64_t const* val;
iterate_set_c_( itr, val, set, next_in_int64_set_c )
{
res += *val;
}
expect_c_( res == 1234 );
release_c( set );
return finish_tap_c_();
}
start_set_itr_c
cSetItr start_set_itr_c();
Function that returns a cSetItr value to get the first value in the set.
set_itr_is_valid_c
bool set_itr_is_valid_c( cSetItr itr );
Function to check if the iterator is valid.