#include <Unbounded_Set.h>
Inheritance diagram for ACE_Unbounded_Set:


Public Types | |
| typedef ACE_Unbounded_Set_Iterator< T > | ITERATOR |
| typedef ACE_Unbounded_Set_Iterator< T > | iterator |
| typedef ACE_Unbounded_Set_Const_Iterator< T > | CONST_ITERATOR |
| typedef ACE_Unbounded_Set_Const_Iterator< T > | const_iterator |
Public Methods | |
| ACE_Unbounded_Set (ACE_Allocator *alloc=0) | |
| Constructor. Use user specified allocation strategy if specified. More... | |
| ACE_Unbounded_Set (const ACE_Unbounded_Set< T > &) | |
| Copy constructor. More... | |
| void | operator= (const ACE_Unbounded_Set< T > &) |
| Assignment operator. More... | |
| ~ACE_Unbounded_Set (void) | |
| Destructor. More... | |
| int | is_empty (void) const |
| Returns 1 if the container is empty, otherwise returns 0. More... | |
| int | is_full (void) const |
| Returns 0. More... | |
| int | insert (const T &new_item) |
| Linear insertion of an item. More... | |
| int | insert_tail (const T &item) |
| Insert <item> at the tail of the set (doesn't check for duplicates). More... | |
| int | remove (const T &item) |
| Linear remove operation. More... | |
| int | find (const T &item) const |
| Finds if <item> occurs in the set. Returns 0 if find succeeds, else -1. More... | |
| size_t | size (void) const |
| Size of the set. More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
| void | reset (void) |
| Reset the <ACE_Unbounded_Set> to be empty. More... | |
| ACE_Unbounded_Set_Iterator< T > | begin (void) |
| ACE_Unbounded_Set_Iterator< T > | end (void) |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Private Methods | |
| void | delete_nodes (void) |
| Delete all the nodes in the Set. More... | |
| void | copy_nodes (const ACE_Unbounded_Set< T > &) |
| Copy nodes into this set. More... | |
Private Attributes | |
| ACE_Node< T > * | head_ |
| Head of the linked list of Nodes. More... | |
| size_t | cur_size_ |
| Current size of the set. More... | |
| ACE_Allocator * | allocator_ |
| Allocation strategy of the set. More... | |
Friends | |
| class | ACE_Unbounded_Set_Iterator< T > |
| class | ACE_Unbounded_Set_Const_Iterator< T > |
This implementation of an unordered set uses a circular linked list with a dummy node. This implementation does not allow duplicates, but it maintains FIFO ordering of insertions.
Requirements and Performance Characteristics
Definition at line 177 of file Unbounded_Set.h.
|
|||||
|
Definition at line 187 of file Unbounded_Set.h. |
|
|||||
|
Definition at line 186 of file Unbounded_Set.h. |
|
|||||
|
Definition at line 185 of file Unbounded_Set.h. |
|
|||||
|
Definition at line 184 of file Unbounded_Set.h. |
|
||||||||||
|
Constructor. Use user specified allocation strategy if specified. Initialize an empty set using the allocation strategy of the user if provided. Definition at line 132 of file Unbounded_Set.cpp. References ACE_NEW_MALLOC, allocator_, head_, and ACE_Allocator::instance.
00133 : head_ (0), 00134 cur_size_ (0), 00135 allocator_ (alloc) 00136 { 00137 // ACE_TRACE ("ACE_Unbounded_Set<T>::ACE_Unbounded_Set"); 00138 00139 if (this->allocator_ == 0) 00140 this->allocator_ = ACE_Allocator::instance (); 00141 00142 ACE_NEW_MALLOC (this->head_, 00143 (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), 00144 ACE_Node<T>); 00145 // Make the list circular by pointing it back to itself. 00146 this->head_->next_ = this->head_; 00147 } |
|
||||||||||
|
Copy constructor. Initialize this set to be an exact copy of the set provided. Definition at line 150 of file Unbounded_Set.cpp. References ACE_NEW_MALLOC, ACE_TRACE, allocator_, copy_nodes, head_, and ACE_Allocator::instance.
00151 : head_ (0), 00152 cur_size_ (0), 00153 allocator_ (us.allocator_) 00154 { 00155 ACE_TRACE ("ACE_Unbounded_Set<T>::ACE_Unbounded_Set"); 00156 00157 if (this->allocator_ == 0) 00158 this->allocator_ = ACE_Allocator::instance (); 00159 00160 ACE_NEW_MALLOC (this->head_, 00161 (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), 00162 ACE_Node<T>); 00163 this->head_->next_ = this->head_; 00164 this->copy_nodes (us); 00165 } |
|
||||||||||
|
Destructor. Destroy the nodes of the set. Definition at line 117 of file Unbounded_Set.cpp. References ACE_DES_FREE_TEMPLATE, delete_nodes, and head_.
00118 {
00119 // ACE_TRACE ("ACE_Unbounded_Set<T>::~ACE_Unbounded_Set");
00120
00121 this->delete_nodes ();
00122
00123 // Delete the dummy node.
00124 ACE_DES_FREE_TEMPLATE (head_,
00125 this->allocator_->free,
00126 ACE_Node,
00127 <T>);
00128 this->head_ = 0;
00129 }
|
|
||||||||||
|
Definition at line 237 of file Unbounded_Set.cpp. Referenced by ACE_Registry::make_string, and ACE_Registry::Binding_Iterator::next_one.
00238 {
00239 // ACE_TRACE ("ACE_Unbounded_Set<T>::begin");
00240 return ACE_Unbounded_Set_Iterator<T> (*this);
00241 }
|
|
||||||||||
|
Copy nodes into this set.
Definition at line 86 of file Unbounded_Set.cpp. References head_, insert_tail, ACE_Node::item_, and ACE_Node::next_. Referenced by ACE_Unbounded_Set, and operator=.
00087 {
00088 for (ACE_Node<T> *curr = us.head_->next_;
00089 curr != us.head_;
00090 curr = curr->next_)
00091 this->insert_tail (curr->item_);
00092 }
|
|
||||||||||
|
Delete all the nodes in the Set.
Definition at line 95 of file Unbounded_Set.cpp. References ACE_DES_FREE_TEMPLATE, cur_size_, head_, and ACE_Node::next_. Referenced by operator=, reset, and ~ACE_Unbounded_Set.
00096 {
00097 ACE_Node<T> *curr = this->head_->next_;
00098
00099 // Keep looking until we've hit the dummy node.
00100
00101 while (curr != this->head_)
00102 {
00103 ACE_Node<T> *temp = curr;
00104 curr = curr->next_;
00105 ACE_DES_FREE_TEMPLATE (temp,
00106 this->allocator_->free,
00107 ACE_Node,
00108 <T>);
00109 this->cur_size_--;
00110 }
00111
00112 // Reset the list to be a circular list with just a dummy node.
00113 this->head_->next_ = this->head_;
00114 }
|
|
||||||||||
|
Dump the state of an object.
Definition at line 63 of file Unbounded_Set.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, ACE_Unbounded_Set_Iterator::advance, LM_DEBUG, and ACE_Unbounded_Set_Iterator::next.
00064 {
00065 ACE_TRACE ("ACE_Unbounded_Set<T>::dump");
00066
00067 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00068 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nhead_ = %u"), this->head_));
00069 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nhead_->next_ = %u"), this->head_->next_));
00070 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ncur_size_ = %d\n"), this->cur_size_));
00071
00072 T *item = 0;
00073 #if !defined (ACE_NLOGGING)
00074 size_t count = 1;
00075 #endif /* ! ACE_NLOGGING */
00076
00077 for (ACE_Unbounded_Set_Iterator<T> iter (*(ACE_Unbounded_Set<T> *) this);
00078 iter.next (item) != 0;
00079 iter.advance ())
00080 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("count = %d\n"), count++));
00081
00082 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00083 }
|
|
||||||||||
|
Definition at line 244 of file Unbounded_Set.cpp. Referenced by ACE_Registry::make_string.
00245 {
00246 // ACE_TRACE ("ACE_Unbounded_Set<T>::end");
00247 return ACE_Unbounded_Set_Iterator<T> (*this, 1);
00248 }
|
|
||||||||||
|
Finds if <item> occurs in the set. Returns 0 if find succeeds, else -1. Performs a linear find operation. Definition at line 180 of file Unbounded_Set.cpp. References head_, ACE_Node::item_, and ACE_Node::next_. Referenced by insert.
00181 {
00182 // ACE_TRACE ("ACE_Unbounded_Set<T>::find");
00183 // Set <item> into the dummy node.
00184 this->head_->item_ = item;
00185
00186 ACE_Node<T> *temp = this->head_->next_;
00187
00188 // Keep looping until we find the item.
00189 while (!(temp->item_ == item))
00190 temp = temp->next_;
00191
00192 // If we found the dummy node then it's not really there, otherwise,
00193 // it is there.
00194 return temp == this->head_ ? -1 : 0;
00195 }
|
|
||||||||||
|
||||||||||
|
Insert <item> at the tail of the set (doesn't check for duplicates). Constant time insert at the end of the set. Definition at line 30 of file Unbounded_Set.cpp. References ACE_NEW_MALLOC_RETURN, cur_size_, and head_. Referenced by copy_nodes, and insert.
00031 {
00032 // ACE_TRACE ("ACE_Unbounded_Set<T>::insert_tail");
00033 ACE_Node<T> *temp;
00034
00035 // Insert <item> into the old dummy node location.
00036 this->head_->item_ = item;
00037
00038 // Create a new dummy node.
00039 ACE_NEW_MALLOC_RETURN (temp,
00040 ACE_static_cast(ACE_Node<T>*,
00041 this->allocator_->malloc (sizeof (ACE_Node<T>))),
00042 ACE_Node<T> (this->head_->next_),
00043 -1);
00044 // Link this pointer into the list.
00045 this->head_->next_ = temp;
00046
00047 // Point the head to the new dummy node.
00048 this->head_ = temp;
00049
00050 this->cur_size_++;
00051 return 0;
00052 }
|
|
||||||||||
|
Returns 1 if the container is empty, otherwise returns 0. Constant time is_empty check. Definition at line 5 of file Unbounded_Set.inl. References ACE_TRACE, and head_.
|
|
||||||||||
|
Returns 0. Always returns 0 since the set can never fill up. Definition at line 12 of file Unbounded_Set.inl. References ACE_TRACE.
00013 {
00014 ACE_TRACE ("ACE_Unbounded_Set<T>::is_full");
00015 return 0; // We should implement a "node of last resort for this..."
00016 }
|
|
||||||||||
|
Assignment operator. Perform a deep copy of the rhs into the lhs. Definition at line 168 of file Unbounded_Set.cpp. References ACE_TRACE, copy_nodes, and delete_nodes.
00169 {
00170 ACE_TRACE ("ACE_Unbounded_Set<T>::operator=");
00171
00172 if (this != &us)
00173 {
00174 this->delete_nodes ();
00175 this->copy_nodes (us);
00176 }
00177 }
|
|
||||||||||
|
Linear remove operation. Remove first occurrence of <item> from the set. Returns 0 if it removes the item, -1 if it can't find the item, and -1 if a failure occurs. Definition at line 208 of file Unbounded_Set.cpp. References ACE_DES_FREE_TEMPLATE, cur_size_, head_, and ACE_Node::next_.
00209 {
00210 // ACE_TRACE ("ACE_Unbounded_Set<T>::remove");
00211
00212 // Insert the item to be founded into the dummy node.
00213 this->head_->item_ = item;
00214
00215 ACE_Node<T> *curr = this->head_;
00216
00217 while (!(curr->next_->item_ == item))
00218 curr = curr->next_;
00219
00220 if (curr->next_ == this->head_)
00221 return -1; // Item was not found.
00222 else
00223 {
00224 ACE_Node<T> *temp = curr->next_;
00225 // Skip over the node that we're deleting.
00226 curr->next_ = temp->next_;
00227 this->cur_size_--;
00228 ACE_DES_FREE_TEMPLATE (temp,
00229 this->allocator_->free,
00230 ACE_Node,
00231 <T>);
00232 return 0;
00233 }
00234 }
|
|
||||||||||
|
Reset the <ACE_Unbounded_Set> to be empty. Delete the nodes of the set. Definition at line 55 of file Unbounded_Set.cpp. References ACE_TRACE, and delete_nodes. Referenced by ACE_Registry::Naming_Context::list.
00056 {
00057 ACE_TRACE ("reset");
00058
00059 this->delete_nodes ();
00060 }
|
|
||||||||||
|
Size of the set. Access the size of the set. Definition at line 23 of file Unbounded_Set.cpp. References cur_size_.
00024 {
00025 // ACE_TRACE ("ACE_Unbounded_Set<T>::size");
00026 return this->cur_size_;
00027 }
|
|
|||||
|
Definition at line 181 of file Unbounded_Set.h. |
|
|||||
|
Definition at line 180 of file Unbounded_Set.h. |
|
|||||
|
Declare the dynamic allocation hooks.
Definition at line 282 of file Unbounded_Set.h. |
|
|||||
|
Allocation strategy of the set.
Definition at line 298 of file Unbounded_Set.h. Referenced by ACE_Unbounded_Set. |
|
|||||
|
Current size of the set.
Definition at line 295 of file Unbounded_Set.h. Referenced by delete_nodes, insert_tail, remove, and size. |
|
|||||
|
Head of the linked list of Nodes.
Definition at line 292 of file Unbounded_Set.h. Referenced by ACE_Unbounded_Set, copy_nodes, delete_nodes, find, insert_tail, is_empty, remove, and ~ACE_Unbounded_Set. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002