summaryrefslogtreecommitdiff
path: root/ace/Cache_Heap_T.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ace/Cache_Heap_T.cpp')
-rw-r--r--ace/Cache_Heap_T.cpp283
1 files changed, 0 insertions, 283 deletions
diff --git a/ace/Cache_Heap_T.cpp b/ace/Cache_Heap_T.cpp
deleted file mode 100644
index bc1f3f4389d..00000000000
--- a/ace/Cache_Heap_T.cpp
+++ /dev/null
@@ -1,283 +0,0 @@
-// $Id$
-
-#ifndef ACE_CACHE_HEAP_T_CPP
-#define ACE_CACHE_HEAP_T_CPP
-
-#include "ace_Cache_Heap_T.h"
-#include "ace_Cache_Manager_T.h"
-
-ACE_RCSID(ace, Cache_Heap_T, "$Id$")
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN>
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::ACE_Cache_Heap (ACE_Allocator *alloc,
- size_t maxsize)
- : allocator_ (alloc),
- maxsize_ (maxsize),
- size_ (0)
-{
- if (this->allocator_ == 0)
- this->allocator_ = ACE_Allocator::instance ();
-
- size_t memsize
- = this->maxsize_ * sizeof (Cache_Heap_Item *);
-
- // @@ James, can you please use the right ACE_* macro here?
- this->heap_ = (Cache_Heap_Item **) this->allocator_->malloc (memsize);
-
- if (this->heap_)
- for (size_t i = 0; i < this->maxsize_; i++)
- this->heap_[i] = 0;
- else
- // should indicate something.
- this->maxsize_ = 0;
-
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN>
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::~ACE_Cache_Heap (void)
-{
- if (this->heap_ != 0)
- {
- for (size_t i = 0; i < this->maxsize_; i++)
- if (this->heap_[i])
- {
- ACE_DES_FREE (this->heap_[i], this->allocator_->free,
- Cache_Heap_Item);
- this->heap_[i] = 0;
- }
- this->allocator_->free (this->heap_);
- this->heap_ = 0;
- }
-
- this->allocator_ = 0;
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> int
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::is_empty (void) const
-{
- return (this->size_ == 0);
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> int
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::is_full (void) const
-{
- return this->size_ == this->maxsize_;
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> size_t
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::size (void) const
-{
- return this->size_;
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> size_t
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::maxsize (void) const
-{
- return this->maxsize_;
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> int
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::maxsize (Cache_Manager *cm,
- size_t new_maxsize)
-{
- int result = -1;
-
- size_t memsize
- = new_maxsize * sizeof (Cache_Heap_Item *);
-
- // @@ JAmes, can you please use the right ACE_*_RETURN macro here?
- Cache_Heap_Item **new_heap
- = (Cache_Heap_Item **) this->allocator_->malloc (memsize);
- if (new_heap)
- {
- while (new_maxsize < this->size_)
- cm->FLUSH_i ();
-
- for (size_t i = 0; i < new_maxsize; i++)
- if (i < this->size_)
- new_heap[i] = this->heap_[i];
- else
- new_heap[i] = 0;
-
- // @@ James, why is this volatile?!
- Cache_Heap_Item ** volatile temp = this->heap_;
- this->heap_ = new_heap;
- this->maxsize_ = new_maxsize;
- this->allocator_->free (temp);
- result = 0;
- }
-
- return result;
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> void
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::insert_i (Cache_Heap_Item *item)
-{
- /* ASSERT: this->size_ < this->maxsize_ */
-
- size_t i;
-
- for (i = this->size_ + 1; i > 1; i /= 2)
- {
- if (item->priority () > this->heap_[i/2 - 1]->priority ())
- break;
-
- this->heap_[i-1] = this->heap_[i/2 - 1];
- this->heap_[i-1]->heap_idx_ = i-1;
- }
-
- this->heap_[i-1] = item;
- this->heap_[i-1]->heap_idx_ = i-1;
- this->size_++;
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> int
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::insert (const EXT_ID &ext_id,
- ACE_Cache_Object *const &int_id)
-{
- if (this->is_full ())
- return -1;
-
- Cache_Heap_Item *item;
- ACE_NEW_MALLOC_RETURN (item,
- (Cache_Heap_Item *)
- this->allocator_->malloc (sizeof (Cache_Heap_Item)),
- Cache_Heap_Item (ext_id,
- int_id),
- -1);
-
- this->insert_i (item);
-
- return 0;
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> void
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::remove_i (void)
-{
- /* ASSERT: this->size_ > 0 */
- this->size_--;
- Cache_Heap_Item *temp = this->heap_[this->size_];
- this->heap_[this->size_] = 0;
-
- size_t i = 1;
- while (2*i <= this->size_)
- {
- size_t child = 2*i;
- if ((child < this->size_)
- && (this->heap_[2*i]->priority ()
- < this->heap_[2*i - 1]->priority ()))
- child = 2*i + 1;
-
- if (temp->priority () < this->heap_[child-1]->priority ())
- break;
-
- this->heap_[i-1] = this->heap_[child-1];
- this->heap_[i-1]->heap_idx_ = i-1;
- i = child;
- }
-
- if (this->size_ > 0)
- {
- this->heap_[i-1] = temp;
- this->heap_[i-1]->heap_idx_ = i-1;
- }
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> void
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::remove_i (size_t pos)
-{
- Cache_Heap_Item *item = this->heap_[pos];
-
- if (pos > 0)
- {
- int i = pos + 1;
- do
- {
- this->heap_[i-1] = this->heap_[i/2 - 1];
- this->heap_[i-1]->heap_idx_ = i-1;
- i /= 2;
- }
- while (i > 1);
- }
-
- this->heap_[0] = item;
- this->remove_i ();
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> int
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::remove (EXT_ID &ext_id,
- ACE_Cache_Object *&int_id)
-{
- if (this->is_empty ())
- return -1;
-
- Cache_Heap_Item *item = this->heap_[0];
-
- this->remove_i ();
-
- ext_id = item->ext_id_;
- int_id = item->int_id_;
-
- ACE_DES_FREE (item,
- this->allocator_->free, Cache_Heap_Item);
- item = 0;
- return 0;
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> int
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::remove (void *item)
-{
- if (item == 0)
- return 0;
-
- // James, please use the right ACE_*_cast() macro here.
- Cache_Heap_Item *real_item = (Cache_Heap_Item *) item;
-
- // Make sure the item is where it thinks it is.
- if (this->heap_[real_item->heap_idx_] != real_item)
- return -1;
-
- this->remove_i (real_item->heap_idx_);
-
- ACE_DES_FREE (real_item, this->allocator_->free, Cache_Heap_Item);
- real_item = 0;
-
- return 0;
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> int
-ACE_Cache_Heap<EXT_ID,FACT,H_FN,E_FN>::adjust (void *item)
-{
- if (item == 0)
- return 0;
-
- // James, please use the right ACE_*_cast() macro here.
- Cache_Heap_Item *real_item = (Cache_Heap_Item *) item;
-
- // Make sure the item is where it thinks it is.
- if (this->heap_[real_item->heap_idx_] != real_item)
- return -1;
-
- this->remove_i (real_item->heap_idx_);
- this->insert_i (real_item);
-
- return 0;
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN>
-ACE_Cache_Heap_Item<EXT_ID,FACT,H_FN,E_FN>::
-ACE_Cache_Heap_Item (const EXT_ID &ext_id, ACE_Cache_Object *const &int_id)
- : ext_id_ (ext_id),
- int_id_ (int_id),
- heap_idx_ (0)
-{
- this->int_id_->heap_item (this);
-}
-
-template <class EXT_ID, class FACT, class H_FN, class E_FN> unsigned int
-ACE_Cache_Heap_Item<EXT_ID,FACT,H_FN,E_FN>::priority (void)
-{
- return this->int_id_->priority ();
-}
-
-#endif /* ACE_CACHE_HEAP_T_CPP */