summaryrefslogtreecommitdiff
path: root/ace/Hash_Map_Manager.cpp
diff options
context:
space:
mode:
authorjxh <jxh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-31 01:01:08 +0000
committerjxh <jxh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-31 01:01:08 +0000
commit3ff7e0e7be55f33e0d2fb36d9114b4e1831ab4c5 (patch)
tree65317464ad2eb9aef307742284b94023b1836007 /ace/Hash_Map_Manager.cpp
parent1e0be1b93b4d0717e1ab6334cbdb1521fa5f6b0b (diff)
downloadATCD-3ff7e0e7be55f33e0d2fb36d9114b4e1831ab4c5.tar.gz
Made all the _i find methods use shared_find, to ease template
specilization efforts.
Diffstat (limited to 'ace/Hash_Map_Manager.cpp')
-rw-r--r--ace/Hash_Map_Manager.cpp95
1 files changed, 55 insertions, 40 deletions
diff --git a/ace/Hash_Map_Manager.cpp b/ace/Hash_Map_Manager.cpp
index d30a9b39b32..67df5f63294 100644
--- a/ace/Hash_Map_Manager.cpp
+++ b/ace/Hash_Map_Manager.cpp
@@ -164,6 +164,7 @@ ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::close_i (void)
this->allocator_->free (this->table_);
this->table_ = 0;
this->allocator_->free (this->sentinel_);
+ this->sentinel_ = 0;
}
return 0;
}
@@ -211,23 +212,17 @@ template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::bind_i (const EXT_ID &ext_id,
const INT_ID &int_id)
{
- u_long loc = this->hash (ext_id) % this->total_size_;
+ ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp;
- 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_)
- continue;
-
- this->sentinel_->ext_id_ = sentinel_ext_id_fakenull_;
+ u_long loc;
+ int result = this->shared_find (ext_id, temp, loc);
- if (temp == this->sentinel_)
+ if (result == -1)
{
void *ptr;
// Not found.
ACE_ALLOCATOR_RETURN (ptr,
- this->allocator_->malloc (sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>) ),
+ this->allocator_->malloc (sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>)),
-1);
this->table_[loc] =
@@ -253,24 +248,17 @@ template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::trybind_i (const EXT_ID &ext_id,
INT_ID &int_id)
{
- u_long loc = this->hash (ext_id) % this->total_size_;
-
- ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp = this->table_[loc];
+ ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp;
- for (this->sentinel_->ext_id_ = ext_id;
- this->equal (temp->ext_id_, ext_id) == 0;
- temp = temp->next_)
- continue;
+ u_long loc;
+ int result = this->shared_find (ext_id, temp, loc);
- this->sentinel_->ext_id_ = sentinel_ext_id_fakenull_;
-
- if (temp == this->sentinel_)
+ if (result == -1)
{
// Not found.
void *ptr;
- // Not found.
ACE_ALLOCATOR_RETURN (ptr,
- this->allocator_->malloc (sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>) ),
+ this->allocator_->malloc (sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>)),
-1);
this->table_[loc] =
@@ -299,19 +287,13 @@ template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::unbind_i (const EXT_ID &ext_id,
INT_ID &int_id)
{
- u_long loc = this->hash (ext_id) % this->total_size_;
-
- ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp = this->table_[loc];
+ ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp;
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *prev = 0;
- 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_;
+ u_long loc;
+ int result = this->shared_find (ext_id, temp, prev, loc);
- if (temp == this->sentinel_)
+ if (result == -1)
{
errno = ENOENT;
return -1;
@@ -356,9 +338,10 @@ 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> *&entry,
+ u_long &loc)
{
- u_long loc = this->hash (ext_id) % this->total_size_;
+ loc = this->hash (ext_id) % this->total_size_;
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp = this->table_[loc];
@@ -382,12 +365,42 @@ 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;
+ }
+}
+
+template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::find_i (const EXT_ID &ext_id,
INT_ID &int_id)
{
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *entry;
-
- if (this->shared_find (ext_id, entry) == -1)
+
+ u_long dummy;
+ if (this->shared_find (ext_id, entry, dummy) == -1)
return -1;
else
{
@@ -400,8 +413,9 @@ template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::find_i (const EXT_ID &ext_id)
{
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *entry;
-
- return this->shared_find (ext_id, entry);
+
+ u_long dummy;
+ return this->shared_find (ext_id, entry, dummy);
}
template <class EXT_ID, class INT_ID, class LOCK> int
@@ -429,7 +443,8 @@ ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::rebind_i (const EXT_ID &ext_id,
{
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *node;
- if (this->shared_find (ext_id, node) == -1)
+ u_long dummy;
+ if (this->shared_find (ext_id, node, dummy) == -1)
return this->bind_i (ext_id, int_id);
else
{