/* handler for function 5 */ static Obj HdlrFunc5 ( Obj self, Obj a_flags ) { Obj l_with = 0; Obj l_changed = 0; Obj l_imp = 0; Obj l_hash = 0; Obj l_hash2 = 0; Obj l_i = 0; Obj t_1 = 0; Obj t_2 = 0; Obj t_3 = 0; Obj t_4 = 0; Obj t_5 = 0; Obj t_6 = 0; Obj t_7 = 0; Obj t_8 = 0; Obj t_9 = 0; Obj t_10 = 0; Obj t_11 = 0; Bag oldFrame; OLD_BRK_CURR_STAT /* allocate new stack frame */ SWITCH_TO_NEW_FRAME(self,0,0,oldFrame); REM_BRK_CURR_STAT(); SET_BRK_CURR_STAT(0); /* hash := HASH_FLAGS( flags ) mod 11001; */ t_3 = GF_HASH__FLAGS; t_2 = CALL_1ARGS( t_3, a_flags ); CHECK_FUNC_RESULT( t_2 ) t_1 = MOD( t_2, INTOBJ_INT(11001) ); l_hash = t_1; /* for i in [ 0 .. 3 ] do */ for ( t_1 = INTOBJ_INT(0); ((Int)t_1) <= ((Int)INTOBJ_INT(3)); t_1 = (Obj)(((UInt)t_1)+4) ) { l_i = t_1; /* hash2 := 2 * ((hash + 31 * i) mod 11001) + 1; */ C_PROD_INTOBJS( t_6, INTOBJ_INT(31), l_i ) C_SUM_FIA( t_5, l_hash, t_6 ) t_4 = MOD( t_5, INTOBJ_INT(11001) ); C_PROD_FIA( t_3, INTOBJ_INT(2), t_4 ) C_SUM_FIA( t_2, t_3, INTOBJ_INT(1) ) l_hash2 = t_2; /* if IsBound( WITH_IMPS_FLAGS_CACHE[hash2] ) then */ t_4 = GC_WITH__IMPS__FLAGS__CACHE; CHECK_BOUND( t_4, "WITH_IMPS_FLAGS_CACHE" ) CHECK_INT_POS( l_hash2 ) t_3 = C_ISB_LIST( t_4, l_hash2 ); t_2 = (Obj)(UInt)(t_3 != False); if ( t_2 ) { /* if IS_IDENTICAL_OBJ( WITH_IMPS_FLAGS_CACHE[hash2], flags ) then */ t_4 = GF_IS__IDENTICAL__OBJ; t_6 = GC_WITH__IMPS__FLAGS__CACHE; CHECK_BOUND( t_6, "WITH_IMPS_FLAGS_CACHE" ) C_ELM_LIST_FPL( t_5, t_6, l_hash2 ) t_3 = CALL_2ARGS( t_4, t_5, a_flags ); CHECK_FUNC_RESULT( t_3 ) CHECK_BOOL( t_3 ) t_2 = (Obj)(UInt)(t_3 != False); if ( t_2 ) { /* WITH_IMPS_FLAGS_CACHE_HIT := WITH_IMPS_FLAGS_CACHE_HIT + 1; */ t_3 = GC_WITH__IMPS__FLAGS__CACHE__HIT; CHECK_BOUND( t_3, "WITH_IMPS_FLAGS_CACHE_HIT" ) C_SUM_FIA( t_2, t_3, INTOBJ_INT(1) ) AssGVar( G_WITH__IMPS__FLAGS__CACHE__HIT, t_2 ); /* return WITH_IMPS_FLAGS_CACHE[hash2 + 1]; */ t_3 = GC_WITH__IMPS__FLAGS__CACHE; CHECK_BOUND( t_3, "WITH_IMPS_FLAGS_CACHE" ) C_SUM_FIA( t_4, l_hash2, INTOBJ_INT(1) ) CHECK_INT_POS( t_4 ) C_ELM_LIST_FPL( t_2, t_3, t_4 ) RES_BRK_CURR_STAT(); SWITCH_TO_OLD_FRAME(oldFrame); return t_2; } /* fi */ } /* else */ else { /* break; */ break; } /* fi */ } /* od */ /* if i = 3 then */ t_1 = (Obj)(UInt)(((Int)l_i) == ((Int)INTOBJ_INT(3))); if ( t_1 ) { /* WITH_IMPS_FLAGS_COUNT := (WITH_IMPS_FLAGS_COUNT + 1) mod 4; */ t_3 = GC_WITH__IMPS__FLAGS__COUNT; CHECK_BOUND( t_3, "WITH_IMPS_FLAGS_COUNT" ) C_SUM_FIA( t_2, t_3, INTOBJ_INT(1) ) t_1 = MOD( t_2, INTOBJ_INT(4) ); AssGVar( G_WITH__IMPS__FLAGS__COUNT, t_1 ); /* i := WITH_IMPS_FLAGS_COUNT; */ t_1 = GC_WITH__IMPS__FLAGS__COUNT; CHECK_BOUND( t_1, "WITH_IMPS_FLAGS_COUNT" ) l_i = t_1; /* hash2 := 2 * ((hash + 31 * i) mod 11001) + 1; */ C_PROD_FIA( t_5, INTOBJ_INT(31), l_i ) C_SUM_FIA( t_4, l_hash, t_5 ) t_3 = MOD( t_4, INTOBJ_INT(11001) ); C_PROD_FIA( t_2, INTOBJ_INT(2), t_3 ) C_SUM_FIA( t_1, t_2, INTOBJ_INT(1) ) l_hash2 = t_1; } /* fi */ /* WITH_IMPS_FLAGS_CACHE_MISS := WITH_IMPS_FLAGS_CACHE_MISS + 1; */ t_2 = GC_WITH__IMPS__FLAGS__CACHE__MISS; CHECK_BOUND( t_2, "WITH_IMPS_FLAGS_CACHE_MISS" ) C_SUM_FIA( t_1, t_2, INTOBJ_INT(1) ) AssGVar( G_WITH__IMPS__FLAGS__CACHE__MISS, t_1 ); /* with := flags; */ l_with = a_flags; /* changed := true; */ t_1 = True; l_changed = t_1; /* while changed od */ while ( 1 ) { t_1 = (Obj)(UInt)(l_changed != False); if ( ! t_1 ) break; /* changed := false; */ t_1 = False; l_changed = t_1; /* for imp in IMPLICATIONS do */ t_4 = GC_IMPLICATIONS; CHECK_BOUND( t_4, "IMPLICATIONS" ) if ( IS_SMALL_LIST(t_4) ) { t_3 = (Obj)(UInt)1; t_1 = INTOBJ_INT(1); } else { t_3 = (Obj)(UInt)0; t_1 = CALL_1ARGS( GF_ITERATOR, t_4 ); } while ( 1 ) { if ( t_3 ) { if ( LEN_LIST(t_4) < INT_INTOBJ(t_1) ) break; t_2 = ELMV0_LIST( t_4, INT_INTOBJ(t_1) ); t_1 = (Obj)(((UInt)t_1)+4); if ( t_2 == 0 ) continue; } else { if ( CALL_1ARGS( GF_IS_DONE_ITER, t_1 ) != False ) break; t_2 = CALL_1ARGS( GF_NEXT_ITER, t_1 ); } l_imp = t_2; /* if IS_SUBSET_FLAGS( with, imp[2] ) and not IS_SUBSET_FLAGS( with, imp[1] ) then */ t_8 = GF_IS__SUBSET__FLAGS; C_ELM_LIST_FPL( t_9, l_imp, INTOBJ_INT(2) ) t_7 = CALL_2ARGS( t_8, l_with, t_9 ); CHECK_FUNC_RESULT( t_7 ) CHECK_BOOL( t_7 ) t_6 = (Obj)(UInt)(t_7 != False); t_5 = t_6; if ( t_5 ) { t_10 = GF_IS__SUBSET__FLAGS; C_ELM_LIST_FPL( t_11, l_imp, INTOBJ_INT(1) ) t_9 = CALL_2ARGS( t_10, l_with, t_11 ); CHECK_FUNC_RESULT( t_9 ) CHECK_BOOL( t_9 ) t_8 = (Obj)(UInt)(t_9 != False); t_7 = (Obj)(UInt)( ! ((Int)t_8) ); t_5 = t_7; } if ( t_5 ) { /* with := AND_FLAGS( with, imp[1] ); */ t_6 = GF_AND__FLAGS; C_ELM_LIST_FPL( t_7, l_imp, INTOBJ_INT(1) ) t_5 = CALL_2ARGS( t_6, l_with, t_7 ); CHECK_FUNC_RESULT( t_5 ) l_with = t_5; /* changed := true; */ t_5 = True; l_changed = t_5; } /* fi */ } /* od */ } /* od */ /* WITH_IMPS_FLAGS_CACHE[hash2] := flags; */ t_1 = GC_WITH__IMPS__FLAGS__CACHE; CHECK_BOUND( t_1, "WITH_IMPS_FLAGS_CACHE" ) CHECK_INT_POS( l_hash2 ) C_ASS_LIST_FPL( t_1, l_hash2, a_flags ) /* WITH_IMPS_FLAGS_CACHE[hash2 + 1] := with; */ t_1 = GC_WITH__IMPS__FLAGS__CACHE; CHECK_BOUND( t_1, "WITH_IMPS_FLAGS_CACHE" ) C_SUM_FIA( t_2, l_hash2, INTOBJ_INT(1) ) CHECK_INT_POS( t_2 ) C_ASS_LIST_FPL( t_1, t_2, l_with ) /* return with; */ RES_BRK_CURR_STAT(); SWITCH_TO_OLD_FRAME(oldFrame); return l_with; /* return; */ RES_BRK_CURR_STAT(); SWITCH_TO_OLD_FRAME(oldFrame); return 0; }
/* handler for function 6 */ static Obj HdlrFunc6 ( Obj self, Obj a_filter ) { Obj l_rank = 0; Obj l_flags = 0; Obj l_i = 0; Obj t_1 = 0; Obj t_2 = 0; Obj t_3 = 0; Obj t_4 = 0; Obj t_5 = 0; Obj t_6 = 0; Obj t_7 = 0; Bag oldFrame; OLD_BRK_CURR_STAT /* allocate new stack frame */ SWITCH_TO_NEW_FRAME(self,0,0,oldFrame); REM_BRK_CURR_STAT(); SET_BRK_CURR_STAT(0); /* rank := 0; */ l_rank = INTOBJ_INT(0); /* if IS_FUNCTION( filter ) then */ t_3 = GF_IS__FUNCTION; t_2 = CALL_1ARGS( t_3, a_filter ); CHECK_FUNC_RESULT( t_2 ) CHECK_BOOL( t_2 ) t_1 = (Obj)(UInt)(t_2 != False); if ( t_1 ) { /* flags := FLAGS_FILTER( filter ); */ t_2 = GF_FLAGS__FILTER; t_1 = CALL_1ARGS( t_2, a_filter ); CHECK_FUNC_RESULT( t_1 ) l_flags = t_1; } /* else */ else { /* flags := filter; */ l_flags = a_filter; } /* fi */ /* for i in TRUES_FLAGS( WITH_HIDDEN_IMPS_FLAGS( flags ) ) do */ t_5 = GF_TRUES__FLAGS; t_7 = GF_WITH__HIDDEN__IMPS__FLAGS; t_6 = CALL_1ARGS( t_7, l_flags ); CHECK_FUNC_RESULT( t_6 ) t_4 = CALL_1ARGS( t_5, t_6 ); CHECK_FUNC_RESULT( t_4 ) if ( IS_SMALL_LIST(t_4) ) { t_3 = (Obj)(UInt)1; t_1 = INTOBJ_INT(1); } else { t_3 = (Obj)(UInt)0; t_1 = CALL_1ARGS( GF_ITERATOR, t_4 ); } while ( 1 ) { if ( t_3 ) { if ( LEN_LIST(t_4) < INT_INTOBJ(t_1) ) break; t_2 = ELMV0_LIST( t_4, INT_INTOBJ(t_1) ); t_1 = (Obj)(((UInt)t_1)+4); if ( t_2 == 0 ) continue; } else { if ( CALL_1ARGS( GF_IS_DONE_ITER, t_1 ) != False ) break; t_2 = CALL_1ARGS( GF_NEXT_ITER, t_1 ); } l_i = t_2; /* if IsBound( RANK_FILTERS[i] ) then */ t_7 = GC_RANK__FILTERS; CHECK_BOUND( t_7, "RANK_FILTERS" ) CHECK_INT_POS( l_i ) t_6 = C_ISB_LIST( t_7, l_i ); t_5 = (Obj)(UInt)(t_6 != False); if ( t_5 ) { /* rank := rank + RANK_FILTERS[i]; */ t_7 = GC_RANK__FILTERS; CHECK_BOUND( t_7, "RANK_FILTERS" ) C_ELM_LIST_FPL( t_6, t_7, l_i ) C_SUM_FIA( t_5, l_rank, t_6 ) l_rank = t_5; } /* else */ else { /* rank := rank + 1; */ C_SUM_FIA( t_5, l_rank, INTOBJ_INT(1) ) l_rank = t_5; } /* fi */ } /* od */ /* return rank; */ RES_BRK_CURR_STAT(); SWITCH_TO_OLD_FRAME(oldFrame); return l_rank; /* return; */ RES_BRK_CURR_STAT(); SWITCH_TO_OLD_FRAME(oldFrame); return 0; }
bool isa(Obj recval) const { return IS_SMALL_LIST(recval) && LEN_LIST(recval) == 2; }
Obj boyers_planarity_check(Obj digraph, int flags, bool krtwsk) { DIGRAPHS_ASSERT(flags == EMBEDFLAGS_PLANAR || flags == EMBEDFLAGS_OUTERPLANAR || flags == EMBEDFLAGS_SEARCHFORK23 || flags == EMBEDFLAGS_SEARCHFORK4 || flags == EMBEDFLAGS_SEARCHFORK33); if (CALL_1ARGS(IsDigraph, digraph) != True) { ErrorQuit("Digraphs: boyers_planarity_check (C): the 1st argument must be " "a digraph, not %s", (Int) TNAM_OBJ(digraph), 0L); } Obj const out = FuncOutNeighbours(0L, digraph); if (FuncIS_ANTISYMMETRIC_DIGRAPH(0L, out) != True) { ErrorQuit("Digraphs: boyers_planarity_check (C): the 1st argument must be " "an antisymmetric digraph", 0L, 0L); } Int V = DigraphNrVertices(digraph); Int E = DigraphNrEdges(digraph); if (V > INT_MAX) { // Cannot currently test this, it might always be true, depending on the // definition of Int. ErrorQuit("Digraphs: boyers_planarity_check (C): the maximum number of " "nodes is %d, found %d", INT_MAX, V); return 0L; } else if (2 * E > INT_MAX) { // Cannot currently test this ErrorQuit("Digraphs: boyers_planarity_check (C): the maximum number of " "edges is %d, found %d", INT_MAX / 2, E); return 0L; } graphP theGraph = gp_New(); switch (flags) { case EMBEDFLAGS_SEARCHFORK33: gp_AttachK33Search(theGraph); break; case EMBEDFLAGS_SEARCHFORK23: gp_AttachK23Search(theGraph); break; case EMBEDFLAGS_SEARCHFORK4: gp_AttachK4Search(theGraph); break; } if (gp_InitGraph(theGraph, V) != OK) { gp_Free(&theGraph); ErrorQuit("Digraphs: boyers_planarity_check (C): invalid number of nodes!", 0L, 0L); return 0L; } else if (gp_EnsureArcCapacity(theGraph, 2 * E) != OK) { gp_Free(&theGraph); ErrorQuit("Digraphs: boyers_planarity_check (C): invalid number of edges!", 0L, 0L); return 0L; } int status; for (Int v = 1; v <= LEN_LIST(out); ++v) { DIGRAPHS_ASSERT(gp_VertexInRange(theGraph, v)); gp_SetVertexIndex(theGraph, v, v); Obj const out_v = ELM_LIST(out, v); for (Int w = 1; w <= LEN_LIST(out_v); ++w) { DIGRAPHS_ASSERT(gp_VertexInRange(theGraph, w)); int u = INT_INTOBJ(ELM_LIST(out_v, w)); if (v != u) { status = gp_AddEdge(theGraph, v, 0, u, 0); if (status != OK) { // Cannot currently test this, i.e. it shouldn't happen (and // currently there is no example where it does happen) gp_Free(&theGraph); ErrorQuit("Digraphs: boyers_planarity_check (C): internal error, " "can't add edge from %d to %d", (Int) v, (Int) u); return 0L; } } } } status = gp_Embed(theGraph, flags); if (status == NOTOK) { // Cannot currently test this, i.e. it shouldn't happen (and // currently there is no example where it does happen) gp_Free(&theGraph); ErrorQuit("Digraphs: boyers_planarity_check (C): status is not ok", 0L, 0L); } Obj res; if (krtwsk) { // Kuratowski subgraph isolator gp_SortVertices(theGraph); Obj subgraph = NEW_PLIST_IMM(T_PLIST, theGraph->N); SET_LEN_PLIST(subgraph, theGraph->N); for (int i = 1; i <= theGraph->N; ++i) { int nr = 0; Obj list = NEW_PLIST_IMM(T_PLIST, 0); int j = theGraph->V[i].link[1]; while (j) { if (CALL_3ARGS(IsDigraphEdge, digraph, INTOBJ_INT((Int) i), INTOBJ_INT((Int) theGraph->E[j].neighbor)) == True) { AssPlist(list, ++nr, INTOBJ_INT(theGraph->E[j].neighbor)); } j = theGraph->E[j].link[1]; } if (nr == 0) { RetypeBag(list, T_PLIST_EMPTY); } SET_ELM_PLIST(subgraph, i, list); CHANGED_BAG(subgraph); } res = NEW_PLIST_IMM(T_PLIST, 2); SET_LEN_PLIST(res, 2); SET_ELM_PLIST(res, 1, (status == NONEMBEDDABLE ? False : True)); SET_ELM_PLIST(res, 2, subgraph); CHANGED_BAG(res); } else if (status == NONEMBEDDABLE) { res = False; } else { res = True; } gp_Free(&theGraph); return res; }
UInt GAP_LenList(Obj obj) { return LEN_LIST(obj); }
int transversalSize() const { return LEN_LIST(ELM_REC(sc, RName_transversal)); }
/**************************************************************************** ** *F FuncADD_SET( <self>, <set>, <obj> ) . . . . . . . add an element to a set ** ** 'FuncADD_SET' implements the internal function 'AddSet'. ** ** 'AddSet( <set>, <obj> )' ** ** 'AddSet' adds <obj>, which may be an object of an arbitrary type, to the ** set <set>, which must be a proper set. If <obj> is already an element of ** the set <set>, then <set> is not changed. Otherwise <obj> is inserted at ** the correct position such that <set> is again a set afterwards. ** ** 'AddSet' does not return anything, it is only called for the side effect ** of changing <set>. */ Obj FuncADD_SET ( Obj self, Obj set, Obj obj ) { UInt len; /* logical length of the list */ UInt pos; /* position */ UInt isCyc; /* True if the set being added to consists of kernel cyclotomics */ UInt notpos; /* position of an original element (not the new one) */ UInt wasHom; UInt wasNHom; UInt wasTab; /* check the arguments */ while ( ! IsSet(set) || ! IS_MUTABLE_OBJ(set) ) { set = ErrorReturnObj( "AddSet: <set> must be a mutable proper set (not a %s)", (Int)TNAM_OBJ(set), 0L, "you can replace <set> via 'return <set>;'" ); } len = LEN_LIST(set); /* perform the binary search to find the position */ pos = PositionSortedDensePlist( set, obj ); /* add the element to the set if it is not already there */ if ( len < pos || ! EQ( ELM_PLIST(set,pos), obj ) ) { GROW_PLIST( set, len+1 ); SET_LEN_PLIST( set, len+1 ); { Obj *ptr; ptr = PTR_BAG(set); memmove((void *)(ptr + pos+1),(void*)(ptr+pos),(size_t)(sizeof(Obj)*(len+1-pos))); #if 0 for ( i = len+1; pos < i; i-- ) { *ptr = *(ptr-1); ptr--; */ /* SET_ELM_PLIST( set, i, ELM_PLIST(set,i-1) ); */ } #endif } SET_ELM_PLIST( set, pos, obj ); CHANGED_BAG( set ); /* fix up the type of the result */ if ( HAS_FILT_LIST( set, FN_IS_SSORT ) ) { isCyc = (TNUM_OBJ(set) == T_PLIST_CYC_SSORT); wasHom = HAS_FILT_LIST(set, FN_IS_HOMOG); wasTab = HAS_FILT_LIST(set, FN_IS_TABLE); wasNHom = HAS_FILT_LIST(set, FN_IS_NHOMOG); CLEAR_FILTS_LIST(set); /* the result of addset is always dense */ SET_FILT_LIST( set, FN_IS_DENSE ); /* if the object we added was not mutable then we might be able to conclude more */ if ( ! IS_MUTABLE_OBJ(obj) ) { /* a one element list is automatically homogenous and ssorted */ if (len == 0 ) { if (TNUM_OBJ(obj) <= T_CYC) RetypeBagIfWritable( set, T_PLIST_CYC_SSORT); else { SET_FILT_LIST( set, FN_IS_HOMOG ); SET_FILT_LIST( set, FN_IS_SSORT ); if (IS_HOMOG_LIST(obj)) /* it might be a table */ SET_FILT_LIST( set, FN_IS_TABLE ); } } else { /* Now determine homogeneity */ if (isCyc) if (TNUM_OBJ(obj) <= T_CYC) RetypeBagIfWritable( set, T_PLIST_CYC_SSORT); else { RESET_FILT_LIST(set, FN_IS_HOMOG); SET_FILT_LIST(set, FN_IS_NHOMOG); } else if (wasHom) { if (!SyInitializing) { notpos = (pos == 1) ? 2 : 1; if (FAMILY_OBJ(ELM_PLIST(set,notpos)) == FAMILY_OBJ(obj)) { SET_FILT_LIST(set, FN_IS_HOMOG); if (wasTab) { if (IS_HOMOG_LIST( obj )) SET_FILT_LIST(set, FN_IS_TABLE); } } else SET_FILT_LIST(set, FN_IS_NHOMOG); } } else if (wasNHom) SET_FILT_LIST(set, FN_IS_NHOMOG); } } SET_FILT_LIST( set, FN_IS_SSORT ); } else { CLEAR_FILTS_LIST(set); SET_FILT_LIST( set, FN_IS_DENSE ); } }