📄 sctpredg.h
字号:
/*-- yDel_SORT (Powerset)------------------------------------------*/
#define Powerset_Del(SORT, COMPONENTSORT, LOW, HIGH) \
SORT XCAT(yDel_,SORT) \
XPP_PROTO( (COMPONENTSORT Item, SORT PS) ) \
XPP_NOPROTO( (Item, PS) COMPONENTSORT Item; SORT PS; ) \
{ \
/* Modified by GBU,000103 in WIP only unsigned [0..HIGH] is used */ \
/* if (Item < LOW || Item > HIGH) return PS;*/ \
/* Item = Item - LOW;*/ \
if (Item > HIGH) return PS; \
PS.A[Item/32] = ~((unsigned long)1 << Item%32) & PS.A[Item/32]; \
return PS; \
}
/*-- yAnd_SORT (Powerset)------------------------------------------*/
#define Powerset_And(SORT, COMPONENTSORT, LOW, HIGH) \
SORT XCAT(yAnd_,SORT) \
XPP_PROTO( (SORT PS1, SORT PS2) ) \
XPP_NOPROTO( (PS1, PS2) SORT PS1; SORT PS2; ) \
{ \
SORT PS; \
int Item; \
\
for (Item=0; Item<=(HIGH-LOW)/32; Item++) \
PS.A[Item] = PS1.A[Item] & PS2.A[Item]; \
return PS; \
}
/*-- yOr_SORT (Powerset)-------------------------------------------*/
#define Powerset_Or(SORT, COMPONENTSORT, LOW, HIGH) \
SORT XCAT(yOr_,SORT) \
XPP_PROTO( (SORT PS1, SORT PS2) ) \
XPP_NOPROTO( (PS1, PS2) SORT PS1; SORT PS2; ) \
{ \
SORT PS; \
int Item; \
\
for (Item=0; Item<=(HIGH-LOW)/32; Item++) \
PS.A[Item] = PS1.A[Item] | PS2.A[Item]; \
return PS; \
}
/*-- yLE_SORT (Powerset)-------------------------------------------*/
#define Powerset_LE(SORT, COMPONENTSORT, LOW, HIGH) \
SDL_Boolean XCAT(yLE_,SORT) \
XPP_PROTO( (SORT PS1, SORT PS2) ) \
XPP_NOPROTO( (PS1, PS2) SORT PS1; SORT PS2; ) \
{ \
int Item; \
\
for (Item=0; Item<=(HIGH-LOW)/32; Item++) { \
if ( (PS2.A[Item] | PS1.A[Item]) ^ PS2.A[Item] ) \
return SDL_False; \
} \
return SDL_True; \
}
/*-- yLT_SORT (Powerset)-------------------------------------------*/
#define Powerset_LT(SORT, COMPONENTSORT, LOW, HIGH) \
SDL_Boolean XCAT(yLT_,SORT) \
XPP_PROTO( (SORT PS1, SORT PS2) ) \
XPP_NOPROTO( (PS1, PS2) SORT PS1; SORT PS2; ) \
{ \
int Item; \
for (Item=0; Item<=(HIGH-LOW)/32; Item++) { \
if ( (PS2.A[Item] | PS1.A[Item]) ^ PS2.A[Item] ) \
return SDL_False; \
} \
for (Item=0; Item<=(HIGH-LOW)/32; Item++) { \
if ( PS2.A[Item] ^ PS1.A[Item] ) \
return SDL_True; \
} \
return SDL_False; \
}
/*-- yGE_SORT (Powerset)-------------------------------------------*/
#define Powerset_GE(SORT, COMPONENTSORT, LOW, HIGH) \
SDL_Boolean XCAT(yGE_,SORT) \
XPP_PROTO( (SORT PS1, SORT PS2) ) \
XPP_NOPROTO( (PS1, PS2) SORT PS1; SORT PS2; ) \
{ \
int Item; \
for (Item=0; Item<=(HIGH-LOW)/32; Item++) { \
if ( (PS1.A[Item] | PS2.A[Item]) ^ PS1.A[Item] ) \
return SDL_False; \
} \
return SDL_True; \
}
/*-- yGT_SORT (Powerset)-------------------------------------------*/
#define Powerset_GT(SORT, COMPONENTSORT, LOW, HIGH) \
SDL_Boolean XCAT(yGT_,SORT) \
XPP_PROTO( (SORT PS1, SORT PS2) ) \
XPP_NOPROTO( (PS1, PS2) SORT PS1; SORT PS2; ) \
{ \
int Item; \
for (Item=0; Item<=(HIGH-LOW)/32; Item++) { \
if ( (PS1.A[Item] | PS2.A[Item]) ^ PS1.A[Item] ) \
return SDL_False; \
} \
for (Item=0; Item<=(HIGH-LOW)/32; Item++) { \
if ( PS1.A[Item] ^ PS2.A[Item] ) \
return SDL_True; \
} \
return SDL_False; \
}
/*-- yLength_SORT (Powerset)---------------------------------------*/
#define Powerset_Length(SORT, COMPONENTSORT, LOW, HIGH) \
SDL_Integer XCAT(yLength_,SORT) \
XPP_PROTO( (SORT PS) ) \
XPP_NOPROTO( (PS) SORT PS; ) \
{ \
int W, B; \
int NoOfComp; \
NoOfComp = 0; \
for (W=0; W<=(HIGH-LOW)/32; W++) { \
for (B=0; B<32; B++) { \
if (((unsigned long)1 << B) & PS.A[W]) \
NoOfComp++; \
} \
} \
return NoOfComp; \
}
/*-- yTake_SORT (Powerset)------------------------------------*/
#define Powerset_Take(SORT, COMPONENTSORT, LOW, HIGH) \
COMPONENTSORT XCAT(yTake_,SORT) \
XPP_PROTO( (SORT PS) ) \
XPP_NOPROTO( (PS) SORT PS; ) \
{ \
COMPONENTSORT Result; \
int W, B; \
for (W=0; W<=(HIGH-LOW)/32; W++) { \
for (B=0; B<32; B++) { \
if (((unsigned long)1 << B) & PS.A[W]) \
return (COMPONENTSORT)(LOW+W*32+B); \
} \
} \
xReportStringError("Take in Powerset sort", "Empty powerset") \
(void)memset((void *)(&Result), 0, sizeof(COMPONENTSORT)); \
XCAT(yDef_,COMPONENTSORT)(&Result); \
return Result; \
}
/*-- yTake2_SORT (Powerset)------------------------------------*/
#define Powerset_Take2(SORT, COMPONENTSORT, LOW, HIGH) \
COMPONENTSORT XCAT(yTake2_,SORT) \
XPP_PROTO( (SORT PS, SDL_Integer Index) ) \
XPP_NOPROTO( (PS, Index) SORT PS; SDL_Integer Index; ) \
{ \
COMPONENTSORT Result; \
int W, B; \
int NoOfComp; \
NoOfComp = 0; \
for (W=0; W<=(HIGH-LOW)/32; W++) { \
for (B=0; B<32; B++) { \
if (((unsigned long)1 << B) & PS.A[W]) { \
if (++NoOfComp == Index) \
return (COMPONENTSORT)(LOW+W*32+B); \
} \
} \
} \
xReportStringError("Take in Powerset sort", "Index out of range") \
(void)memset((void *)(&Result), 0, sizeof(COMPONENTSORT)); \
XCAT(yDef_,COMPONENTSORT)(&Result); \
return Result; \
}
/*-- yEq_SORT (Powerset)-------------------------------------------*/
#define Powerset_Equal(SORT, COMPONENTSORT, LOW, HIGH) \
SDL_Boolean XCAT(yEq_,SORT) \
XPP_PROTO( (SORT Expr1, SORT Expr2) ) \
XPP_NOPROTO( (Expr1, Expr2) SORT Expr1; SORT Expr2; ) \
{ \
int Item; \
for (Item=0; Item<=(HIGH-LOW)/32; Item++) { \
if ( Expr1.A[Item] ^ Expr2.A[Item] ) \
return SDL_False; \
} \
return SDL_True; \
}
/*-- yDef_SORT (Powerset)------------------------------------------*/
#define Powerset_Default(SORT, COMPONENTSORT, LOW, HIGH) \
void XCAT(yDef_,SORT) \
XPP_PROTO( (SORT *S) ) \
XPP_NOPROTO( (S) SORT *S; ) \
{ \
int Item; \
for (Item=0; Item<=(HIGH-LOW)/32; Item++) \
(*S).A[Item] = (unsigned long)0; \
}
/****+***************************************************************
07 Generator Powerset (general component type)
********************************************************************/
/* typedef for GPowerset type -------------------------------------*/
#define GPowerset_Type(SORT, COMPONENTSORT) \
typedef struct XCAT(SORT,_ystruct) * XCAT(SORT,_yptr); \
typedef struct XCAT(SORT,_ystruct) { \
XCAT(SORT,_yptr) Suc; \
COMPONENTSORT Data; \
} XCAT(SORT,_yrec); \
typedef struct { \
XCAT(SORT,_yptr) First; \
XCAT(SORT,_yptr) Last; \
int Length; \
xbool IsAssigned; \
} SORT;
#define GPowerset_prototypes(SORT, COMPONENTSORT) \
extern SORT XCAT(yEmpty_,SORT) XPP((void)); \
extern SDL_Boolean XCAT(yIn_,SORT) XPP((COMPONENTSORT, SORT)); \
extern SORT XCAT(yIncl_,SORT) XPP((COMPONENTSORT, SORT)); \
extern SORT XCAT(yDel_,SORT) XPP((COMPONENTSORT, SORT)); \
extern SDL_Boolean XCAT(yLT_,SORT) XPP((SORT, SORT)); \
extern SDL_Boolean XCAT(yGT_,SORT) XPP((SORT, SORT)); \
extern SDL_Boolean XCAT(yLE_,SORT) XPP((SORT, SORT)); \
extern SDL_Boolean XCAT(yGE_,SORT) XPP((SORT, SORT)); \
extern SORT XCAT(yAnd_,SORT) XPP((SORT, SORT)); \
extern SORT XCAT(yOr_,SORT) XPP((SORT, SORT)); \
extern SDL_Integer XCAT(yLength_,SORT) XPP((SORT)); \
extern COMPONENTSORT XCAT(yTake_,SORT) XPP((SORT)); \
extern COMPONENTSORT XCAT(yTake2_,SORT) XPP((SORT, SDL_Integer)); \
\
extern SORT XCAT(yCopyList_,SORT) XPP((SORT PS)); \
extern SDL_Boolean XCAT(yInInner_,SORT) \
XPP((COMPONENTSORT Item, SORT PS)); \
extern XCAT(SORT,_yptr) XCAT(yGetAvail_,SORT) XPP((void)); \
\
extern char * XCAT(yWri_,SORT) XPP((void * PS)); \
extern int XCAT(yRead_,SORT) XPP((void * Result));
/*-- yEmpty_SORT (GPowerset)---------------------------------------*/
#define GPowerset_Empty(SORT, COMPONENTSORT) \
XCAT(SORT,_yptr) XCAT(yGetAvail_,SORT) XPP((void)) \
{ \
XCAT(SORT,_yptr) Item; \
if (XCAT(yAvail_,SORT) != (XCAT(SORT,_yptr))0) { \
Item = XCAT(yAvail_,SORT); \
XCAT(yAvail_,SORT) = XCAT(yAvail_,SORT)->Suc; \
Item->Suc = (XCAT(SORT,_yptr))0; \
} else { \
Item = (XCAT(SORT,_yptr))xAlloc((unsigned)sizeof(XCAT(SORT,_yrec))); \
} \
return Item; \
} \
\
SORT XCAT(yEmpty_,SORT) XPP((void)) \
{ \
SORT Result; \
Result.First = (XCAT(SORT,_yptr))0; \
Result.Last = (XCAT(SORT,_yptr))0; \
Result.Length = 0; \
Result.IsAssigned = (xbool)0; \
return Result; \
}
/*-- yIn_SORT (GPowerset)------------------------------------------*/
#define GPowerset_In(SORT, COMPONENTSORT) \
SDL_Boolean XCAT(yInInner_,SORT) \
XPP_PROTO( (COMPONENTSORT Item, SORT PS) ) \
XPP_NOPROTO( (Item, PS) COMPONENTSORT Item; SORT PS; ) \
{ \
XCAT(SORT,_yptr) Temp; \
SDL_Boolean Result; \
Result = SDL_False; \
for (Temp=PS.First; \
Temp!=(XCAT(SORT,_yptr))0 && !Result; \
Temp=Temp->Suc) \
if ( XCAT(yEqF_,COMPONENTSORT)(Temp->Data, Item) ) \
Result = SDL_True; \
return Result; \
} \
\
SDL_Boolean XCAT(yIn_,SORT) \
XPP_PROTO( (COMPONENTSORT Item, SORT PS) ) \
XPP_NOPROTO( (Item, PS) COMPONENTSORT Item; SORT PS; ) \
{ \
SDL_Boolean Result; \
Result = XCAT(yInInner_,SORT)(Item, PS); \
if (! PS.IsAssigned) \
XCAT(yFree_,SORT)((void **)&PS); \
return Result; \
}
/*-- yIncl_SORT (GPowerset)----------------------------------------*/
#define GPowerset_Incl(SORT, COMPONENTSORT) \
SORT XCAT(yCopyList_,SORT) \
XPP_PROTO( (SORT PS) ) \
XPP_NOPROTO( (PS) SORT PS; ) \
{ \
XCAT(SORT,_yptr) TempPS, TempRes; \
SORT Result; \
Result = PS; \
Result.IsAssigned = (xbool)0; \
if (PS.First != (XCAT(SORT,_yptr))0 ) { \
TempPS = PS.First; \
TempRes = XCAT(yGetAvail_,SORT)(); \
XCAT(yAssF_,COMPONENTSORT)(TempRes->Data, TempPS->Data, XASS); \
Result.First = TempRes; \
while (TempPS->Suc != (XCAT(SORT,_yptr))0) { \
TempPS = TempPS->Suc; \
TempRes->Suc = XCAT(yGetAvail_,SORT)(); \
TempRes = TempRes->Suc; \
XCAT(yAssF_,COMPONENTSORT)(TempRes->Data, TempPS->Data, XASS); \
} \
Result.Last = TempRes; \
} \
return Result; \
} \
\
SORT XCAT(yIncl_,SORT) \
XPP_PROTO( (COMPONENTSORT Item, SORT PS) ) \
XPP_NOPROTO( (Item, PS) COMPONENTSORT Item; SORT PS; ) \
{ \
SORT Result; \
if (PS.IsAssigned) \
Result = XCAT(yCopyList_,SORT)(PS); \
else \
Result = PS; \
if (! XCAT(yInInner_,SORT)(Item, Result) ) { \
if (Result.Last == (XCAT(SORT,_yptr))0) { \
Result.Last = XCAT(yGetAvail_,SORT)(); \
Result.First = Result.Last; \
} else { \
Result.Last->Suc = XCAT(yGetAvail_,SORT)(); \
Result.Last = Result.Last->Suc; \
} \
XCAT(yAssF_,COMPONENTSORT)(Result.Last->Data, Item, XASS); \
Result.Length++; \
} \
return Result; \
}
/*-- yDel_SORT (GPowerset)-----------------------------------------*/
#define GPowerset_Del(SORT, COMPONENTSORT) \
SORT XCAT(yDel_,SORT) \
XPP_PROTO( (COMPONENTSORT Item, SORT PS) ) \
XPP_NOPROTO( (Item, PS) COMPONENTSORT Item; SORT PS; ) \
{ \
SORT Result; \
XCAT(SORT,_yptr) Temp, Prev; \
if (PS.IsAssigned) \
Result = XCAT(yCopyList_,SORT)(PS); \
else \
Result = PS; \
if ( Result.First != (XCAT(SORT,_yptr))0 ) { \
Prev = Result.First; \
if ( XCAT(yEqF_,COMPONENTSORT)(Prev->Data, Item) ) { \
Result.First = Prev->Suc; \
if (Result.Last == Prev) Result.Last = (XCAT(SORT,_yptr))0; \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -