Event Leftist::ExtractAndAdjust (int value, Lnode * ptr) { if ( ! ptr) ErrXit (9115, "NULL ptr"); Event eee; switch (ptr->flag) { case NOT_IN_THIS_SUBTREE: cout << "I5915 Search failed\n"; eee.EventId (ES_NO_EVENT); return eee; case IN_THIS_NODE: ErrXit (9116, "IN_THIS_NODE"); case TURN_LEFT: { if ( ! ptr->lson) ErrXit (9117, "NULL ptr->lson"); if (ptr->lson->flag == IN_THIS_NODE) { Leftist * new_tree = new Leftist (ptr->lson); eee = new_tree->Remove (FROM_FRONT); ptr->lson = new_tree->root; delete new_tree; } else eee = ExtractAndAdjust (value, ptr->lson); if (Lnode::Dista (ptr->lson) < Lnode::Dista (ptr->rson) ) { Lnode * temp = ptr->rson; ptr->rson = ptr->lson; ptr->lson = temp; } break; } case TURN_RIGHT: // same idea, but on right child no swapping necessary { if ( ! ptr->rson) ErrXit (9118, "NULL ptr->rson"); if (ptr->rson->flag == IN_THIS_NODE) { Leftist * new_tree = new Leftist (ptr->rson); eee = new_tree->Remove (FROM_FRONT); ptr->rson = new_tree->root; delete new_tree; } else eee = ExtractAndAdjust (value, ptr->rson); break; } default: ErrXit (9119, "Bad ptr->flag"); } // end switch ptr->dist = Lnode::Dista (ptr->rson) + 1; return eee; }
void Vlist::CannotRemoveFromEmpty (int where) { switch (where) { case FROM_FRONT: ErrXit (9182, "Empty list"); case MATCHING_TOKEN_ID: case MATCHING_EVENT_ID: case MATCHING_EVENT_ROUTINE: case MATCHING_CLASS: return; } ErrXit (9183, "bad where"); }
Event Leftist::Remove (int where, int value, void (*func) () ) { Event eee; if (Empty () ) { CannotRemoveFromEmpty (where); eee.EventId (NOT_FOUND); return eee; } if ( ! root) ErrXit (9112, "NULL root"); Boolean from_front = NO; switch (where) { case FROM_FRONT: from_front = YES; break; case MATCHING_TOKEN_ID: case MATCHING_EVENT_ID: case MATCHING_EVENT_ROUTINE: Search (root, where, value, func); if (root->flag == IN_THIS_NODE) { from_front = YES; break; } eee = ExtractAndAdjust (value, root); size--; return eee; default: ErrXit (9113, "Bad where"); } // end switch if (from_front) { eee = (Event &) (* root); Lnode * rptr = root->rson; Lnode * sitcan = root; root = root->lson; delete sitcan; int sz = --size; if ( ! root) // no left child --> no merge root = rptr; else // no right child --> no merge if (rptr) { Leftist * new_tree = new Leftist (rptr); Merge (new_tree); } size = sz; } return eee; }
void Leftist::Insert (Event item, int where) { if (where != TIME_KEY) ErrXit (9111, "bad where"); Lnode * new_node = new Lnode(); (Event &) (* new_node) = item; Leftist * new_tree = new Leftist (new_node); Merge (new_tree); size ++; if (size > hi_wtr_mark) hi_wtr_mark = size; }
Token ConvertTOKENtoToken (TOKEN old_style_tkn) { Token new_style_tkn; int k_old = MAX_NUM_ATTR; int k_new = MAX_NUM_RATTR; if (k_new < k_old) ErrXit (9171, "Can't convert: old TOKEN bigger than new Token"); int ii; for (ii=0; ii < MAX_NUM_ATTR; ii++) new_style_tkn.SetTokenRattr (ii, old_style_tkn.attr[ii]); int tkn_id = int (old_style_tkn.attr [0]); new_style_tkn.Id (tkn_id); return new_style_tkn; }
int oldnew2lwc_diff(int mindiff, int LWC, int context, char *ignore, char *function, char *old_fn, char *new_fn, char *lwc_diff_fn) { TRACE(fprintf(STDERR, "oldnew2lwc_diff(%i,%i,%i,%s,%s,%s,%s,%s)\n", mindiff, LWC, context, ignore, function, old_fn, new_fn, lwc_diff_fn)); switch (LWC) { case 0: return oldnew2l_diff(mindiff, context, ignore, function, old_fn, new_fn, lwc_diff_fn); case 1: return oldnew2w_diff(mindiff, context, ignore, function, old_fn, new_fn, lwc_diff_fn); case 2: return oldnew2c_diff(mindiff, context, ignore, function, old_fn, new_fn, lwc_diff_fn); default: ErrXit("oldnew2lwc_diff called with wrong LWC", "", 1); } return 0; }
Vlist * Vlist::Constructor (Lspecies fel_type) { switch (fel_type) { case LINKED: return new Linked(); case HEAP: return new Heap (); case CALENDAR: return new Calendar(150, YES); case HENRIK: return new Henrik(); case INOMIAL: return new Inomial(); case LEFTIST: return new Leftist(); case PAGODA: return new Pagoda(); case PAIR: return new Pair(); case SKEWDN: return new Skewdn(); case SKEWUP: return new Skewup(); case SPLAY: return new Splay(); case TWOLIST: return new Twolist(); default: ErrXit (9181, "Bad event list type"); } return NULL; // pacify compiler }
Boolean Leftist::Search (Lnode * ptr, int which, int id, void (*func)() ) { if ( ! ptr) return NO; Boolean is_it_here = NO; switch (which) { case MATCHING_TOKEN_ID: is_it_here = (ptr->Id() == id); break; case MATCHING_EVENT_ID: is_it_here = (ptr->EventId() == id); break; case MATCHING_EVENT_ROUTINE: is_it_here = (ptr->fn == func); break; default: ErrXit (9114, "Bad which"); } if (is_it_here) { ptr->flag = IN_THIS_NODE; return YES; } if (Search (ptr->lson, which, id, func) == YES) { ptr->flag = TURN_LEFT; return YES; } if (Search (ptr->rson, which, id, func) == YES) { ptr->flag = TURN_RIGHT; return YES; } ptr->flag = NOT_IN_THIS_SUBTREE; return NO; }
void Service::Disengage (int srvr_i) { if (srvr_i < 0 || srvr_i >= num_srvrs) ErrXit (9143, "Bad srvr_i"); srvrunit [srvr_i] . tkn_id = FREE; srvrunit [srvr_i] . pri = 0; }
void Service::Engage (int srvr_i, int tkn_id, int pri) { if (srvr_i < 0 || srvr_i >=num_srvrs) ErrXit (9142, "Bad srvr_i"); srvrunit [srvr_i] . tkn_id = tkn_id; srvrunit [srvr_i] . pri = pri; }
Service::Service (int ns) { if (ns < 1) ErrXit (9141, "Bad ns"); num_srvrs = ns; srvrunit = new Srvrunit [num_srvrs]; }
int Service::GetTokenID (int srvr_i) { if (srvr_i < 0 || srvr_i >= num_srvrs) ErrXit (9145, "Bad srvr_i"); return srvrunit [srvr_i] . tkn_id; }
int Service::GetPri (int srvr_i) { if (srvr_i < 0 || srvr_i >= num_srvrs) ErrXit (9144, "Bad srvr_i"); return srvrunit [srvr_i] . pri; }