template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::unbind_all_i (void) { // Iterate through the entire map calling the destuctor of each // <ACE_Hash_Map_Entry>. for (size_t i = 0; i < this->total_size_; i++) { for (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp_ptr = this->table_[i].next_; temp_ptr != &this->table_[i]; ) { ACE_Hash_Map_Entry<EXT_ID, INT_ID> *hold_ptr = temp_ptr; temp_ptr = temp_ptr->next_; // Explicitly call the destructor. ACE_DES_FREE_TEMPLATE2 (hold_ptr, this->allocator_->free, ACE_Hash_Map_Entry, EXT_ID, INT_ID); } // Restore the sentinel. this->table_[i].next_ = &this->table_[i]; this->table_[i].prev_ = &this->table_[i]; } this->cur_size_ = 0; return 0; }
template <class T, class C> int ACE_Unbounded_Set_Ex<T, C>::remove (const T &item) { // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::remove"); // Insert the item to be founded into the dummy node. this->head_->item_ = item; NODE *curr = this->head_; while (!(this->comp_ (curr->next_->item_, item))) curr = curr->next_; if (curr->next_ == this->head_) return -1; // Item was not found. else { NODE *temp = curr->next_; // Skip over the node that we're deleting. curr->next_ = temp->next_; --this->cur_size_; ACE_DES_FREE_TEMPLATE2 (temp, this->allocator_->free, ACE_Node, T, C); return 0; } }
template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::close_i (void) { // Protect against "double-deletion" in case the destructor also // gets called. if (this->table_ != 0) { // Remove all the entries. this->unbind_all_i (); // Iterate through the buckets cleaning up the sentinels. for (size_t i = 0; i < this->total_size_; i++) { // Destroy the dummy entry. ACE_Hash_Map_Entry<EXT_ID, INT_ID> *entry = &this->table_[i]; // The "if" second argument results in a no-op instead of // deallocation. ACE_DES_FREE_TEMPLATE2 (entry, ACE_NOOP, ACE_Hash_Map_Entry, EXT_ID, INT_ID); } // Reset size. this->total_size_ = 0; // Free table memory. this->allocator_->free (this->table_); // Should be done last... this->table_ = 0; } return 0; }
template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::unbind_i (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *entry) { entry->next_->prev_ = entry->prev_; entry->prev_->next_ = entry->next_; // Explicitly call the destructor. ACE_DES_FREE_TEMPLATE2 (entry, this->allocator_->free, ACE_Hash_Map_Entry, EXT_ID, INT_ID); this->cur_size_--; return 0; }
void ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::delete_children_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> *parent) { if (parent) { this->delete_children_i (parent->left ()); this->delete_children_i (parent->right ()); ACE_DES_FREE_TEMPLATE2 (parent->left (), this->allocator_->free, ACE_RB_Tree_Node, EXT_ID, INT_ID); ACE_DES_FREE_TEMPLATE2 (parent->right (), this->allocator_->free, ACE_RB_Tree_Node, EXT_ID, INT_ID); parent->left (0); parent->right (0); } return; }
ACE_Unbounded_Set_Ex<T, C>::~ACE_Unbounded_Set_Ex (void) { // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::~ACE_Unbounded_Set_Ex"); this->delete_nodes (); // Delete the dummy node. ACE_DES_FREE_TEMPLATE2 (head_, this->allocator_->free, ACE_Node, T, C); this->head_ = 0; }
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::close_i () { ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::close_i"); this->delete_children_i (this->root_); ACE_DES_FREE_TEMPLATE2 (this->root_, this->allocator()->free, ACE_RB_Tree_Node, EXT_ID, INT_ID); this->current_size_ = 0; this->root_ = 0; return 0; }
template <class EXT_ID, class INT_ID, class ACE_LOCK> void ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::free_search_structure (void) { // Free up the structure. if (this->search_structure_ != 0) { for (ACE_UINT32 i = 0; i < this->total_size_; i++) // Explicitly call the destructor. { ENTRY *ss = &this->search_structure_[i]; // The "if" second argument results in a no-op instead of // deallocation. ACE_DES_FREE_TEMPLATE2 (ss, ACE_NOOP, ACE_Map_Entry, EXT_ID, INT_ID); } // Actually free the memory. this->allocator_->free (this->search_structure_); this->search_structure_ = 0; } }
template <class T, class C> void ACE_Unbounded_Set_Ex<T, C>::delete_nodes (void) { NODE *curr = this->head_->next_; // Keep looking until we've hit the dummy node. while (curr != this->head_) { NODE *temp = curr; curr = curr->next_; ACE_DES_FREE_TEMPLATE2 (temp, this->allocator_->free, ACE_Node, T, C); --this->cur_size_; } // Reset the list to be a circular list with just a dummy node. this->head_->next_ = this->head_; }
template <class EXT_ID, class INT_ID> int JAWS_Hash_Bucket_DLCStack<EXT_ID, INT_ID>::remove (JAWS_HASH_BUCKET_ITEM *item) { int result = 0; if (item != 0) { if (item->next_ != 0 && item->prev_ != 0) { if (item->next_ != item) { if (this->head_ == item) this->head_ = item->next_; if (this->tail_ == item) this->tail_ = item->prev_; item->next_->prev_ = item->prev_; item->prev_->next_ = item->next_; } else { this->head_ = this->tail_ = 0; } item->next_ = 0; item->prev_ = 0; } if (item->next_ == 0 && item->prev_ == 0) { ACE_DES_FREE_TEMPLATE2 (item, this->allocator_->free, JAWS_Hash_Bucket_Item, EXT_ID, INT_ID); } else result = -1; } return result; }
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::remove_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> *z) { ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::remove_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> *z)"); // Delete the node and reorganize the tree to satisfy the Red-Black // properties. ACE_RB_Tree_Node<EXT_ID, INT_ID> *x; ACE_RB_Tree_Node<EXT_ID, INT_ID> *y; ACE_RB_Tree_Node<EXT_ID, INT_ID> *parent; if (z->left () && z->right ()) y = RB_tree_successor (z); else y = z; if (!y) return -1; if (y->left ()) x = y->left (); else x = y->right (); parent = y->parent (); if (x) { x->parent (parent); } if (parent) { if (y == parent->left ()) parent->left (x); else parent->right (x); } else this->root_ = x; if (y != z) { // Replace node z with node y, since y's pointer may well be // held externally, and be linked with y's key and item. // We will end up deleting the old unlinked, node z. ACE_RB_Tree_Node<EXT_ID, INT_ID> *zParent = z->parent (); ACE_RB_Tree_Node<EXT_ID, INT_ID> *zLeftChild = z->left (); ACE_RB_Tree_Node<EXT_ID, INT_ID> *zRightChild = z->right (); if (zParent) { if (z == zParent->left ()) { zParent->left (y); } else { zParent->right (y); } } else { this->root_ = y; } y->parent (zParent); if (zLeftChild) { zLeftChild->parent (y); } y->left (zLeftChild); if (zRightChild) { zRightChild->parent (y); } y->right (zRightChild); if (parent == z) { parent = y; } ACE_RB_Tree_Node_Base::RB_Tree_Node_Color yColor = y->color (); y->color (z->color ()); z->color (yColor); //Reassign the y pointer to z because the node that y points to will be //deleted y = z; } // CLR pp. 263 says that nil nodes are implicitly colored BLACK if (!y || y->color () == ACE_RB_Tree_Node_Base::BLACK) RB_delete_fixup (x, parent); y->parent (0); y->right (0); y->left (0); ACE_DES_FREE_TEMPLATE2 (y, this->allocator_->free, ACE_RB_Tree_Node, EXT_ID, INT_ID); --this->current_size_; return 0; }
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::remove_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> *z) { ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::remove_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> *z)"); // Delete the node and reorganize the tree to satisfy the Red-Black // properties. ACE_RB_Tree_Node<EXT_ID, INT_ID> *x; ACE_RB_Tree_Node<EXT_ID, INT_ID> *y; ACE_RB_Tree_Node<EXT_ID, INT_ID> *parent; if (z->left () && z->right ()) y = RB_tree_successor (z); else y = z; if (!y) return -1; if (y->left ()) x = y->left (); else x = y->right (); parent = y->parent (); if (x) { x->parent (parent); } if (parent) { if (y == parent->left ()) parent->left (x); else parent->right (x); } else this->root_ = x; if (y != z) { // Copy the elements of y into z. z->key () = y->key (); z->item () = y->item (); } // CLR pp. 263 says that nil nodes are implicitly colored BLACK if (!y || y->color () == ACE_RB_Tree_Node_Base::BLACK) RB_delete_fixup (x, parent); y->parent (0); y->right (0); y->left (0); ACE_DES_FREE_TEMPLATE2 (y, this->allocator_->free, ACE_RB_Tree_Node, EXT_ID, INT_ID); --this->current_size_; return 0; }