1 2 #define GB_GETA( aval, ax, p) aval = (T_Z)ax[ ( p )] 3 #define GB_GETB( bval, bx, p) bval = (T_Z)bx[ ( p )] 4 #define GB_FLIP(i) (-(i)-2) 5 #define GB_IS_FLIPPED(i) ((i) < 0) 6 #define GB_IS_ZOMBIE(i) ((i) < 0) 7 #define GB_IS_NOT_FLIPPED(i) ((i) >= 0) 8 #define GB_IS_NOT_ZOMBIE(i) ((i) >= 0) 9 #define GB_UNFLIP(i) (((i) < 0) ? GB_FLIP(i) : (i)) 10 11 //------------------------------------------------------------------------------ 12 // GB_BINARY_SEARCH 13 //------------------------------------------------------------------------------ 14 15 // search for integer i in the list X [pleft...pright]; no zombies. 16 // The list X [pleft ... pright] is in ascending order. It may have 17 // duplicates. 18 19 #define GB_BINARY_TRIM_SEARCH(i,X,pleft,pright) \ 20 { \ 21 /* binary search of X [pleft ... pright] for integer i */ \ 22 while (pleft < pright) \ 23 { \ 24 int64_t pmiddle = (pleft + pright) / 2 ; \ 25 if (X [pmiddle] < i) \ 26 { \ 27 /* if in the list, it appears in [pmiddle+1..pright] */ \ 28 pleft = pmiddle + 1 ; \ 29 } \ 30 else \ 31 { \ 32 /* if in the list, it appears in [pleft..pmiddle] */ \ 33 pright = pmiddle ; \ 34 } \ 35 } \ 36 /* binary search is narrowed down to a single item */ \ 37 /* or it has found the list is empty */ \ 38 /*ASSERT (pleft == pright || pleft == pright + 1) ;*/ \ 39 } 40