summaryrefslogtreecommitdiff
path: root/apps/drwho/Hash_Table.cpp
blob: 51fba821db95af30681e46a5241422166c249eb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// $Id$

#include "Options.h"
#include "Hash_Table.h"
#include "ace/Log_Msg.h"

Hash_Table::Hash_Table (void)
  : current_ptr (0),
    current_index (0),
    hash_table_size (HASH_TABLE_SIZE)
{
  ACE_NEW (this->hash_table,
           Protocol_Record *[this->hash_table_size]);
  ACE_OS::memset (this->hash_table,
                  0,
                  this->hash_table_size * sizeof *this->hash_table);
}

// Iterate through the hash table returning one node at a time...

Protocol_Record *
Hash_Table::get_next_entry (void)
{
  // Reset the iterator if we are starting from the beginning.

  if (this->current_index == -1)
    this->current_index = 0;

  if (this->current_ptr == 0)
    {

      for (;
	   this->current_index < this->hash_table_size;
	   this->current_index++)
	if (this->hash_table[this->current_index] != 0)
	  {
	    Protocol_Record *prp = this->hash_table[this->current_index++];
	    this->current_ptr  = prp->next_;
	    return prp;
	  }

      this->current_index = -1;
      return 0;
    }
  else
    {
      Protocol_Record *prp = this->current_ptr;
      this->current_ptr	 = this->current_ptr->next_;
      return prp;
    }
}

Protocol_Record *
Hash_Table::get_each_entry (void)
{
  return this->get_next_entry ();
}

// Frees up all the dynamic memory in the hash table.

Hash_Table::~Hash_Table (void)
{
  if (Options::get_opt (Options::DEBUG))
    ACE_DEBUG ((LM_DEBUG,
                "disposing Hash_Table\n"));

  for (int i = 0; i < this->hash_table_size; i++)
    for (Protocol_Record *prp = this->hash_table[i];
         prp != 0; )
      {
	prp = prp->next_;
      }
}