ACE_Fixed_Set< T, ACE_SIZE > Class Template Reference

Implement a simple unordered set of {T} with maximum {ACE_SIZE}. More...

#include <Containers_T.h>

Collaboration diagram for ACE_Fixed_Set< T, ACE_SIZE >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_Fixed_Set_Iterator<
T, ACE_SIZE > 
ITERATOR
typedef ACE_Fixed_Set_Const_Iterator<
T, ACE_SIZE > 
CONST_ITERATOR

Public Member Functions

 ACE_Fixed_Set (void)
 Default Constructor.

 ACE_Fixed_Set (const ACE_Fixed_Set< T, ACE_SIZE > &)
 Copy constructor.

void operator= (const ACE_Fixed_Set< T, ACE_SIZE > &)
 Assignment operator.

 ~ACE_Fixed_Set (void)
 Destructor.

int is_empty (void) const
 Returns 1 if the container is empty, otherwise returns 0.

int is_full (void) const
 Returns 1 if the container is full, otherwise returns 0.

int insert (const T &new_item)
 Linear time insertion of an item unique to the set.

int remove (const T &item)
 Linear time removal operation of an item.

int find (const T &item) const
 Finds if item occurs in the set. Returns 0 if finds, else -1.

size_t size (void) const
 Size of the set.

void dump (void) const
 Dump the state of an object.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Attributes

struct {
   T   item_
   int   is_free_
search_structure_ [ACE_SIZE]
 Holds the contents of the set.

size_t cur_size_
 Current size of the set.

size_t max_size_
 Maximum size of the set.


Friends

class ACE_Fixed_Set_Iterator_Base< T, ACE_SIZE >
class ACE_Fixed_Set_Iterator< T, ACE_SIZE >
class ACE_Fixed_Set_Const_Iterator< T, ACE_SIZE >

Detailed Description

template<class T, size_t ACE_SIZE>
class ACE_Fixed_Set< T, ACE_SIZE >

Implement a simple unordered set of {T} with maximum {ACE_SIZE}.

This implementation of an unordered set uses a fixed array. It does not allow duplicate members. The set provides linear insertion/deletion operations.

Requirements and Performance Characteristics

Definition at line 1355 of file Containers_T.h.


Member Typedef Documentation

template<class T, size_t ACE_SIZE>
typedef ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE> ACE_Fixed_Set< T, ACE_SIZE >::CONST_ITERATOR
 

Definition at line 1364 of file Containers_T.h.

template<class T, size_t ACE_SIZE>
typedef ACE_Fixed_Set_Iterator<T, ACE_SIZE> ACE_Fixed_Set< T, ACE_SIZE >::ITERATOR
 

Definition at line 1363 of file Containers_T.h.


Constructor & Destructor Documentation

template<class T, size_t ACE_SIZE>
ACE_Fixed_Set< T, ACE_SIZE >::ACE_Fixed_Set void   ) 
 

Default Constructor.

Creates an empy set

Definition at line 959 of file Containers_T.cpp.

References ACE_TRACE, and ACE_Fixed_Set< T, ACE_SIZE >::search_structure_.

00960   : cur_size_ (0),
00961     max_size_ (ACE_SIZE)
00962 {
00963   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::ACE_Fixed_Set");
00964   for (size_t i = 0; i < this->max_size_; i++)
00965     this->search_structure_[i].is_free_ = 1;
00966 }

template<class T, size_t ACE_SIZE>
ACE_Fixed_Set< T, ACE_SIZE >::ACE_Fixed_Set const ACE_Fixed_Set< T, ACE_SIZE > &   ) 
 

Copy constructor.

Initializes a set to be a copy of the set parameter.

Definition at line 933 of file Containers_T.cpp.

References ACE_TRACE, ACE_Fixed_Set< T, ACE_SIZE >::max_size_, and ACE_Fixed_Set< T, ACE_SIZE >::search_structure_.

00934   : cur_size_ (fs.cur_size_)
00935 {
00936   ACE_TRACE ("ACE_Fixed_Set<T>::ACE_Fixed_Set");
00937 
00938   for (size_t i = 0, j = 0; i < fs.max_size_ && j < this->cur_size_; ++i)
00939     if (fs.search_structure_[i].is_free_ == 0)
00940       this->search_structure_[j++] = fs.search_structure_[i];
00941 }

template<class T, size_t ACE_SIZE>
ACE_Fixed_Set< T, ACE_SIZE >::~ACE_Fixed_Set void   ) 
 

Destructor.

