Esempio n. 1
0
TQueue::~TQueue() {
	SPBLK* q;
	if (least_) { deleteitem(least_); }
	while((q = spdeq(&sptree_->root)) != nil) {
		deleteitem(q);
	}
	delete sptree_;
	while((q = spdeq(&sptree2_->root)) != nil) {
		deleteitem(q);
	}
	delete sptree2_;
}
Esempio n. 2
0
TQueue::~TQueue() {
	SPBLK* q;
	while((q = spdeq(&sptree_->root)) != nil) {
		deleteitem(q);
	}
	delete sptree_;
	while((q = fifo_->dequeue()) != nil) {
		deleteitem(q);
	}
	delete fifo_;
}
Esempio n. 3
0
void TQueue::move_least(double tnew) {
	TQItem* b = least();
	if (b) {
		b->t_ = tnew;
		TQItem* nl = sphead(sptree_);
		if (nl) {
			if (tnew <= nl->t_ && tnew <= q2least_t()) {
				;
			}else if (nl->t_ <= q2least_t()) {
				least_ = spdeq(&sptree_->root);
				sp1enq(b);
			}else{
				least_ = spdeq(&sptree2_->root);
				sp1enq(b);
			}
		}else if (tnew > q2least_t()) {
			least_ = spdeq(&sptree2_->root);
			sp1enq(b);
		}
	}
}
Esempio n. 4
0
/*----------------
 *
 * sphead() --  return the "lowest" element in the tree.
 *
 *      returns a reference to the head event in the event-set q,
 *      represented as a splay tree; q->root ends up pointing to the head
 *      event, and the old left branch of q is shortened, as if q had
 *      been splayed about the head element; this is done by dequeueing
 *      the head and then making the resulting queue the right son of
 *      the head returned by spdeq; an alternative is provided which
 *      avoids splaying but just searches for and returns a pointer to
 *      the bottom of the left branch
 */
SPBLK* sphead(SPTREE* q) {
    SPBLK* x;

    /* splay version, good amortized bound */
    x = spdeq(&q->root);
    if (x != NULL) {
        x->rightlink = q->root;
        x->leftlink = NULL;
        x->uplink = NULL;
        if (q->root != NULL)
            q->root->uplink = x;
    }
    q->root = x;

    /* alternative version, bad amortized bound,
       but faster on the average */

    return (x);

} /* sphead */
Esempio n. 5
0
/*----------------
 *
 * spdelete() -- Delete node from a tree.
 *
 *	n is deleted from q; the resulting splay tree has been splayed
 *	around its new root, which is the successor of n
 *
 */
void spdelete(SPBLK* n, SPTREE* q) {
    SPBLK* x;

    splay(n, q);
    x = spdeq(&q->root->rightlink);
    if (x == NULL) /* empty right subtree */
    {
        q->root = q->root->leftlink;
        if (q->root)
            q->root->uplink = NULL;
    } else /* non-empty right subtree */
    {
        x->uplink = NULL;
        x->leftlink = q->root->leftlink;
        x->rightlink = q->root->rightlink;
        if (x->leftlink != NULL)
            x->leftlink->uplink = x;
        if (x->rightlink != NULL)
            x->rightlink->uplink = x;
        q->root = x;
    }

} /* spdelete */