summaryrefslogtreecommitdiff
path: root/ace/Hash_Map_Manager.cpp
diff options
context:
space:
mode:
authorjxh <jxh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-08-06 21:37:37 +0000
committerjxh <jxh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-08-06 21:37:37 +0000
commitd8b56f44f20368bd68272dddb332949d033db96e (patch)
treea48e6d967addeafd104635ca29fa5e3b8d69b6df /ace/Hash_Map_Manager.cpp
parent53b86a285573093a38b7e91ce4ee73e61439eb58 (diff)
downloadATCD-d8b56f44f20368bd68272dddb332949d033db96e.tar.gz
Changed implementation back to use a single sentinel_ rather than
an array of them.
Diffstat (limited to 'ace/Hash_Map_Manager.cpp')
-rw-r--r--ace/Hash_Map_Manager.cpp66
1 files changed, 29 insertions, 37 deletions
diff --git a/ace/Hash_Map_Manager.cpp b/ace/Hash_Map_Manager.cpp
index 67df5f63294..de1585b66d2 100644
--- a/ace/Hash_Map_Manager.cpp
+++ b/ace/Hash_Map_Manager.cpp
@@ -71,21 +71,23 @@ ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::resize_i (size_t size)
this->table_ = (ACE_Hash_Map_Entry<EXT_ID, INT_ID> **) ptr;
- this->sentinel_ = (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *) this->allocator_->malloc (sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>));
-
- if (this->sentinel_ == 0)
+ ptr = this->allocator_->malloc (sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>));
+ if (ptr == 0)
{
this->allocator_->free (this->table_);
+ this->table_ = 0;
errno = ENOMEM;
return -1;
}
- else
- new (this->sentinel_) ACE_Hash_Map_Entry<EXT_ID, INT_ID>;
+
+ this->sentinel_ = (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *) ptr;
+ new (this->sentinel_) ACE_Hash_Map_Entry<EXT_ID, INT_ID>;
// This isn't strictly necessary, but we'll do it to make life
// easier.
this->sentinel_->next_ = this->sentinel_;
+
this->total_size_ = size;
// Initialize the hash table to point to the sentinel node.
@@ -163,6 +165,8 @@ ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::close_i (void)
this->allocator_->free (this->table_);
this->table_ = 0;
+
+ this->sentinel_->ext_id_ = sentinel_ext_id_fakenull_;
this->allocator_->free (this->sentinel_);
this->sentinel_ = 0;
}
@@ -339,6 +343,7 @@ ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::unbind (const EXT_ID &ext_id)
template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::shared_find (const EXT_ID &ext_id,
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry,
+ ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&prev,
u_long &loc)
{
loc = this->hash (ext_id) % this->total_size_;
@@ -348,7 +353,7 @@ ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::shared_find (const EXT_ID &ext_id,
for (this->sentinel_->ext_id_ = ext_id;
this->equal (temp->ext_id_, ext_id) == 0;
temp = temp->next_)
- continue;
+ prev = temp;
this->sentinel_->ext_id_ = sentinel_ext_id_fakenull_;
@@ -367,30 +372,10 @@ ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::shared_find (const EXT_ID &ext_id,
template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::shared_find (const EXT_ID &ext_id,
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry,
- ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&prev,
u_long &loc)
{
- loc = this->hash (ext_id) % this->total_size_;
-
- ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp = this->table_[loc];
-
- for (this->sentinel_->ext_id_ = ext_id;
- this->equal (temp->ext_id_, ext_id) == 0;
- temp = temp->next_)
- prev = temp;
-
- this->sentinel_->ext_id_ = sentinel_ext_id_fakenull_;
-
- if (temp != this->sentinel_)
- {
- entry = temp;
- return 0;
- }
- else
- {
- errno = ENOENT;
- return -1;
- }
+ ACE_Hash_Map_Entry<EXT_ID, INT_ID> *prev;
+ return this->shared_find (ext_id, entry, prev, loc);
}
template <class EXT_ID, class INT_ID, class LOCK> int
@@ -483,11 +468,14 @@ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, LOCK>::ACE_Hash_Map_Iterator (ACE_Hash_Map
next_ (this->map_man_.sentinel_)
{
if (this->map_man_.table_ != 0)
- this->advance ();
+ {
+ this->next_ = this->map_man_.table_[0];
+ this->advance ();
+ }
}
template <class EXT_ID, class INT_ID, class LOCK> int
-ACE_Hash_Map_Iterator<EXT_ID, INT_ID, LOCK>::next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&mm)
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, LOCK>::next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry)
{
ACE_READ_GUARD_RETURN (LOCK, ace_mon, this->map_man_.lock_, -1);
@@ -495,7 +483,7 @@ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, LOCK>::next (ACE_Hash_Map_Entry<EXT_ID, IN
&& this->index_ < this->map_man_.total_size_
&& this->next_ != this->map_man_.sentinel_)
{
- mm = this->next_;
+ entry = this->next_;
return 1;
}
else
@@ -520,15 +508,19 @@ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, LOCK>::advance (void)
{
ACE_READ_GUARD_RETURN (LOCK, ace_mon, this->map_man_.lock_, -1);
+ if (this->map_man_.table_ == 0)
+ return -1;
+
if (this->next_->next_ != this->map_man_.sentinel_)
this->next_ = this->next_->next_;
else
- while (this->index_++ < this->map_man_.total_size_)
- if (this->map_man_.table_[this->index_ - 1] != this->map_man_.sentinel_)
- {
- this->next_ = this->map_man_.table_[this->index_ - 1];
- break;
- }
+ while (++this->index_ < this->map_man_.total_size_)
+ if (this->map_man_.table_[this->index_]
+ != this->map_man_.sentinel_)
+ {
+ this->next_ = this->map_man_.table_[this->index_];
+ break;
+ }
return this->index_ < this->map_man_.total_size_
&& this->next_ != this->map_man_.sentinel_;