int sod_halt( sod_session *session ) { pstart(); if ( session->ecode!=SE_NONE ) { #ifdef USE_GETTEXT printf(gettext(vstr("WARNING: unmanaged error:\n\tfunction: %s\n\terror: %s\n\tcode: %d\n", \ session->errorfunc,session->errortext,session->ecode))); #else printf(vstr("WARNING: unmanaged error:\n\tfunction: %s\n\terror: %s\n\tcode: %d\n", \ session->errorfunc,session->errortext,session->ecode)); #endif } if ( session->status==SOD_CONNECTED ) { sod_disconnect(session); } dfree(session); pstop(); return SOD_OK; }
// scc [parameters] [host] [login] [password] int main( int argc, char *argv[] ) { int i; int *a; pstart(); a=dmalloc(sizeof(int)); /* поддержка языков */ setlocale(LC_ALL,""); bindtextdomain("sodaliscc","gettext"); textdomain("sodaliscc"); session=sod_init(); sod_assign_event(session,SOD_EV_DISCON,event_disconnect); sod_assign_event(session,SOD_EV_ERROR,event_error); sod_connect(session,"localhost",1986,"kane","passw"); while ( session->status!=SOD_AUTHORIZED ); sod_logout(session); scanf("%d",&i); sod_halt(session); pstop(); return EXIT_SUCCESS; }
kucode_t NAME(abtree_empty)( ABTREE *tree ) { NODE *a=tree->ptr, *b; pstart(); while ( a!=NULL ) { b=a->left; if ( b==NULL ) { b=a->right; if ( b==NULL ) { b=a->parent; if ( b!=NULL ) { if ( b->left==a ) b->left=NULL; else b->right=NULL; } dfree(a); } } a=b; } tree->ptr=NULL; pstop(); return KE_NONE; }
void event_disconnect( sod_session *session, sod_event_t event, ... ) { pstart(); printf("you are disconnected!\n"); exit(0); pstop(); }
void event_error( sod_session *session, sod_event_t event, ... ) { pstart(); printf("ERROR!!!\n"); printf("%s: %s (%d)\n",session->errorfunc,session->errortext,session->ecode); session->ecode=SE_NONE; pstop(); }
void flush2(void) { fgoto(); flusho(); pstop(); }
helpinit() { erfile = open(erpath, 0); if (erfile < 0) flush(); else pstop(); }
kucode_t NAME(abtree_free)( ABTREE *tree ) { pstart(); NAME(abtree_empty)(tree); dfree(tree); pstop(); return KE_NONE; }
int JALOUSIE::toggleAbwaerts(int JalNr) { SingleLock slock(this, true); if(drvstate[JalNr] == STOP) { return pdrvAbwaerts(JalNr, FAHRZEIT + offset()); } else { return pstop(JalNr); } }
int JALOUSIE::pdrvAbwaerts(int JalNr, int imptime) { if(drvstate[JalNr] == AB) { return 0; } if(drvstate[JalNr] == AUF) { pstop(JalNr); } if(position[JalNr] == AB) { return 0; } return drv(JalNr, AB, imptime, false); }
int JALOUSIE::drvSonne(int JalNr) { SingleLock slock(this, true); if(drvstate[JalNr] != STOP) { pstop(JalNr); } if(position[JalNr] == AB) { return drv(JalNr, AUF, SONNENZEIT, false); // schon geschlossen, also nur noch auf Luecke stellen } else { return drv(JalNr, AB, FAHRZEIT + offset(), true); // erstmal Schliessen } }
ABTREE *NAME(abtree_create)( void ) { ABTREE *tree; pstart(); tree=(ABTREE*)dmalloc(sizeof(ABTREE)); if ( tree==NULL ) { kucode=KE_MEMORY; return NULL; } tree->ptr=NULL; pstop(); return tree; }
/* * An interrupt occurred. Drain any output which * is still in the output buffering pipeline. * Catch interrupts again. Unless we are in visual * reset the output state (out of -nl mode, e.g). * Then like a normal error (with the \n before Interrupt * suppressed in visual mode). */ void onintr(int i) { char *s = "\nInterrupt"; (void)i; #ifdef V6 signal(SIGINT, onintr); #else signal(SIGINT, inopen ? vintr : onintr); #endif draino(); if (!inopen) { pstop(); setlastchar('\n'); #ifndef V6 } #else } else
sod_session *sod_init( void ) { sod_session *session; pstart(); session=dmalloc(sizeof(sod_session)); if ( session==NULL ) return NULL; session->status=SOD_NOT_CONNECTED; session->ecode=SE_NONE; session->errortext=""; session->errorfunc=""; session->socket=-1; session->inpos=0; session->instart=0; session->outpos=0; session->outstart=0; pstop(); return session; }
TYPE NAME(abtree_search)( ABTREE *tree, TYPE data ) { NODE *cur=tree->ptr; pstart(); while ( cur!=NULL ) { if ( ABTREE_MORE(data,cur->data) ) { cur=cur->right; } else if ( !ABTREE_EQ(data,cur->data) ) { cur=cur->left; } else { return cur->data; } } kucode=KE_NOTFOUND; pstop(); return ABTREE_ERRVAL; }
Handle(Geom_BSplineCurve) CFunctionToBspline::CFunctionToBsplineImpl::Curve() { bool interpolate = true; std::vector<ChebSegment> segments = approxSegment(_umin, _umax, 1); int N = _degree + 1; math_Matrix Mt = monimial_to_bezier(N)*cheb_to_monomial(N); // get estimated error and create bspline segments std::vector<Handle(Geom_BSplineCurve)> curves; double errTotal = 0.; std::vector<ChebSegment>::iterator it = segments.begin(); for (; it != segments.end(); ++it) { // get control points ChebSegment& seg = *it; math_Vector cpx = Mt*seg.cx; math_Vector cpy = Mt*seg.cy; math_Vector cpz = Mt*seg.cz; TColgp_Array1OfPnt cp(1,cpx.Length()); for (int i = 1; i <= cpx.Length(); ++i) { gp_Pnt p(cpx(i-1), cpy(i-1), cpz(i-1)); cp.SetValue(i, p); } if (interpolate) { gp_Pnt pstart(_xfunc.value(seg.umin), _yfunc.value(seg.umin), _zfunc.value(seg.umin)); gp_Pnt pstop (_xfunc.value(seg.umax), _yfunc.value(seg.umax), _zfunc.value(seg.umax)); cp.SetValue(1, pstart); cp.SetValue(cpx.Length(), pstop); } // create knots and multiplicity vector TColStd_Array1OfReal knots(1,2); knots.SetValue(1, seg.umin); knots.SetValue(2, seg.umax); TColStd_Array1OfInteger mults(1,2); mults.SetValue(1, _degree+1); mults.SetValue(2, _degree+1); Handle(Geom_BSplineCurve) curve = new Geom_BSplineCurve(cp, knots, mults, _degree); curves.push_back(curve); if (seg.error > errTotal) { errTotal = seg.error; } } _err = errTotal; // concatenate c1 the bspline curves Handle(Geom_BSplineCurve) result = concatC1(curves); #ifdef DEBUG LOG(INFO) << "Result of BSpline approximation of function:"; LOG(INFO) << " approximation error = " << errTotal; LOG(INFO) << " number of control points = " << result->NbPoles(); LOG(INFO) << " number of segments = " << curves.size(); #endif return result; }
int main(int argc,char *argv[]) { static double scoef[ROWS][COLS]; double m1,m2,E,rho,x,min,max,step,S,sunit,xunit; int z1,z2; unsigned int flag; int i; readscoef(scoef); readparms(argc,argv,&z1,&z2,&m1,&m2,&rho,&min,&max,&step,&flag,scoef); sunit = NA*rho/(m2*1.0e25); xunit = 1.0; switch(flag & ZBL_SUNIT){ case ZBL_EV_A: sunit = 100.0*NA*rho/(m2*1.0e25); break; case ZBL_KEV_NM: sunit = NA*rho/(m2*1.0e25); break; case ZBL_KEV_UM: sunit = 1000.0*NA*rho/(m2*1.0e25); break; case ZBL_MEV_MM: sunit = 1000.0*NA*rho/(m2*1.0e25); break; case ZBL_KEV_UG_CM2: sunit = NA/(m2*1e24); break; case ZBL_MEV_MG_CM2: sunit = NA/(m2*1e24); break; case ZBL_KEV_MG_CM2: sunit = 1000.0*NA/(m2*1e24); break; case ZBL_EV_1E15ATOMS_CM2: sunit = 1.0; break; case ZBL_EFFCHARGE: sunit = 1.0; break; } switch(flag & ZBL_XUNIT){ case ZBL_EV: xunit = 1000.0; break; case ZBL_KEV: xunit = 1.0; break; case ZBL_MEV: xunit = 0.001; break; case ZBL_V0: xunit = 1.0; break; case ZBL_BETA: xunit = 0.0072974; break; case ZBL_M_S: xunit = 2187673.0; break; case ZBL_CM_S: xunit = 218767300.0; break; } if(flag & ZBL_DSA){ for(x=min,i=0;x<=max;x+=step,i++); printf(" %i %10.2f\n",i,rho); } for(x=min;x<=max;x+=step){ switch(flag & ZBL_ENERGY){ case FALSE: E = 25.0*x*x/(xunit*xunit); break; default: E = x/(xunit*m1); break; } if(sqrt(E)/(5.0*137.035) > 1.0) fatal_error(8); switch(z1){ case 1: if((flag & ZBL_SUNIT) == ZBL_EFFCHARGE) S = 1.0; else S = pstop(z2,E,scoef); break; case 2: if((flag & ZBL_SUNIT) == ZBL_EFFCHARGE) S = heeff(z2,E); else S = hestop(z2,E,scoef); break; default: if((flag & ZBL_SUNIT) == ZBL_EFFCHARGE) S = hieff(z1,z2,E,scoef); else S = histop(z1,z2,E,scoef); break; } switch(flag & ZBL_NUCLEAR){ case ZBL_N_ONLY: S = nuclear(z1,z2,m1,m2,E*m1); break; case ZBL_N_BOTH: S += nuclear(z1,z2,m1,m2,E*m1); break; case ZBL_N_NO: break; } printf("%12.4e %12.4e\n",x,S*sunit); } exit(0); }
int JALOUSIE::stop(int JalNr) { SingleLock slock(this, true); return pstop(JalNr); }
/* * Main procedure. Process arguments and then * transfer control to the main command processing loop * in the routine commands. We are entered as either "ex", "edit", "vi" * or "view" and the distinction is made here. Actually, we are "vi" if * there is a 'v' in our name, "view" is there is a 'w', and "edit" if * there is a 'd' in our name. For edit we just diddle options; * for vi we actually force an early visual command. */ int main(int ac, char **av) { #ifndef VMUNIX char *erpath = EXSTRINGS; #endif register char *cp; register int c; bool recov = 0; bool ivis; bool itag = 0; bool fast = 0; #ifdef TRACE register char *tracef; #endif /* * Immediately grab the tty modes so that we wont * get messed up if an interrupt comes in quickly. */ gTTY(1); #ifndef USG3TTY normf = tty.sg_flags; #else normf = tty; #endif ppid = getpid(); /* * Defend against d's, v's, w's, and a's in directories of * path leading to our true name. */ av[0] = tailpath(av[0]); /* * Figure out how we were invoked: ex, edit, vi, view. */ ivis = any('v', av[0]); /* "vi" */ if (any('w', av[0])) /* "view" */ value(READONLY) = 1; if (any('d', av[0])) { /* "edit" */ value(OPEN) = 0; value(REPORT) = 1; value(MAGIC) = 0; } #ifndef VMUNIX /* * For debugging take files out of . if name is a.out. */ if (av[0][0] == 'a') erpath = tailpath(erpath); #endif /* * Open the error message file. */ draino(); #ifndef VMUNIX erfile = open(erpath+4, O_RDONLY); if (erfile < 0) { erfile = open(erpath, O_RDONLY); } #endif pstop(); /* * Initialize interrupt handling. */ oldhup = signal(SIGHUP, SIG_IGN); if (oldhup == SIG_DFL) signal(SIGHUP, onhup); oldquit = signal(SIGQUIT, SIG_IGN); ruptible = signal(SIGINT, SIG_IGN) == SIG_DFL; if (signal(SIGTERM, SIG_IGN) == SIG_DFL) signal(SIGTERM, onhup); #ifdef SIGEMT if (signal(SIGEMT, SIG_IGN) == SIG_DFL) signal(SIGEMT, onemt); #endif /* * Initialize end of core pointers. * Normally we avoid breaking back to fendcore after each * file since this can be expensive (much core-core copying). * If your system can scatter load processes you could do * this as ed does, saving a little core, but it will probably * not often make much difference. */ #ifdef UNIX_SBRK fendcore = (line *) sbrk(0); endcore = fendcore - 2; #else # define LINELIMIT 0x8000 fendcore = malloc(LINELIMIT * sizeof(line *)); endcore = fendcore + LINELIMIT - 1; #endif /* * Process flag arguments. */ ac--, av++; while (ac && av[0][0] == '-') { c = av[0][1]; if (c == 0) { hush = 1; value(AUTOPRINT) = 0; fast++; } else switch (c) { case 'R': value(READONLY) = 1; break; #ifdef TRACE case 'T': if (av[0][2] == 0) tracef = "trace"; else { tracef = tttrace; tracef[8] = av[0][2]; if (tracef[8]) tracef[9] = av[0][3]; else tracef[9] = 0; } trace = fopen(tracef, "w"); if (trace == NULL) ex_printf("Trace create error\n"); setbuf(trace, tracbuf); break; #endif #ifdef LISPCODE case 'l': value(LISP) = 1; value(SHOWMATCH) = 1; break; #endif case 'r': recov++; break; case 't': if (ac > 1 && av[1][0] != '-') { ac--, av++; itag = 1; /* BUG: should check for too long tag. */ CP(lasttag, av[0]); } break; case 'v': ivis = 1; break; case 'w': defwind = 0; if (av[0][2] == 0) defwind = 3; else for (cp = &av[0][2]; isdigit((int)*cp); cp++) defwind = 10*defwind + *cp - '0'; break; #ifdef CRYPT case 'x': /* -x: encrypted mode */ xflag = 1; break; #endif default: smerror("Unknown option %s\n", av[0]); break; } ac--, av++; } #ifdef SIGTSTP if (!hush && signal(SIGTSTP, SIG_IGN) == SIG_DFL) signal(SIGTSTP, onsusp), dosusp++; #endif if (ac && av[0][0] == '+') { firstpat = &av[0][1]; ac--, av++; } #ifdef CRYPT if(xflag){ key = getpass(KEYPROMPT); kflag = crinit(key, perm); } #endif /* * If we are doing a recover and no filename * was given, then execute an exrecover command with * the -r option to type out the list of saved file names. * Otherwise set the remembered file name to the first argument * file name so the "recover" initial command will find it. */ if (recov) { if (ac == 0) { ppid = 0; setrupt(); execl(EXRECOVER, "exrecover", "-r", NULL); filioerr(EXRECOVER); ex_exit(1); } CP(savedfile, *av); av++, ac--; } /* * Initialize the argument list. */ argv0 = av; argc0 = ac; args0 = av[0]; erewind(); /* * Initialize a temporary file (buffer) and * set up terminal environment. Read user startup commands. */ if (setexit() == 0) { setrupt(); intty = isatty(0); value(PROMPT) = intty; if ((cp = getenv("SHELL"))) CP(shell, cp); if (fast || !intty) setterm("dumb"); else { gettmode(); if ((cp = getenv("TERM")) != 0 && *cp) setterm(cp); } } if (setexit() == 0 && !fast && intty) { if ((globp = getenv("EXINIT")) && *globp) commands(1,1); else { globp = 0; if ((cp = getenv("HOME")) != 0 && *cp) source(strcat(strcpy(genbuf, cp), "/.exrc"), 1); } } init(); /* moved after prev 2 chunks to fix directory option */ /* * Initial processing. Handle tag, recover, and file argument * implied next commands. If going in as 'vi', then don't do * anything, just set initev so we will do it later (from within * visual). */ if (setexit() == 0) { if (recov) globp = "recover"; else if (itag) globp = ivis ? "tag" : "tag|p"; else if (argc) globp = "next"; if (ivis) initev = globp; else if (globp) { inglobal = 1; commands(1, 1); inglobal = 0; } } /* * Vi command... go into visual. * Strange... everything in vi usually happens * before we ever "start". */ if (ivis) { /* * Don't have to be upward compatible with stupidity * of starting editing at line $. */ if (dol > zero) dot = one; globp = "visual"; if (setexit() == 0) commands(1, 1); } /* * Clear out trash in state accumulated by startup, * and then do the main command loop for a normal edit. * If you quit out of a 'vi' command by doing Q or ^\, * you also fall through to here. */ seenprompt = 1; ungetchar(0); globp = 0; initev = 0; setlastchar('\n'); setexit(); commands(0, 0); cleanup(1); return 0; }
static void ab_rotate_right( ABTREE *tree, NODE *node ) { NODE *t=node->left; pstart(); if ( t!=NULL ) { if ( (t->left!=NULL) && (t->lcnt>=t->rcnt) ) { // ACE стиль t->parent=node->parent; node->left=t->right; node->lcnt=t->rcnt; if ( t->right!=NULL ) t->right->parent=node; t->right=node; t->rcnt=max(node->lcnt,node->rcnt)+1; node->parent=t; } else { // ACD стиль NODE *d=t->right; d->parent=node->parent; t->parent=d; node->parent=d; node->left=d->right; node->lcnt=d->rcnt; if ( node->left!=NULL ) node->left->parent=node; t->right=d->left; t->rcnt=d->lcnt; if ( t->right!=NULL ) t->right->parent=t; d->right=node; d->rcnt=max(node->lcnt,node->rcnt)+1; d->left=t; d->lcnt=max(t->lcnt,t->rcnt)+1; t=d; } if ( t->parent!=NULL ) { if ( t->parent->left==node ) { t->parent->left=t; t->parent->lcnt=max(t->lcnt,t->rcnt)+1; } else { t->parent->right=t; t->parent->rcnt=max(t->lcnt,t->rcnt)+1; } } else { tree->ptr=t; } } pstop(); }
kucode_t NAME(abtree_ins)( ABTREE *tree, TYPE data ) { NODE *cur=tree->ptr; NODE *p=NULL, *newnode; pstart(); // создание элемента newnode=(NODE*)dmalloc(sizeof(NODE)); if ( newnode==NULL ) return KE_MEMORY; newnode->left=NULL; newnode->right=NULL; newnode->data=data; newnode->lcnt=0; newnode->rcnt=0; // поиск места while ( cur!=NULL ) { p=cur; if ( ABTREE_MORE(data,cur->data) ) { cur=cur->right; } else if ( !ABTREE_EQ(data,cur->data) ) { cur=cur->left; } else { dfree(newnode); return KE_DOUBLE; } } // вставка if ( p==NULL ) { // первый элемент в списке tree->ptr=newnode; newnode->parent=NULL; } else { newnode->parent=p; if ( ABTREE_MORE(data,p->data) ) { p->right=newnode; } else { p->left=newnode; } } // балансировка while ( p!=NULL ) { if ( p->left==newnode ) p->lcnt=max(newnode->lcnt,newnode->rcnt)+1; else p->rcnt=max(newnode->lcnt,newnode->rcnt)+1; if ( p->lcnt-p->rcnt==2 ) { ab_rotate_right(tree,p); p=p->parent; } else if ( p->rcnt-p->lcnt==2 ) { ab_rotate_left(tree,p); p=p->parent; } newnode=p; p=p->parent; } pstop(); return KE_NONE; }
/* * Main procedure. Process arguments and then * transfer control to the main command processing loop * in the routine commands. We are entered as either "ex", "edit" or "vi" * and the distinction is made here. Actually, we are "vi" if * there is a 'v' in our name, and "edit" if there is a 'd' in our * name. For edit we just diddle options; for vi we actually * force an early visual command, setting the external initev so * the q command in visual doesn't give command mode. */ int main(int ac, char **av) { #if 0 char *erpath = EXSTRINGS; #endif register char *cp; register int c; bool recov = 0; bool ivis = any('v', av[0]); bool itag = 0; bool fast = 0; #ifdef TRACE register char *tracef; #endif /* * Immediately grab the tty modes so that we wont * get messed up if an interrupt comes in quickly. */ gTTY(1); normf = tty; #if 0 /* * For debugging take files out of . if name is a.out. * If a 'd' in our name, then set options for edit. */ if (av[0][0] == 'a') erpath += 9; #endif if (ivis) { options[MAGIC].odefault = value(MAGIC) = 0; options[BEAUTIFY].odefault = value(BEAUTIFY) = 1; } else if (any('d', av[0])) { value(OPEN) = 0; value(REPORT) = 1; value(MAGIC) = 0; } /* * Open the error message file. */ draino(); #if 0 erfile = open(erpath, 0); if (erfile < 0) { flush(); exit(1); } #endif pstop(); /* * Initialize interrupt handling. */ oldhup = signal(SIGHUP, SIG_IGN); if (oldhup == SIG_DFL) signal(SIGHUP, onhup); oldquit = signal(SIGQUIT, SIG_IGN); ruptible = signal(SIGINT, SIG_IGN) == SIG_DFL; if (signal(SIGTERM, SIG_IGN) == SIG_DFL) signal(SIGTERM, onhup); /* * Initialize end of core pointers. * Normally we avoid breaking back to fendcore after each * file since this can be expensive (much core-core copying). * If your system can scatter load processes you could do * this as ed does, saving a little core, but it will probably * not often make much difference. */ #ifdef UNIX_SBRK fendcore = (line *) sbrk(0); endcore = fendcore - 2; #else # define LINELIMIT 0x8000 fendcore = malloc(LINELIMIT * sizeof(line *)); endcore = fendcore + LINELIMIT - 1; #endif /* * Process flag arguments. */ ac--, av++; while (ac && av[0][0] == '-') { c = av[0][1]; if (c == 0) { hush = 1; value(AUTOPRINT) = 0; fast++; } else switch (c) { #ifdef TRACE case 'T': if (av[0][2] == 0) tracef = "trace"; else { tracef = tttrace; tracef[8] = av[0][2]; if (tracef[8]) tracef[9] = av[0][3]; else tracef[9] = 0; } trace = fopen(tracef, "w"); if (trace == NULL) ex_printf("Trace create error\n"); setbuf(trace, tracbuf); break; #endif #ifdef LISP case 'l': value(LISP) = 1; value(SHOWMATCH) = 1; break; #endif case 'r': recov++; break; case 't': if (ac > 1 && av[1][0] != '-') { ac--, av++; itag = 1; /* BUG: should check for too long tag. */ CP(lasttag, av[0]); } break; case 'v': globp = ""; ivis = 1; break; default: smerror("Unknown option %s\n", av[0]); break; } ac--, av++; } if (ac && av[0][0] == '+') { firstln = getn(av[0] + 1); if (firstln == 0) firstln = 20000; ac--, av++; } /* * If we are doing a recover and no filename * was given, then execute an exrecover command with * the -r option to type out the list of saved file names. * Otherwise set the remembered file name to the first argument * file name so the "recover" initial command will find it. */ if (recov) { if (ac == 0) { die++; setrupt(); execl(EXRECOVER, "exrecover", "-r", NULL); filioerr(EXRECOVER); exit(1); } CP(savedfile, *av); av++, ac--; } /* * Initialize the argument list. */ argv0 = av; argc0 = ac; args0 = av[0]; erewind(); /* * Initialize a temporary file (buffer) and * set up terminal environment. Read user startup commands. */ init(); if (setexit() == 0) { setrupt(); intty = isatty(0); if (fast || !intty) setterm("dumb"); else { gettmode(); if ((cp = getenv("TERM")) != 0) setterm(cp); if ((cp = getenv("HOME")) != 0) source(strcat(strcpy(genbuf, cp), "/.exrc"), 1); } } /* * Initial processing. Handle tag, recover, and file argument * implied next commands. If going in as 'vi', then don't do * anything, just set initev so we will do it later (from within * visual). */ if (setexit() == 0) { if (recov) globp = "recover"; else if (itag) globp = ivis ? "tag" : "tag|p"; else if (argc) globp = "next"; if (ivis) initev = globp; else if (globp) { inglobal = 1; commands(1, 1); inglobal = 0; } } /* * Vi command... go into visual. * Strange... everything in vi usually happens * before we ever "start". */ if (ivis) { /* * Don't have to be upward compatible with stupidity * of starting editing at line $. */ if (dol > zero) dot = one; globp = "visual"; if (setexit() == 0) commands(1, 1); } /* * Clear out trash in state accumulated by startup, * and then do the main command loop for a normal edit. * If you quit out of a 'vi' command by doing Q or ^\, * you also fall through to here. */ ungetchar(0); globp = 0; initev = 0; setlastchar('\n'); setexit(); commands(0, 0); cleanup(1); return 0; }
void KU_MATRIX_F(free)( KU_MATRIX_T *matrix ) { pstartp("matrix = %p", matrix); dfree(matrix); pstop(); }
kucode_t NAME(abtree_rem)( ABTREE *tree, TYPE data ) { NODE *cur=tree->ptr; NODE *p; pstart(); // поиск элемента while ( cur!=NULL ) { if ( ABTREE_MORE(data,cur->data) ) { cur=cur->right; } else if ( !ABTREE_EQ(data,cur->data) ) { cur=cur->left; } else break; } if ( cur==NULL ) return KE_NOTFOUND; // замена его минимальным большим элементом p=cur->right; if ( p==NULL ) { p=cur->parent; if ( p!=NULL ) { if ( p->left==cur ) { p->left=cur->left; if ( cur->left!=NULL ) { p->lcnt=max(cur->left->lcnt,cur->left->rcnt)+1; cur->left->parent=p; } else p->lcnt=0; } else { p->right=cur->left; if ( cur->left!=NULL ) { p->rcnt=max(cur->left->lcnt,cur->left->rcnt)+1; cur->left->parent=p; } else p->rcnt=0; } } else { tree->ptr=cur->left; if ( cur->left!=NULL ) cur->left->parent=NULL; } dfree(cur); } else { while ( p->lcnt>0 ) p=p->left; cur->data=p->data; cur=p; p=cur->parent; if ( p->left==cur ) { p->left=cur->right; if ( cur->right!=NULL ) { p->lcnt=max(cur->right->lcnt,cur->right->rcnt)+1; cur->right->parent=p; } else p->lcnt=0; } else { p->right=cur->right; if ( cur->right!=NULL ) { p->rcnt=max(cur->right->lcnt,cur->right->rcnt)+1; cur->right->parent=p; } else p->rcnt=0; } dfree(cur); } // балансировка if ( p!=NULL ) { if ( p->lcnt-p->rcnt==2 ) { ab_rotate_right(tree,p); p=p->parent; } else if ( p->rcnt-p->lcnt==2 ) { ab_rotate_left(tree,p); p=p->parent; } cur=p; p=p->parent; } while ( p!=NULL ) { if ( p->left==cur ) p->lcnt=max(cur->lcnt,cur->rcnt)+1; else p->rcnt=max(cur->lcnt,cur->rcnt)+1; if ( p->lcnt-p->rcnt==2 ) { ab_rotate_right(tree,p); p=p->parent; } else if ( p->rcnt-p->lcnt==2 ) { ab_rotate_left(tree,p); p=p->parent; } cur=p; p=p->parent; } pstop(); return KE_NONE; }