Destroys a set.

Definition at line 926 of file Containers_T.cpp.

References ACE_TRACE.

00927 {
00928   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::~ACE_Fixed_Set");
00929   this->cur_size_ = 0;
00930 }


Member Function Documentation

template<class T, size_t ACE_SIZE>
void ACE_Fixed_Set< T, ACE_SIZE >::dump void   )  const
 

Dump the state of an object.

Definition at line 918 of file Containers_T.cpp.

References ACE_TRACE.

00919 {
00920 #if defined (ACE_HAS_DUMP)
00921   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::dump");
00922 #endif /* ACE_HAS_DUMP */
00923 }

template<class T, size_t ACE_SIZE>
int ACE_Fixed_Set< T, ACE_SIZE >::find const T &  item  )  const
 

Finds if item occurs in the set. Returns 0 if finds, else -1.

Performs a linear find operation for the specified item.

Definition at line 969 of file Containers_T.cpp.

References ACE_TRACE, and ACE_Fixed_Set< T, ACE_SIZE >::search_structure_.

00970 {
00971   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::find");
00972 
00973   for (size_t i = 0, j = 0; i < this->max_size_ && j < this->cur_size_; ++i)
00974     if (this->search_structure_[i].is_free_ == 0)
00975       {
00976         if (this->search_structure_[i].item_ == item)
00977           return 0;
00978         ++j;
00979       }
00980 
00981   return -1;
00982 }

template<class T, size_t ACE_SIZE>
int ACE_Fixed_Set< T, ACE_SIZE >::insert const T &  new_item  ) 
 

Linear time insertion of an item unique to the set.

Insert new_item into the set (doesn't allow duplicates). Returns -1 if failures occur, 1 if item is already present, else 0.

Definition at line 985 of file Containers_T.cpp.

References ACE_TRACE, ACE_Fixed_Set< T, ACE_SIZE >::search_structure_, and ssize_t.

Referenced by ACE_Sig_Handlers::handler(), and ACE_Sig_Handlers::register_handler().

00986 {
00987   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::insert");
00988   ssize_t first_free = -1;   // Keep track of first free slot.
00989   size_t i;
00990 
00991   for (i = 0;
00992        i < this->max_size_  && first_free == -1;
00993        ++i)
00994 
00995     // First, make sure we don't allow duplicates.
00996 
00997     if (this->search_structure_[i].is_free_ == 0)
00998       {
00999         if (this->search_structure_[i].item_ == item)
01000           return 1;
01001       }
01002     else
01003       first_free = i;
01004 
01005   // If we found a free spot let's reuse it.
01006 
01007   if (first_free > -1)
01008     {
01009       this->search_structure_[first_free].item_ = item;
01010       this->search_structure_[first_free].is_free_ = 0;
01011       this->cur_size_++;
01012       return 0;
01013     }
01014   else /* No more room! */
01015     {
01016       errno = ENOMEM;
01017       return -1;
01018     }
01019 }

template<class T, size_t ACE_SIZE>
ACE_INLINE int ACE_Fixed_Set< T, ACE_SIZE >::is_empty void   )  const
 

Returns 1 if the container is empty, otherwise returns 0.

Performs constant time check to determine if a set is empty.

Definition at line 166 of file Containers_T.inl.

References ACE_TRACE.

00167 {
00168   ACE_TRACE ("ACE_Fixed_Set<T>::is_empty");
00169   return this->cur_size_ == 0;
00170 }

template<class T, size_t ACE_SIZE>
ACE_INLINE int ACE_Fixed_Set< T, ACE_SIZE >::is_full void   )  const
 

Returns 1 if the container is full, otherwise returns 0.

Performs a constant time check to see if the set is full.

Definition at line 173 of file Containers_T.inl.

References ACE_TRACE.

00174 {
00175   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::is_full");
00176   return this->cur_size_ == this->max_size_;
00177 }

template<class T, size_t ACE_SIZE>
void ACE_Fixed_Set< T, ACE_SIZE >::operator= const ACE_Fixed_Set< T, ACE_SIZE > &   ) 
 

Assignment operator.

Deep copy of one set to another.

Definition at line 944 of file Containers_T.cpp.

References ACE_TRACE, ACE_Fixed_Set< T, ACE_SIZE >::cur_size_, ACE_Fixed_Set< T, ACE_SIZE >::max_size_, and ACE_Fixed_Set< T, ACE_SIZE >::search_structure_.

