PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/dep/acelite/ace/Hash_Multi_Map_Manager_T.cpp

https://github.com/chucho/FaceCore
C++ | 603 lines | 464 code | 99 blank | 40 comment | 89 complexity | d875cb164ffe69e9befce1f0b7cffcc2 MD5 | raw file
  1. //=============================================================================
  2. /**
  3. * @file Hash_Multi_Map_Manager_T.cpp
  4. *
  5. * $Id: Hash_Multi_Map_Manager_T.cpp 91688 2010-09-09 11:21:50Z johnnyw $
  6. *
  7. * @author Shanshan Jiang <shanshan.jiang@vanderbilt.edu>
  8. */
  9. //=============================================================================
  10. #ifndef ACE_Hash_Multi_Map_Manager_T_CPP
  11. #define ACE_Hash_Multi_Map_Manager_T_CPP
  12. #include "ace/Hash_Multi_Map_Manager_T.h"
  13. #if !defined (ACE_LACKS_PRAGMA_ONCE)
  14. # pragma once
  15. #endif /* ACE_LACKS_PRAGMA_ONCE */
  16. #if !defined (__ACE_INLINE__)
  17. # include "ace/Hash_Multi_Map_Manager_T.inl"
  18. #endif /* __ACE_INLINE__ */
  19. #include "ace/Malloc_Base.h"
  20. ACE_BEGIN_VERSIONED_NAMESPACE_DECL
  21. template <class EXT_ID, class INT_ID>
  22. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID>::ACE_Hash_Multi_Map_Entry (ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *next,
  23. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *prev)
  24. : next_ (next),
  25. prev_ (prev)
  26. {
  27. }
  28. template <class EXT_ID, class INT_ID>
  29. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID>::ACE_Hash_Multi_Map_Entry (const EXT_ID &ext_id,
  30. const ACE_Unbounded_Set<INT_ID> &int_id_set,
  31. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *next,
  32. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *prev)
  33. : ext_id_ (ext_id),
  34. int_id_set_ (int_id_set),
  35. next_ (next),
  36. prev_ (prev)
  37. {
  38. }
  39. template <class EXT_ID, class INT_ID>
  40. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID>::~ACE_Hash_Multi_Map_Entry (void)
  41. {
  42. }
  43. template <class EXT_ID, class INT_ID> EXT_ID &
  44. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID>::key ()
  45. {
  46. return ext_id_;
  47. }
  48. template <class EXT_ID, class INT_ID> ACE_Unbounded_Set<INT_ID> &
  49. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID>::item ()
  50. {
  51. return int_id_set_;
  52. }
  53. template <class EXT_ID, class INT_ID> void
  54. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID>::dump (void) const
  55. {
  56. #if defined (ACE_HAS_DUMP)
  57. ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
  58. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("next_ = %d"), this->next_));
  59. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("prev_ = %d"), this->prev_));
  60. ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
  61. #endif /* ACE_HAS_DUMP */
  62. }
  63. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> void
  64. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::dump (void) const
  65. {
  66. #if defined (ACE_HAS_DUMP)
  67. ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
  68. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("total_size_ = %d"), this->total_size_));
  69. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ncur_size_ = %d"), this->cur_size_));
  70. this->table_allocator_->dump ();
  71. this->entry_allocator_->dump ();
  72. this->lock_.dump ();
  73. ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
  74. #endif /* ACE_HAS_DUMP */
  75. }
  76. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  77. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::create_buckets (size_t size)
  78. {
  79. size_t bytes = size * sizeof (ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID>);
  80. void *ptr;
  81. ACE_ALLOCATOR_RETURN (ptr,
  82. this->table_allocator_->malloc (bytes),
  83. -1);
  84. this->table_ = (ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *) ptr;
  85. this->total_size_ = size;
  86. // Initialize each entry in the hash table to be a circular linked
  87. // list with the dummy node in the front serving as the anchor of
  88. // the list.
  89. for (size_t i = 0; i < size; i++)
  90. new (&this->table_[i]) ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> (&this->table_[i],
  91. &this->table_[i]);
  92. return 0;
  93. }
  94. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  95. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::open (size_t size,
  96. ACE_Allocator *table_alloc,
  97. ACE_Allocator *entry_alloc)
  98. {
  99. ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
  100. // Calling this->close_i () to ensure we release previous allocated
  101. // memory before allocating new one.
  102. this->close_i ();
  103. if (table_alloc == 0)
  104. table_alloc = ACE_Allocator::instance ();
  105. this->table_allocator_ = table_alloc;
  106. if (entry_alloc == 0)
  107. entry_alloc = table_alloc;
  108. this->entry_allocator_ = entry_alloc;
  109. // This assertion is here to help track a situation that shouldn't
  110. // happen, but did with Sun C++ 4.1 (before a change to this class
  111. // was made: it used to have an enum that was supposed to be defined
  112. // to be ACE_DEFAULT_MAP_SIZE, but instead was defined to be 0).
  113. if (size == 0)
  114. return -1;
  115. return this->create_buckets (size);
  116. }
  117. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  118. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::close_i (void)
  119. {
  120. // Protect against "double-deletion" in case the destructor also
  121. // gets called.
  122. if (this->table_ != 0)
  123. {
  124. // Remove all the entries.
  125. this->unbind_all_i ();
  126. // Iterate through the buckets cleaning up the sentinels.
  127. for (size_t i = 0; i < this->total_size_; i++)
  128. {
  129. // Destroy the dummy entry.
  130. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *entry = &this->table_[i];
  131. // The second argument results in a no-op instead of
  132. // deallocation.
  133. ACE_DES_FREE_TEMPLATE2 (entry, ACE_NOOP,
  134. ACE_Hash_Multi_Map_Entry, EXT_ID, INT_ID);
  135. }
  136. // Reset size.
  137. this->total_size_ = 0;
  138. // Free table memory.
  139. this->table_allocator_->free (this->table_);
  140. // Should be done last...
  141. this->table_ = 0;
  142. }
  143. return 0;
  144. }
  145. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  146. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::unbind_all_i (void)
  147. {
  148. // Iterate through the entire map calling the destuctor of each
  149. // <ACE_Hash_Multi_Map_Entry>.
  150. for (size_t i = 0; i < this->total_size_; i++)
  151. {
  152. for (ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *temp_ptr = this->table_[i].next_;
  153. temp_ptr != &this->table_[i];
  154. )
  155. {
  156. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *hold_ptr = temp_ptr;
  157. temp_ptr = temp_ptr->next_;
  158. // Explicitly call the destructor.
  159. ACE_DES_FREE_TEMPLATE2 (hold_ptr, this->entry_allocator_->free,
  160. ACE_Hash_Multi_Map_Entry, EXT_ID, INT_ID);
  161. }
  162. // Restore the sentinel.
  163. this->table_[i].next_ = &this->table_[i];
  164. this->table_[i].prev_ = &this->table_[i];
  165. }
  166. this->cur_size_ = 0;
  167. return 0;
  168. }
  169. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  170. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::bind_i (const EXT_ID &ext_id,
  171. const INT_ID &int_id,
  172. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *&entry)
  173. {
  174. size_t loc;
  175. int result = this->shared_find (ext_id, entry, loc);
  176. ACE_Unbounded_Set<INT_ID> int_id_set;
  177. if (result == -1)
  178. {
  179. void *ptr;
  180. // Not found.
  181. ACE_ALLOCATOR_RETURN (ptr,
  182. this->entry_allocator_->malloc (sizeof (ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID>)),
  183. -1);
  184. int_id_set.insert (int_id);
  185. entry = new (ptr) ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> (ext_id,
  186. int_id_set,
  187. this->table_[loc].next_,
  188. &this->table_[loc]);
  189. this->table_[loc].next_ = entry;
  190. entry->next_->prev_ = entry;
  191. this->cur_size_++;
  192. return 0;
  193. }
  194. else
  195. {
  196. int_id_set = (*entry).int_id_set_;
  197. if (0 == int_id_set.insert (int_id))
  198. {
  199. this->unbind_i (entry);
  200. return this->bind_i (ext_id, int_id_set);
  201. }
  202. else
  203. return 1;
  204. }
  205. }
  206. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  207. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::bind_i (const EXT_ID &ext_id,
  208. const ACE_Unbounded_Set<INT_ID> &int_id_set,
  209. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *&entry)
  210. {
  211. size_t loc;
  212. int result = this->shared_find (ext_id, entry, loc);
  213. if (result == -1)
  214. {
  215. void *ptr;
  216. // Not found.
  217. ACE_ALLOCATOR_RETURN (ptr,
  218. this->entry_allocator_->malloc (sizeof (ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID>)),
  219. -1);
  220. entry = new (ptr) ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> (ext_id,
  221. int_id_set,
  222. this->table_[loc].next_,
  223. &this->table_[loc]);
  224. this->table_[loc].next_ = entry;
  225. entry->next_->prev_ = entry;
  226. this->cur_size_++;
  227. return 0;
  228. }
  229. else
  230. return 1;
  231. }
  232. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  233. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::trybind_i (const EXT_ID &ext_id,
  234. ACE_Unbounded_Set<INT_ID> &int_id_set,
  235. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *&entry)
  236. {
  237. size_t loc;
  238. int result = this->shared_find (ext_id, entry, loc);
  239. if (result == -1)
  240. {
  241. // Not found.
  242. void *ptr;
  243. ACE_ALLOCATOR_RETURN (ptr,
  244. this->entry_allocator_->malloc (sizeof (ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID>)),
  245. -1);
  246. entry = new (ptr) ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> (ext_id,
  247. int_id_set,
  248. this->table_[loc].next_,
  249. &this->table_[loc]);
  250. this->table_[loc].next_ = entry;
  251. entry->next_->prev_ = entry;
  252. this->cur_size_++;
  253. return 0;
  254. }
  255. else
  256. return 1;
  257. }
  258. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  259. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::unbind_i (const EXT_ID &ext_id,
  260. ACE_Unbounded_Set<INT_ID> &int_id_set)
  261. {
  262. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *temp;
  263. size_t loc;
  264. int result = this->shared_find (ext_id, temp, loc);
  265. if (result == -1)
  266. {
  267. errno = ENOENT;
  268. return -1;
  269. }
  270. int_id_set = temp->int_id_set_;
  271. return this->unbind_i (temp);
  272. }
  273. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  274. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::unbind_i (ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *entry)
  275. {
  276. entry->next_->prev_ = entry->prev_;
  277. entry->prev_->next_ = entry->next_;
  278. // Explicitly call the destructor.
  279. ACE_DES_FREE_TEMPLATE2 (entry, this->entry_allocator_->free,
  280. ACE_Hash_Multi_Map_Entry, EXT_ID, INT_ID);
  281. this->cur_size_--;
  282. return 0;
  283. }
  284. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  285. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::unbind_i (const EXT_ID &ext_id,
  286. const INT_ID &int_id)
  287. {
  288. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *temp;
  289. size_t loc;
  290. int result = this->shared_find (ext_id, temp, loc);
  291. if (result == -1)
  292. {
  293. errno = ENOENT;
  294. return -1;
  295. }
  296. ACE_Unbounded_Set<INT_ID> int_id_set = (*temp).int_id_set_;
  297. if (0 == int_id_set.remove (int_id))
  298. {
  299. this->unbind_i (temp);
  300. if (0 != int_id_set.size ())
  301. return this->bind_i (ext_id, int_id_set);
  302. else
  303. return 0;
  304. }
  305. else
  306. return -1;
  307. }
  308. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  309. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::shared_find (const EXT_ID &ext_id,
  310. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *&entry,
  311. size_t &loc)
  312. {
  313. loc = this->hash (ext_id) % this->total_size_;
  314. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *temp = this->table_[loc].next_;
  315. while (temp != &this->table_[loc] && this->equal (temp->ext_id_, ext_id) == 0)
  316. temp = temp->next_;
  317. if (temp == &this->table_[loc])
  318. {
  319. errno = ENOENT;
  320. return -1;
  321. }
  322. else
  323. {
  324. entry = temp;
  325. return 0;
  326. }
  327. }
  328. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  329. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::rebind_i (const EXT_ID &ext_id,
  330. const ACE_Unbounded_Set<INT_ID> &int_id_set,
  331. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *&entry)
  332. {
  333. size_t dummy;
  334. if (this->shared_find (ext_id, entry, dummy) == -1)
  335. return this->bind_i (ext_id, int_id_set);
  336. else
  337. {
  338. entry->ext_id_ = ext_id;
  339. entry->int_id_set_ = int_id_set;
  340. return 1;
  341. }
  342. }
  343. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  344. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::rebind_i (const EXT_ID &ext_id,
  345. const ACE_Unbounded_Set<INT_ID> &int_id_set,
  346. ACE_Unbounded_Set<INT_ID> &old_int_id_set,
  347. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *&entry)
  348. {
  349. size_t dummy;
  350. if (this->shared_find (ext_id, entry, dummy) == -1)
  351. return this->bind_i (ext_id, int_id_set);
  352. else
  353. {
  354. old_int_id_set = entry->int_id_set_;
  355. entry->ext_id_ = ext_id;
  356. entry->int_id_set_ = int_id_set;
  357. return 1;
  358. }
  359. }
  360. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  361. ACE_Hash_Multi_Map_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::rebind_i (const EXT_ID &ext_id,
  362. const ACE_Unbounded_Set<INT_ID> &int_id_set,
  363. EXT_ID &old_ext_id,
  364. ACE_Unbounded_Set<INT_ID> &old_int_id_set,
  365. ACE_Hash_Multi_Map_Entry<EXT_ID, INT_ID> *&entry)
  366. {
  367. size_t dummy;
  368. if (this->shared_find (ext_id, entry, dummy) == -1)
  369. return this->bind_i (ext_id, int_id_set);
  370. else
  371. {
  372. old_ext_id = entry->ext_id_;
  373. old_int_id_set = entry->int_id_set_;
  374. entry->ext_id_ = ext_id;
  375. entry->int_id_set_ = int_id_set;
  376. return 1;
  377. }
  378. }
  379. // ------------------------------------------------------------
  380. ACE_ALLOC_HOOK_DEFINE(ACE_Hash_Multi_Map_Iterator_Base)
  381. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> void
  382. ACE_Hash_Multi_Map_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::dump_i (void) const
  383. {
  384. ACE_TRACE ("ACE_Hash_Multi_Map_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::dump_i");
  385. ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
  386. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("index_ = %d "), this->index_));
  387. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("next_ = %x"), this->next_));
  388. ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
  389. }
  390. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  391. ACE_Hash_Multi_Map_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::forward_i (void)
  392. {
  393. ACE_TRACE ("ACE_Hash_Multi_Map_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::forward_i");
  394. if (this->map_man_->table_ == 0)
  395. return -1;
  396. // Handle initial case specially.
  397. else if (this->index_ == -1)
  398. {
  399. this->index_++;
  400. return this->forward_i ();
  401. }
  402. else if (this->index_ >= static_cast<ssize_t> (this->map_man_->total_size_))
  403. return 0;
  404. this->next_ = this->next_->next_;
  405. if (this->next_ == &this->map_man_->table_[this->index_])
  406. {
  407. while (++this->index_ < static_cast<ssize_t> (this->map_man_->total_size_))
  408. {
  409. this->next_ = this->map_man_->table_[this->index_].next_;
  410. if (this->next_ != &this->map_man_->table_[this->index_])
  411. break;
  412. }
  413. }
  414. return this->index_ < static_cast<ssize_t> (this->map_man_->total_size_);
  415. }
  416. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  417. ACE_Hash_Multi_Map_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::reverse_i (void)
  418. {
  419. ACE_TRACE ("ACE_Hash_Multi_Map_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::reverse_i");
  420. if (this->map_man_->table_ == 0)
  421. return -1;
  422. else if (this->index_ == static_cast<ssize_t> (this->map_man_->total_size_))
  423. {
  424. this->index_--;
  425. return this->reverse_i ();
  426. }
  427. else if (this->index_ < 0)
  428. return 0;
  429. this->next_ = this->next_->prev_;
  430. if (this->next_ == &this->map_man_->table_[this->index_])
  431. {
  432. while (--this->index_ >= 0)
  433. {
  434. this->next_ = this->map_man_->table_[this->index_].prev_;
  435. if (this->next_ != &this->map_man_->table_[this->index_])
  436. break;
  437. }
  438. }
  439. return this->index_ >= 0;
  440. }
  441. // ------------------------------------------------------------
  442. ACE_ALLOC_HOOK_DEFINE(ACE_Hash_Multi_Map_Const_Iterator_Base)
  443. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> void
  444. ACE_Hash_Multi_Map_Const_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::dump_i (void) const
  445. {
  446. ACE_TRACE ("ACE_Hash_Multi_Map_Const_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::dump_i");
  447. ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
  448. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("index_ = %d "), this->index_));
  449. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("next_ = %x"), this->next_));
  450. ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
  451. }
  452. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  453. ACE_Hash_Multi_Map_Const_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::forward_i (void)
  454. {
  455. ACE_TRACE ("ACE_Hash_Multi_Map_Const_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::forward_i");
  456. if (this->map_man_->table_ == 0)
  457. return -1;
  458. // Handle initial case specially.
  459. else if (this->index_ == -1)
  460. {
  461. this->index_++;
  462. return this->forward_i ();
  463. }
  464. else if (this->index_ >= (ssize_t) this->map_man_->total_size_)
  465. return 0;
  466. this->next_ = this->next_->next_;
  467. if (this->next_ == &this->map_man_->table_[this->index_])
  468. {
  469. while (++this->index_ < (ssize_t) this->map_man_->total_size_)
  470. {
  471. this->next_ = this->map_man_->table_[this->index_].next_;
  472. if (this->next_ != &this->map_man_->table_[this->index_])
  473. break;
  474. }
  475. }
  476. return this->index_ < (ssize_t) this->map_man_->total_size_;
  477. }
  478. template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int
  479. ACE_Hash_Multi_Map_Const_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::reverse_i (void)
  480. {
  481. ACE_TRACE ("ACE_Hash_Multi_Map_Const_Iterator_Base<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::reverse_i");
  482. if (this->map_man_->table_ == 0)
  483. return -1;
  484. else if (this->index_ == (ssize_t) this->map_man_->total_size_)
  485. {
  486. this->index_--;
  487. return this->reverse_i ();
  488. }
  489. else if (this->index_ < 0)
  490. return 0;
  491. this->next_ = this->next_->prev_;
  492. if (this->next_ == &this->map_man_->table_[this->index_])
  493. {
  494. while (--this->index_ >= 0)
  495. {
  496. this->next_ = this->map_man_->table_[this->index_].prev_;
  497. if (this->next_ != &this->map_man_->table_[this->index_])
  498. break;
  499. }
  500. }
  501. return this->index_ >= 0;
  502. }
  503. ACE_END_VERSIONED_NAMESPACE_DECL
  504. #endif /* ACE_Hash_Multi_Map_Manager_T_CPP */