dyn_index.C 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * $XConsortium: dyn_index.cc /main/5 1996/07/18 14:34:38 drk $
  25. *
  26. * Copyright (c) 1993 HAL Computer Systems International, Ltd.
  27. * All rights reserved. Unpublished -- rights reserved under
  28. * the Copyright Laws of the United States. USE OF A COPYRIGHT
  29. * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
  30. * OR DISCLOSURE.
  31. *
  32. * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
  33. * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
  34. * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
  35. * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
  36. * INTERNATIONAL, LTD.
  37. *
  38. * RESTRICTED RIGHTS LEGEND
  39. * Use, duplication, or disclosure by the Government is subject
  40. * to the restrictions as set forth in subparagraph (c)(l)(ii)
  41. * of the Rights in Technical Data and Computer Software clause
  42. * at DFARS 252.227-7013.
  43. *
  44. * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
  45. * 1315 Dell Avenue
  46. * Campbell, CA 95008
  47. *
  48. */
  49. #include "index/dyn_index.h"
  50. #ifdef C_API
  51. #define v_static_key (*v_static_key_ptr)
  52. #endif
  53. dyn_index::dyn_index(c_code_t x) : c_index(x)
  54. {
  55. v_inv_lists_hd = 0;
  56. v_idx_agent_ptr = 0;
  57. }
  58. dyn_index::~dyn_index()
  59. {
  60. ////////////////////////////////////////////////////////
  61. // Need not to delete index object handlers, as they
  62. // are handled by the object cache. qfc 6-17-93
  63. ////////////////////////////////////////////////////////
  64. }
  65. data_t* dyn_index::hd_to_key(const handler& t)
  66. {
  67. get_key_string(t);
  68. /*
  69. MESSAGE(cerr, "dyn_index::hd_to_key():");
  70. if ( v_static_key.get() )
  71. debug(cerr, v_static_key.get());
  72. MESSAGE(cerr, "************");
  73. */
  74. return new data_t(v_static_key.get(), v_static_key.size());
  75. }
  76. Boolean
  77. dyn_index::insert_key_loc(const handler& t, const oid_t& id)
  78. {
  79. //MESSAGE(cerr, "dyn_index::insert_key_loc()");
  80. //id.asciiOut(cerr); cerr << "\n";
  81. data_t* intKey = hd_to_key(t);
  82. _insert_loc( *intKey, id );
  83. delete intKey;
  84. return true;
  85. }
  86. Boolean
  87. dyn_index::insert_key_loc(const oid_t& t, const oid_t& id)
  88. {
  89. data_t intKey(int(t.icode()), voidPtr(-1));
  90. return _insert_loc( intKey, id );
  91. }
  92. Boolean
  93. dyn_index::_insert_loc(data_t& intKey, const oid_t& id)
  94. {
  95. /*
  96. MESSAGE(cerr, "in dyn_index insert()");
  97. debug(cerr, intKey);
  98. debug(cerr, id);
  99. debug(cerr, p);
  100. */
  101. if ( v_idx_agent_ptr -> member( intKey ) == true ) {
  102. int hash = int(long((intKey.dt)));
  103. //MESSAGE(cerr, "update inv list");
  104. //debug(cerr, hash);
  105. /**************************/
  106. // just update the inv list
  107. /**************************/
  108. oid_list_handler* list_hd =
  109. (*v_inv_lists_hd) -> get_list(hash);
  110. if ( list_hd == 0 )
  111. throw(stringException("NULL oidlist ptr"));
  112. /*
  113. MESSAGE(cerr, "insert to list before");
  114. (*list_hd) -> asciiOut(cerr); cerr << "\n";
  115. */
  116. (*list_hd) -> insert_component(id);
  117. //list_hd -> commit();
  118. /*
  119. MESSAGE(cerr, "insert to list after");
  120. (*list_hd) -> asciiOut(cerr); cerr << "\n";
  121. */
  122. delete list_hd;
  123. } else {
  124. //MESSAGE(cerr, "create inv list");
  125. /**************************/
  126. // create a new inv list
  127. /**************************/
  128. oid_list list;
  129. list.insert_component(id);
  130. (*v_inv_lists_hd) -> append_list(list);
  131. intKey.dt = (voidPtr)(size_t)(*v_inv_lists_hd) -> count();
  132. //debug(cerr, int(intKey.dt));
  133. v_idx_agent_ptr -> insert( intKey );
  134. }
  135. /*
  136. MESSAGE(cerr, "dyn_index::_insert_loc(): ");
  137. v_idx_agent_ptr -> asciiOut(cerr);
  138. MESSAGE(cerr, "=========================");
  139. */
  140. return true;
  141. }
  142. Boolean
  143. dyn_index::remove_loc(handler& t, const oid_t& id)
  144. {
  145. data_t* intKey = hd_to_key(t);
  146. if ( intKey == 0 )
  147. return false;
  148. else {
  149. Boolean ok = _remove_loc(*intKey, id);
  150. delete intKey;
  151. return ok;
  152. }
  153. }
  154. Boolean
  155. dyn_index::remove_loc(const oid_t& t, const oid_t& id)
  156. {
  157. data_t intKey(int(t.icode()), voidPtr(-1));
  158. return _remove_loc(intKey, id);
  159. }
  160. Boolean dyn_index::_remove_loc(data_t& intKey, const oid_t& id)
  161. {
  162. //MESSAGE(cerr, "_remove_loc()");
  163. Boolean ok = v_idx_agent_ptr -> member( intKey );
  164. if ( ok == false ) return true; // no key in the hash table.
  165. //MESSAGE(cerr, "in hash table");
  166. int hash = int(long(intKey.dt));
  167. oid_list_handler *list_hd =
  168. (*v_inv_lists_hd) -> get_list(hash);
  169. if ( list_hd == 0 )
  170. throw(stringException("NULL oid list ptr"));
  171. //MESSAGE(cerr, "remove_component():");
  172. (*list_hd) -> remove_component(id);
  173. //list_hd -> commit();
  174. //MESSAGE(cerr, "remove_component() done");
  175. delete list_hd;
  176. //MESSAGE(cerr, "_remove_loc() done");
  177. return true;
  178. }
  179. Boolean dyn_index::update_streampos(handler& /* old_obj */,
  180. handler& /* new_obj */,
  181. mmdb_pos_t /* pos */
  182. )
  183. {
  184. return false;
  185. }
  186. oid_list_handler* dyn_index::get_loc_list(const oid_t& id)
  187. {
  188. data_t intKey((int)id.icode());
  189. if ( v_idx_agent_ptr -> member( intKey ) == true ) {
  190. return (*v_inv_lists_hd) -> get_list(int(long(intKey.dt)));
  191. } else {
  192. return 0;
  193. }
  194. }
  195. oid_list_handler* dyn_index::get_loc_list(const handler& t)
  196. {
  197. //MESSAGE(cerr, "dyn_index::get_loc_list()");
  198. //debug(cerr, (*v_inv_lists_hd) -> get_store() -> my_path());
  199. //debug(cerr, (*v_inv_lists_hd) -> get_store() -> my_name());
  200. if ( OK() == false ) {
  201. MESSAGE(cerr,
  202. "dyn_index::get_loc_list(): bad index object status");
  203. return 0;
  204. }
  205. data_t* intKey = 0;
  206. if ( ( intKey = hd_to_key(t)) != 0 &&
  207. v_idx_agent_ptr -> member( *intKey ) == true
  208. ) {
  209. //MESSAGE(cerr, "in hash table");
  210. int p = int(long(intKey -> dt));
  211. //debug(cerr, p);
  212. delete intKey;
  213. //MESSAGE(cerr, "dyn_index::get_loc_list() done");
  214. return (*v_inv_lists_hd) -> get_list(p);
  215. } else {
  216. //MESSAGE(cerr, "not in hash table");
  217. delete intKey;
  218. return 0;
  219. }
  220. }
  221. int dyn_index::invlist_length(handler& t)
  222. {
  223. oid_list_handler* locs = get_loc_list(t);
  224. if ( locs == 0 )
  225. throw(stringException("NULL oid list ptr"));
  226. return (*locs) -> count();
  227. }
  228. io_status dyn_index::asciiOut(ostream& )
  229. {
  230. return done;
  231. }