ZEDA  1.6.18
zeda_rrtab.h
Go to the documentation of this file.
1 /* ZEDA - Elementary Data and Algorithms
2  * Copyright (C) 1998 Tomomichi Sugihara (Zhidao)
3  */
9 #ifndef __ZEDA_RRTAB_H__
10 #define __ZEDA_RRTAB_H__
11 
12 #include <zeda/zeda_misc.h>
13 
15 
16 /* ********************************************************** *//* ************************************************** */
19 
27 #define zRRTabClass(tab_t,cell_t) \
28 typedef struct{\
29  uint num;\
30  cell_t *buf;\
31 } tab_t;\
32 tab_t *tab_t##Alloc(tab_t *tab, uint n);\
33 void tab_t##Free(tab_t *tab);\
34 cell_t *tab_t##Cell(tab_t *tab, uint i, uint j);\
35 
36 #define zRRTabClassMethod(tab_t,cell_t) \
37 tab_t *tab_t##Alloc(tab_t *tab, uint n)\
38 {\
39  if( !( tab->buf = zAlloc( cell_t, n*(n-1)/2 ) ) ){\
40  ZALLOCERROR();\
41  return NULL;\
42  }\
43  tab->num = n;\
44  return tab;\
45 }\
46 void tab_t##Free(tab_t *tab)\
47 {\
48  zFree( tab->buf );\
49  tab->num = 0;\
50 }\
51 cell_t *tab_t##Cell(tab_t *tab, uint i, uint j)\
52 {\
53  if( i == j || i >= tab->num || j >= tab->num ) return NULL;\
54  if( i > j ) zSwap( int, i, j );\
55  return tab->buf + ( 2*tab->num - i - 1 ) * i / 2 + j - i - 1;\
56 }
57 
60 /* ********************************************************** *//* ************************************************** */
63 
75 
76 #define zRRBoolCheck(tab,i,j) ( zRRBoolCell(tab,i,j) ? *zRRBoolCell(tab,i,j) : false )
77 #define zRRBoolMark(tab,i,j) do{ if( zRRBoolCell(tab,i,j) ){ *zRRBoolCell(tab,i,j) = true; } } while( 0 )
78 #define zRRBoolUnmark(tab,i,j) do{ if( zRRBoolCell(tab,i,j) ){ *zRRBoolCell(tab,i,j) = false; } } while( 0 )
79 
83 
84 #endif /* __ZEDA_RRTAB_H__ */
#define __END_DECLS
Definition: zeda_defs.h:30
miscellanies.
#define __BEGIN_DECLS
Definition: zeda_defs.h:26
boolean table - an example of round-robin table.
Definition: zeda_rrtab.h:74
#define zRRTabClass(tab_t, cell_t)
generate round-robin table class.
Definition: zeda_rrtab.h:27