ZEDA  1.6.18
Macros
universal round-robin table.

Macros

#define zRRTabClass(tab_t, cell_t)
 generate round-robin table class. More...
 
#define zRRTabClassMethod(tab_t, cell_t)
 

Detailed Description

Macro Definition Documentation

◆ zRRTabClass

#define zRRTabClass (   tab_t,
  cell_t 
)
Value:
typedef struct{\
uint num;\
cell_t *buf;\
} tab_t;\
tab_t *tab_t##Alloc(tab_t *tab, uint n);\
void tab_t##Free(tab_t *tab);\
cell_t *tab_t##Cell(tab_t *tab, uint i, uint j);\
unsigned int uint
Definition: zeda_defs.h:104

generate round-robin table class.

A macro zRRTabClass() can generate a new round-robin table class, which consists of the table size and the pointer to the buffer.

◆ zRRTabClassMethod

#define zRRTabClassMethod (   tab_t,
  cell_t 
)
Value:
tab_t *tab_t##Alloc(tab_t *tab, uint n)\
{\
if( !( tab->buf = zAlloc( cell_t, n*(n-1)/2 ) ) ){\
ZALLOCERROR();\
return NULL;\
}\
tab->num = n;\
return tab;\
}\
void tab_t##Free(tab_t *tab)\
{\
zFree( tab->buf );\
tab->num = 0;\
}\
cell_t *tab_t##Cell(tab_t *tab, uint i, uint j)\
{\
if( i == j || i >= tab->num || j >= tab->num ) return NULL;\
if( i > j ) zSwap( int, i, j );\
return tab->buf + ( 2*tab->num - i - 1 ) * i / 2 + j - i - 1;\
}
#define zAlloc(t, n)
Definition: zeda_misc.h:81
#define zSwap(type, a, b)
swap values of two data a and b. type the data type of a and b.
Definition: zeda_misc.h:56
unsigned int uint
Definition: zeda_defs.h:104