CAMLprim value mlsdlevent_add(value elist) { int len = mlsdl_list_length(elist); LOCALARRAY(SDL_Event, evt, len); value l = elist; int i=0; while(is_not_nil(l)){ evt[i] = SDLEvent_of_value(hd(l)); l = tl(l); i++; } if(SDL_PeepEvents(evt, len, SDL_ADDEVENT, SDL_ALLEVENTS) < 0) raise_event_exn(SDL_GetError()); return Val_unit; }
CAMLprim value mlsdlevent_get(value omask, value num) { int n = Int_val(num); int m; LOCALARRAY(SDL_Event, evt, n); Uint32 mask = Opt_arg(omask, Int_val, SDL_ALLEVENTS); m = SDL_PeepEvents(evt, n, SDL_GETEVENT, mask); if(m < 0) raise_event_exn(SDL_GetError()); { int i; CAMLparam0(); CAMLlocal1(v); v = nil(); for(i=m-1; i>=0; i--){ value e = value_of_SDLEvent(evt[i]); v = mlsdl_cons(e, v); } CAMLreturn(v); } }
void SeqEdgeColoringPar<DefaultStructs>::vizing( VizingState<Graph, ColorMap> &vState, typename Graph::PEdge edge, typename Graph::PVertex vertX) { typedef typename Graph::PVertex Vert; typedef typename Graph::PEdge Edge; const EdgeDirection Mask = EdDirIn|EdDirOut|EdUndir; int degree = vState.graph.Delta(Mask); int freeColorX; //color not incident to X; always freeColorX <= maxColor Edge LOCALARRAY(usedColorX, vState.notColored); //edges incident to X (by colors) int LOCALARRAY(usedColorY, vState.notColored); //if colors are incident to Y_k (yes/no) int LOCALARRAY(freeColorYY, vState.notColored); /*freeColorYY[i]==j means that color i is not incident with the vertex described in fan[j] (fan[j]- edge (v,u) one vertex is vertX and second is the described one)*/ Edge LOCALARRAY(fan, degree); //as in Vizing's proof (edges that are used in fan) int fanLen, ii; Vert vertY = edge->getEnd(vertX); int idVertX = vState.vertToTab[vertX]; for(ii=0; ii<=vState.maxColor; ii++) usedColorX[ii] = NULL; for(Edge eX = vState.graph.getEdge(vertX, Mask); eX; eX = vState.graph.getEdgeNext(vertX, eX, Mask)) { if(!vState.colors.hasKey(eX)) continue; int tmpCol = vState.colors[eX]; if(tmpCol<0 || tmpCol>=vState.notColored) continue; usedColorX[ tmpCol ] = eX; } for(ii=0; ii<=vState.maxColor; ii++) if(usedColorX[ii]==NULL) break; freeColorX = ii; for(int i=0; i<=vState.maxColor; i++) freeColorYY[i] = -1; //clear all free color of all Y_k (for all k) fanLen = 0; //long while while(1) { //creating fan vertY = vState.graph.getEdgeEnd(edge, vertX); //take Y_k for(int i=0; i<=vState.maxColor; i++) //reset used colors usedColorY[i] = 0; for(Edge eY = vState.graph.getEdge(vertY, Mask); eY; eY = vState.graph.getEdgeNext(vertY, eY, Mask)) { if(!vState.colors.hasKey(eY)) continue; int tmpCol = vState.colors[eY]; if(tmpCol<0 || tmpCol>=vState.notColored) continue; usedColorY[ tmpCol ] = 1; } fan[fanLen++] = edge; //create new entry in fan of X //check if fan recoloring is enough for(ii=0; ii<=vState.maxColor; ii++) { if(usedColorY[ii]!=0 || usedColorX[ii]!=NULL) continue; //if there is unused color in X and Y_k: if(fanLen>1) { int j = fanLen-1; do { int prevColor = vState.colors[ fan[j] ]; vState.changeColor(fan[j], prevColor, ii); vState.colors[ fan[j] ] = ii; ii = prevColor; } while( (j=freeColorYY[ii])>0 ); //recoloring in fan (2) } vState.changeColor(fan[0], vState.notColored, ii); vState.colors[ fan[0] ] = ii; return; } for(ii=0; ii<=vState.maxColor; ii++) { if( usedColorY[ii]>0 ) continue; //we don't watch colors from neighbourhood of Y if( freeColorYY[ii]>=0 ) { //there are 2 vertices in fan that miss color 'ii' //a)recoloring by path; [next b)recoloring by fan] //subgraph creation vState.subgraph(freeColorX, ii); //travel from vertex vertX... int iV = vState.altPathWalk(idVertX, ii); int endVert = vState.vertToTab[ vState.graph.getEdgeEnd( fan[ freeColorYY[ii] ] , vertX) ]; if(iV==endVert) { endVert = vState.vertToTab[ vertY ]; fanLen--; } else { fanLen = freeColorYY[ii]; } //path recoloring (starts in endVert) vState.altPathRecoloring(endVert, freeColorX); // fan recoloring ii = freeColorX; for(int i=fanLen; i>0;) { //recoloring in fan (2) int prevColor = vState.colors[ fan[i] ]; vState.changeColor(fan[i], prevColor, ii); vState.colors[ fan[i] ] = ii; ii = prevColor; i = freeColorYY[ii]; } vState.changeColor(fan[0], vState.notColored, ii); vState.colors[ fan[0] ] = ii; return; //double break } else //add information about free colors in Y_k freeColorYY[ii] = fanLen-1; } //we search edge incident to X that has color missed to edges of the fan for(Edge ee = vState.graph.getEdge(vertX, Mask); ee; ee = vState.graph.getEdgeNext(vertX, ee, Mask)) { Vert v = vState.graph.getEdgeEnd(ee, vertX); vState.tabVert[ vState.vertToTab[v] ].vc[0] = 0; } for(ii=0; ii<fanLen; ii++) { Vert v = vState.graph.getEdgeEnd(fan[ii], vertX); vState.tabVert[ vState.vertToTab[v] ].vc[0] = 1; } for(ii=0; ii<=vState.maxColor; ii++) { if( freeColorYY[ii]<0 || usedColorX[ii]==NULL ) continue; Vert v = vState.graph.getEdgeEnd( usedColorX[ii], vertX ); if( vState.tabVert[ vState.vertToTab[v] ].vc[0]==1 ) continue; edge = usedColorX[ii]; break; } if(ii>vState.maxColor) { //we use new color ( ++maxColor ) ++vState.maxColor; vState.changeColor(fan[0], vState.notColored, vState.maxColor); vState.colors[ fan[0] ] = vState.maxColor; return; } } }