00945 {
00946   ACE_TRACE ("ACE_Fixed_Set<T>::operator=");
00947 
00948   if (this != &fs)
00949     {
00950       this->cur_size_ = fs.cur_size_;
00951 
00952       for (size_t i = 0, j = 0; i < fs.max_size_ && j < this->cur_size_; ++i)
00953         if (fs.search_structure_[i].is_free_ == 0)
00954           this->search_structure_[j++] = fs.search_structure_[i];
00955     }
00956 }

template<class T, size_t ACE_SIZE>
int ACE_Fixed_Set< T, ACE_SIZE >::remove const T &  item  ) 
 

Linear time removal operation of an item.

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. Removal doesn't reclaim memory for the item.

Definition at line 1022 of file Containers_T.cpp.

References ACE_TRACE, and ACE_Fixed_Set< T, ACE_SIZE >::search_structure_.

Referenced by ACE_Sig_Handlers::dispatch(), ACE_Sig_Handlers::handler(), ACE_Sig_Handlers::register_handler(), and ACE_Sig_Handlers::remove_handler().

01023 {
01024   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::remove");
01025 
01026   for (size_t i = 0, j = 0;
01027        i < this->max_size_ && j < this->cur_size_;
01028        ++i)
01029     if (this->search_structure_[i].is_free_ == 0)
01030       {
01031         if (this->search_structure_[i].item_ == item)
01032           {
01033             // Mark this entry as being free.
01034             this->search_structure_[i].is_free_ = 1;
01035 
01036             --this->cur_size_;
01037             return 0;
01038           }
01039         else
01040           ++j;
01041       }
01042 
01043   return -1;
01044 }

template<class T, size_t ACE_SIZE>
size_t ACE_Fixed_Set< T, ACE_SIZE >::size void   )  const
 

Size of the set.

Returns the current size of the set.

Definition at line 911 of file Containers_T.cpp.

References ACE_TRACE.

Referenced by ACE_Sig_Handlers::remove_handler().

00912 {
00913   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::size");
00914   return this->cur_size_;
00915 }


Friends And Related Function Documentation

template<class T, size_t ACE_SIZE>
friend class ACE_Fixed_Set_Const_Iterator< T, ACE_SIZE > [friend]
 

Definition at line 1360 of file Containers_T.h.

template<class T, size_t ACE_SIZE>
friend class ACE_Fixed_Set_Iterator< T, ACE_SIZE > [friend]
 

Definition at line 1359 of file Containers_T.h.

template<class T, size_t ACE_SIZE>
friend class ACE_Fixed_Set_Iterator_Base< T, ACE_SIZE > [friend]
 

Definition at line 1358 of file Containers_T.h.


Member Data Documentation

template<class T, size_t ACE_SIZE>
ACE_Fixed_Set< T, ACE_SIZE >::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 1439 of file Containers_T.h.

template<class T, size_t ACE_SIZE>
size_t ACE_Fixed_Set< T, ACE_SIZE >::cur_size_ [private]
 

Current size of the set.

Definition at line 1453 of file Containers_T.h.

Referenced by ACE_Fixed_Set< T, ACE_SIZE >::operator=().

template<class T, size_t ACE_SIZE>
int ACE_Fixed_Set< T, ACE_SIZE >::is_free_ [private]
 

Keeps track of whether this item is in use or not.

Definition at line 1449 of file Containers_T.h.

template<class T, size_t ACE_SIZE>
T ACE_Fixed_Set< T, ACE_SIZE >::item_ [private]
 

Item in the set.

Definition at line 1446 of file Containers_T.h.

template<class T, size_t ACE_SIZE>
size_t ACE_Fixed_Set< T, ACE_SIZE >::max_size_ [private]
 

Maximum size of the set.

Definition at line 1456 of file Containers_T.h.

Referenced by ACE_Fixed_Set< T, ACE_SIZE >::ACE_Fixed_Set(), and ACE_Fixed_Set< T, ACE_SIZE >::operator=().

struct { ... } ACE_Fixed_Set< T, ACE_SIZE >::search_structure_[ACE_SIZE] [private]
 

Holds the contents of the set.

Referenced by ACE_Fixed_Set< T, ACE_SIZE >::ACE_Fixed_Set(), ACE_Fixed_Set< T, ACE_SIZE >::find(), ACE_Fixed_Set< T, ACE_SIZE >::insert(), ACE_Fixed_Set< T, ACE_SIZE >::operator=(), and ACE_Fixed_Set< T, ACE_SIZE >::remove().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:22:20 2006 for ACE by doxygen 1.3.6