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_
 Item in the set.
   int   is_free_
 Keeps track of whether this item is in use or not.
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 1353 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 1362 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 1361 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 955 of file Containers_T.cpp.

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

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

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 929 of file Containers_T.cpp.

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

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

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

Destructor.

Destroys a set.

Definition at line 922 of file Containers_T.cpp.

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

00923 {
00924   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::~ACE_Fixed_Set");
00925   this->cur_size_ = 0;
00926 }


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 914 of file Containers_T.cpp.

References ACE_TRACE.

00915 {
00916 #if defined (ACE_HAS_DUMP)
00917   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::dump");
00918 #endif /* ACE_HAS_DUMP */
00919 }

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 965 of file Containers_T.cpp.

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

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

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 981 of file Containers_T.cpp.

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

Referenced by ACE_Sig_Handlers::handler().

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

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, and ACE_Fixed_Set< T, ACE_SIZE >::cur_size_.

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, ACE_Fixed_Set< T, ACE_SIZE >::cur_size_, and ACE_Fixed_Set< T, ACE_SIZE >::max_size_.

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 940 of file Containers_T.cpp.

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

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

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 1018 of file Containers_T.cpp.

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

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

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

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 907 of file Containers_T.cpp.

References ACE_TRACE.

Referenced by ACE_Sig_Handlers::remove_handler().

00908 {
00909   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::size");
00910   return this->cur_size_;
00911 }


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 1358 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 1357 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 1356 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 1437 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 1451 of file Containers_T.h.

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

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 1447 of file Containers_T.h.

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

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

Item in the set.

Definition at line 1444 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 1454 of file Containers_T.h.

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 >::is_full(), ACE_Fixed_Set< T, ACE_SIZE >::operator=(), and ACE_Fixed_Set< T, ACE_SIZE >::remove().

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(), and ACE_Fixed_Set< T, ACE_SIZE >::operator=().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:08 2010 for ACE by  doxygen 1.4.7