Example #1
0
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &rbt)
    : root_ (0),
      current_size_ (0)
{
    ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &rbt)");
    ACE_WRITE_GUARD (ACE_LOCK, ace_mon, this->lock_);
    allocator_ = rbt.allocator_;

    // Make a deep copy of the passed tree.
    ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> iter(rbt);

    for (iter.first ();

            iter.is_done () == 0; iter.next ())
        insert_i (*(iter.key ()),
                  *(iter.item ()));
}
Example #2
0
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> void
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::operator = (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &rbt)
{
    ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::operator =");
    ACE_WRITE_GUARD (ACE_LOCK, ace_mon, this->lock_);

    if (this != &rbt)
    {
        // Clear out the existing tree.
        close_i ();

        // Make a deep copy of the passed tree.
        ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> iter(rbt);

        for (iter.first ();
                iter.is_done () == 0;
                iter.next ())
            insert_i (*(iter.key ()),
                      *(iter.item ()));

        // Use the same allocator as the rhs.
        allocator_ = rbt.allocator_;
    }
}
void insert_i(Trie * node, const char * key, const char * val, int pos, int n, int idx) 
{
	if( pos == n) 
	{	
		/* Se achou o elemento */
		int size = strlen(val);

		/* Se ainda está nulo, aloca o espaço */
		if(node->elem == NULL) 
			node->elem = (char*) malloc(sizeof(char) * size);
		/* Copia o identificador para a posição correta */
		strcpy(node->elem, val);

		node->idx = idx;
	} else {
		/* Se o nó que precisa ser inserido está nulo, alocar */
		if(node->branch[mapChar(val[pos])] == NULL) {
			node->branch[mapChar(val[pos])] = (Trie*) malloc(sizeof(Trie));
			initializeTrie(node->branch[mapChar(val[pos])]);
		}

 		insert_i(node->branch[mapChar(val[pos])], key, val, pos+1, n, idx);
	}
}
/* Interface para o insert interno (insert_i) */
void insert(Trie *node, const char *key, const char *val, int idx){
	insert_i(node, key, val, 0, strlen(key), idx);
}