Exemple #1
0
int
Map<S,T>::remove(const S& s)
{
	Mapnode_ATTLC<S,T>* t = head();
	while (t) {
		if (s < t->map_data.key)
			t = t->L();
		else if (t->map_data.key < s)
			t = t->R();
		else break;
	}
	if (t) {
		if (mi_count > 0) {
			remove_flag = 1;
			if (!t->remove_mark) {
				t->remove_mark = 1;
				n--;
			}
			return (1);
		}
		else {
			removenode(t);
			delete t;
			n--;
			return (1);
		}
	}
	else {
		return (0);
	}
}
Exemple #2
0
/** The add() routine add input command to history record, which implemented by linked list
first check if input command has existed in history record. if existed, move to tail. Then check the size of 
history record, if it meet the capacity of history record, remove the head node.
@args: int no: the id of the command
@args: char inBuff[]: command entered
@args: node start: the head of the linked list
@args: size: record the size of history record.
@args: capacity: the capacity of history record, could change by sethistory(), the default value is 8

***/
void add(int no,char inBuff[],struct node *start,int* size,int capacity){

    struct node *temp=search(inBuff,&start);    /*call search() to check if the command have existed in history record*/
    if(temp->next!=NULL){                       /*if existed, remove it*/
        removenode(temp);
        *size-=1;
    }
    while(*size >=capacity){                    /*check the record size, if over flow, remove the element from the head of linked list*/
        removenode(start);
        *size-=1;
    }

    struct node *current=start;                /*create a new node*/
    struct node *newnode=(struct node *) malloc(sizeof(struct node));
    newnode->index=no;
    strcpy(newnode->argsBuff, inBuff);
    newnode->next=NULL;

    while(current->next!=NULL){                /*append it to the tail of linked list*/
        current=current->next;
    }
    current->next=newnode;
    *size+=1;
}
Exemple #3
0
/*
 * Remove old nodes (directories).
 * Note that this routine runs in O(N*D) where:
 *	N is the number of directory entries to be removed.
 *	D is the maximum depth of the tree.
 * If N == D this can be quite slow. If the list were
 * topologically sorted, the deletion could be done in
 * time O(N).
 */
void
removeoldnodes(void)
{
	struct entry *ep, **prev;
	long change;

	vprintf(stdout, "Remove old nodes (directories).\n");
	do	{
		change = 0;
		prev = &removelist;
		for (ep = removelist; ep != NULL; ep = *prev) {
			if (ep->e_entries != NULL) {
				prev = &ep->e_next;
				continue;
			}
			*prev = ep->e_next;
			removenode(ep);
			freeentry(ep);
			change++;
		}
	} while (change);
	for (ep = removelist; ep != NULL; ep = ep->e_next)
		badentry(ep, "cannot remove, non-empty");
}