void insert(char *sorted_word, int index, trie_node *root)
{
	if(*sorted_word=='\0')
	{
		if(root->word>0)
		{
			index_node *temp = root->head;
			while(temp->next!=NULL)
				temp = temp->next;
			temp->next = new_index_node(index);
		} else
		{
			root->head = new_index_node(index);
		}
	} else
	{
		if(root->arr[*sorted_word-'a']==NULL)
		{
			root->arr[*sorted_word-'a'] = new_trie_node();
			insert(sorted_word+1, index, root->arr[*sorted_word-'a']);
		} else
		{
			insert(sorted_word+1, index, root->arr[*sorted_word-'a']);
		}
	}
}
Exemple #2
0
Fichier : pg.c Projet : xrg/pg_top
/*
 * Determine if indexrelid exists in the list and update it if it does.
 * Otherwise Create a new node and insert it into the list.  Sort this
 * list by indexrelid.
 */
struct index_node *
upsert_index_stats(struct index_node * head,
			long long indexrelid, long long idx_scan, long long idx_tup_read,
				   long long idx_tup_fetch)
{
	struct index_node *c = head;

	/* List is empty, create a new node. */
	if (head == NULL)
	{
		head = new_index_node(indexrelid);
		update_index_stats(head, idx_scan, idx_tup_read, idx_tup_fetch);
		return head;
	}

	/* Check if this indexrelid exists already. */
	while (c != NULL)
	{
		if (c->indexrelid == indexrelid)
		{
			/* Found an existing node with same indexrelid, update it. */
			update_index_stats(c, idx_scan, idx_tup_read, idx_tup_fetch);
			return head;
		}
		c = c->next;
	}

	/*
	 * Didn't find indexrelid.  Create a new node, save the data and insert
	 * it.
	 */
	c = new_index_node(indexrelid);
	update_index_stats(c, idx_scan, idx_tup_read, idx_tup_fetch);
	head = insert_index_stats(head, c);
	return head;
}