2 #ifndef JAWS_CACHE_LIST_T_H
3 #define JAWS_CACHE_LIST_T_H
5 #include "ace/Malloc.h"
6 #include "JAWS/Cache_Object.h"
8 // Forward declarations
9 template <class EXT_ID
, class FACTORY
, class HASH_FUNC
, class EQ_FUNC
>
10 class JAWS_Cache_Manager
;
12 template <class EXT_ID
, class FACTORY
, class HASH_FUNC
, class EQ_FUNC
>
13 class JAWS_Cache_List_Item
;
16 template <class EXT_ID
, class FACT
, class H_FN
, class E_FN
>
18 // Roll my own heap here. Eventually, a heap should be its own
19 // standalone data structure.
21 // This version is not a heap, but a doubly linked list. We are
22 // trying to simplify all the heap operations to be O(1).
25 typedef JAWS_Cache_Manager
<EXT_ID
, FACT
, H_FN
, E_FN
> Cache_Manager
;
26 typedef JAWS_Cache_List_Item
<EXT_ID
, FACT
, H_FN
, E_FN
> Cache_List_Item
;
28 JAWS_Cache_List (ACE_Allocator
*alloc
= 0, size_t maxsize
= 8192);
29 // maxsize is the total number of objects the in memory cache is
34 int is_empty () const;
38 size_t maxsize () const;
40 int maxsize (Cache_Manager
*cm
, size_t new_maxsize
);
41 // attempt to grow (or shrink) the heap. Return 0 on success, -1 on
44 int insert (const EXT_ID
&ext_id
, JAWS_Cache_Object
*const &int_id
);
45 // attempt to insert int_id into heap.
47 int remove (EXT_ID
&ext_id
, JAWS_Cache_Object
*&int_id
);
48 // attempt to remove the top element of heap.
50 int remove (void *item
);
51 // treat item as a Cache_List_Item, and remove it from the heap
53 int adjust (void *item
);
54 // treat item as a Cache_List_Item, and alter its heap position
57 void insert_i (Cache_List_Item
*item
);
58 // insert item into heap.
60 void remove_i (Cache_List_Item
*item
);
61 // remove the element residing at pos, but do not delete it.
64 // remove the element residing at the top of heap, but do not delete it.
67 ACE_Allocator
*allocator_
;
72 Cache_List_Item
*item_
;
74 Cache_List_Item
*head_
;
75 Cache_List_Item
*tail_
;
79 template <class EXT_ID
, class FACT
, class H_FN
, class E_FN
>
80 class JAWS_Cache_List_Item
82 friend class JAWS_Cache_List
<EXT_ID
, FACT
, H_FN
, E_FN
>;
85 typedef JAWS_Cache_List
<EXT_ID
, FACT
, H_FN
, E_FN
> Cache_List
;
87 JAWS_Cache_List_Item (const EXT_ID
&ext_id
, JAWS_Cache_Object
*const &int_id
);
88 unsigned int priority ();
92 JAWS_Cache_Object
*int_id_
;
94 JAWS_Cache_List_Item
*next_
;
95 JAWS_Cache_List_Item
*prev_
;
98 #include "JAWS/Cache_List_T.cpp"
100 #endif /* JAWS_CACHE_LIST_T_H */