1 #ifndef JAWS_HASH_BUCKET_T_CPP
2 #define JAWS_HASH_BUCKET_T_CPP
4 #include "JAWS/Hash_Bucket_T.h"
10 template <class EXT_ID
, class INT_ID
>
11 JAWS_Hash_Bucket_Item
<EXT_ID
, INT_ID
>
12 ::JAWS_Hash_Bucket_Item (const EXT_ID
&ext_id
, const INT_ID
&int_id
,
13 JAWS_Hash_Bucket_Item
<EXT_ID
, INT_ID
> *next
,
14 JAWS_Hash_Bucket_Item
<EXT_ID
, INT_ID
> *prev
)
22 template <class EXT_ID
, class INT_ID
>
23 JAWS_Hash_Bucket_Item
<EXT_ID
, INT_ID
>
24 ::JAWS_Hash_Bucket_Item (JAWS_Hash_Bucket_Item
<EXT_ID
, INT_ID
> *next
,
25 JAWS_Hash_Bucket_Item
<EXT_ID
, INT_ID
> *prev
)
31 template <class EXT_ID
, class INT_ID
>
32 JAWS_Hash_Bucket_Item
<EXT_ID
, INT_ID
>::~JAWS_Hash_Bucket_Item ()
39 // ---------------------
40 // Hash_Bucket_DLCStack
41 // ---------------------
43 template <class EXT_ID
, class INT_ID
>
44 JAWS_Hash_Bucket_DLCStack
<EXT_ID
, INT_ID
>::
45 JAWS_Hash_Bucket_DLCStack (ACE_Allocator
*alloc
)
50 if (this->allocator_
== 0)
51 this->allocator_
= ACE_Allocator::instance ();
54 template <class EXT_ID
, class INT_ID
>
55 JAWS_Hash_Bucket_DLCStack
<EXT_ID
, INT_ID
>::
56 ~JAWS_Hash_Bucket_DLCStack ()
61 template <class EXT_ID
, class INT_ID
> int
62 JAWS_Hash_Bucket_DLCStack
<EXT_ID
, INT_ID
>::
65 return this->head_
== 0 && this->tail_
== 0;
68 template <class EXT_ID
, class INT_ID
> JAWS_HASH_BUCKET_ITEM
*
69 JAWS_Hash_Bucket_DLCStack
<EXT_ID
, INT_ID
>::
70 push (const EXT_ID
&ext_id
, const INT_ID
&int_id
)
72 size_t malloc_size
= sizeof (JAWS_HASH_BUCKET_ITEM
);
73 JAWS_HASH_BUCKET_ITEM
*item
;
74 ACE_NEW_MALLOC_RETURN (item
,
75 (JAWS_HASH_BUCKET_ITEM
*)
76 this->allocator_
->malloc (malloc_size
),
77 JAWS_HASH_BUCKET_ITEM (ext_id
, int_id
), 0);
81 if (this->is_empty ())
85 item
->next_
= this->head_
;
86 item
->prev_
= this->tail_
;
90 item
->next_
= this->head_
;
91 item
->prev_
= this->tail_
;
92 this->head_
->prev_
= item
;
93 this->tail_
->next_
= item
;
101 template <class EXT_ID
, class INT_ID
> JAWS_HASH_BUCKET_ITEM
*
102 JAWS_Hash_Bucket_DLCStack
<EXT_ID
, INT_ID
>::pop ()
104 JAWS_HASH_BUCKET_ITEM
*item
= 0;
106 if (! this->is_empty ())
109 if (this->head_
== this->tail_
)
111 this->head_
= this->tail_
= 0;
115 this->head_
= this->head_
->next_
;
116 this->head_
->prev_
= this->tail_
;
117 this->tail_
->next_
= this->head_
;
126 template <class EXT_ID
, class INT_ID
> void
127 JAWS_Hash_Bucket_DLCStack
<EXT_ID
, INT_ID
>::reset ()
129 JAWS_HASH_BUCKET_ITEM
*item
= 0;
131 while ((item
= this->pop ()) != 0)
135 template <class EXT_ID
, class INT_ID
> int
136 JAWS_Hash_Bucket_DLCStack
<EXT_ID
, INT_ID
>::remove (JAWS_HASH_BUCKET_ITEM
*item
)
142 if (item
->next_
!= 0 && item
->prev_
!= 0)
144 if (item
->next_
!= item
)
146 if (this->head_
== item
)
147 this->head_
= item
->next_
;
148 if (this->tail_
== item
)
149 this->tail_
= item
->prev_
;
150 item
->next_
->prev_
= item
->prev_
;
151 item
->prev_
->next_
= item
->next_
;
155 this->head_
= this->tail_
= 0;
161 if (item
->next_
== 0 && item
->prev_
== 0)
163 ACE_DES_FREE_TEMPLATE2 (item
, this->allocator_
->free
,
164 JAWS_Hash_Bucket_Item
, EXT_ID
, INT_ID
);
174 // ------------------------------
175 // Hash_Bucket_DLCStack_Iterator
176 // ------------------------------
178 template <class EXT_ID
, class INT_ID
>
179 JAWS_Hash_Bucket_DLCStack_Iterator
<EXT_ID
, INT_ID
>::
180 JAWS_Hash_Bucket_DLCStack_Iterator (const JAWS_HASH_BUCKET_DLCSTACK
&dlcstack
)
181 : dlcstack_ (dlcstack
),
188 template <class EXT_ID
, class INT_ID
> int
189 JAWS_Hash_Bucket_DLCStack_Iterator
<EXT_ID
, INT_ID
>::first ()
193 if (! this->dlcstack_
.is_empty ())
196 this->next_
= this->dlcstack_
.head_
;
197 this->prev_
= this->dlcstack_
.tail_
;
204 template <class EXT_ID
, class INT_ID
> int
205 JAWS_Hash_Bucket_DLCStack_Iterator
<EXT_ID
, INT_ID
>::last ()
207 return this->first ();
210 template <class EXT_ID
, class INT_ID
> int
211 JAWS_Hash_Bucket_DLCStack_Iterator
<EXT_ID
, INT_ID
>::advance ()
215 if (this->next_
!= 0)
217 this->prev_
= this->next_
;
218 this->next_
= this->next_
->next_
;
219 if (this->next_
== this->dlcstack_
.head_
)
226 result
= this->first ();
231 template <class EXT_ID
, class INT_ID
> int
232 JAWS_Hash_Bucket_DLCStack_Iterator
<EXT_ID
, INT_ID
>::revert ()
236 if (this->prev_
!= 0)
238 this->next_
= this->prev_
;
239 this->prev_
= this->prev_
->prev_
;
240 if (this->prev_
== this->dlcstack_
.tail_
)
247 result
= this->last ();
252 template <class EXT_ID
, class INT_ID
> int
253 JAWS_Hash_Bucket_DLCStack_Iterator
<EXT_ID
, INT_ID
>::
254 next (JAWS_HASH_BUCKET_ITEM
*&item
)
256 if (this->next_
== 0)
260 return ! this->done ();
263 template <class EXT_ID
, class INT_ID
> int
264 JAWS_Hash_Bucket_DLCStack_Iterator
<EXT_ID
, INT_ID
>::
265 next (JAWS_HASH_BUCKET_ITEM
*&item
) const
268 return ! this->done ();
271 template <class EXT_ID
, class INT_ID
> int
272 JAWS_Hash_Bucket_DLCStack_Iterator
<EXT_ID
, INT_ID
>::
273 prev (JAWS_HASH_BUCKET_ITEM
*&item
)
275 if (this->prev_
== 0)
279 return ! this->done ();
282 template <class EXT_ID
, class INT_ID
> int
283 JAWS_Hash_Bucket_DLCStack_Iterator
<EXT_ID
, INT_ID
>::
284 prev (JAWS_HASH_BUCKET_ITEM
*&item
) const
287 return ! this->done ();
290 template <class EXT_ID
, class INT_ID
> int
291 JAWS_Hash_Bucket_DLCStack_Iterator
<EXT_ID
, INT_ID
>::done () const
297 // --------------------
298 // Hash_Bucket_Manager
299 // --------------------
301 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
>
302 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>
303 ::JAWS_Hash_Bucket_Manager (ACE_Allocator
*alloc
)
307 this->dlcstack_
.allocator_
= ACE_Allocator::instance ();
310 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
> int
311 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>::open (ACE_Allocator
*alloc
)
313 this->dlcstack_
.allocator_
= alloc
;
315 this->dlcstack_
.allocator_
= ACE_Allocator::instance ();
320 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
>
321 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>::~JAWS_Hash_Bucket_Manager ()
325 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
> int
326 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>::close ()
328 this->dlcstack_
.reset ();
332 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
> JAWS_HASH_BUCKET_ITEM
*
333 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>
334 ::find_i (const EXT_ID
&ext_id
) const
336 JAWS_HASH_BUCKET_DLCSTACK_ITERATOR
iter (this->dlcstack_
);
337 JAWS_HASH_BUCKET_ITEM
*item
= 0;
340 while (!iter
.done ())
343 if (item
&& EQ_FUNC (item
->ext_id_
, ext_id
))
348 return (item
&& EQ_FUNC (item
->ext_id_
, ext_id
)) ? item
: 0;
351 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
> int
352 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>::find (const EXT_ID
&ext_id
,
353 INT_ID
&int_id
) const
356 JAWS_HASH_BUCKET_ITEM
*item
= this->find_i (ext_id
);
360 int_id
= item
->int_id_
;
367 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
> int
368 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>
369 ::find (const EXT_ID
&ext_id
) const
372 return this->find (ext_id
, dummy_id
);
375 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
> int
376 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>::bind (const EXT_ID
&ext_id
,
377 const INT_ID
&int_id
)
381 if (this->find (ext_id
) == 0)
387 if (this->dlcstack_
.push (ext_id
, int_id
) == 0)
394 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
> int
395 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>::trybind (const EXT_ID
&ext_id
,
400 if (this->find (ext_id
, int_id
) == 0)
406 if (this->dlcstack_
.push (ext_id
, int_id
) == 0)
413 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
> int
414 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>::rebind (const EXT_ID
&ext_id
,
415 const INT_ID
&int_id
,
420 JAWS_HASH_BUCKET_ITEM
*item
= this->find_i (ext_id
);
425 old_ext_id
= item
->ext_id_
;
426 old_int_id
= item
->int_id_
;
427 this->dlcstack_
.remove (item
);
430 if (this->dlcstack_
.push (ext_id
, int_id
) == 0)
436 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
> int
437 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>::unbind (const EXT_ID
&ext_id
,
441 JAWS_HASH_BUCKET_ITEM
*item
= this->find_i (ext_id
);
446 int_id
= item
->int_id_
;
447 this->dlcstack_
.remove (item
);
453 template <class EXT_ID
, class INT_ID
, class EQ_FUNC
> int
454 JAWS_Hash_Bucket_Manager
<EXT_ID
,INT_ID
,EQ_FUNC
>::unbind (const EXT_ID
&ext_id
)
457 return this->unbind (ext_id
, dummy_id
);
460 #endif /* JAWS_HASH_BUCKET_T_CPP */