Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / ACE / apps / drwho / Hash_Table.cpp
bloba2e666a81df7d17150927a697fb66ab90b1e36f1
1 #include "Options.h"
2 #include "Hash_Table.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_Memory.h"
5 #include "ace/OS_NS_string.h"
7 Hash_Table::Hash_Table ()
8 : current_ptr (0),
9 current_index (0),
10 hash_table_size (HASH_TABLE_SIZE)
12 ACE_NEW (this->hash_table,
13 Protocol_Record *[this->hash_table_size]);
14 ACE_OS::memset (this->hash_table,
16 this->hash_table_size * sizeof *this->hash_table);
19 // Iterate through the hash table returning one node at a time...
21 Protocol_Record *
22 Hash_Table::get_next_entry ()
24 // Reset the iterator if we are starting from the beginning.
26 if (this->current_index == -1)
27 this->current_index = 0;
29 if (this->current_ptr == 0)
31 for (; this->current_index < this->hash_table_size; this->current_index++)
32 if (this->hash_table[this->current_index] != 0)
34 Protocol_Record *prp = this->hash_table[this->current_index++];
35 this->current_ptr = prp->next_;
36 return prp;
39 this->current_index = -1;
40 return 0;
42 else
44 Protocol_Record *prp = this->current_ptr;
45 this->current_ptr = this->current_ptr->next_;
46 return prp;
50 Protocol_Record *
51 Hash_Table::get_each_entry ()
53 return this->get_next_entry ();
56 // Frees up all the dynamic memory in the hash table.
58 Hash_Table::~Hash_Table ()
60 if (Options::get_opt (Options::DEBUGGING))
61 ACE_DEBUG ((LM_DEBUG,
62 "disposing Hash_Table\n"));
64 for (int i = 0; i < this->hash_table_size; i++)
65 for (Protocol_Record *prp = this->hash_table[i];
66 prp != 0; )
68 prp = prp->next_;