2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $XConsortium: dyn_index.cc /main/5 1996/07/18 14:34:38 drk $
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
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
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.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
52 #include "index/dyn_index.h"
55 #define v_static_key (*v_static_key_ptr)
59 dyn_index::dyn_index(c_code_t x) : c_index(x)
66 dyn_index::~dyn_index()
68 ////////////////////////////////////////////////////////
69 // Need not to delete index object handlers, as they
70 // are handled by the object cache. qfc 6-17-93
71 ////////////////////////////////////////////////////////
74 data_t* dyn_index::hd_to_key(const handler& t)
78 MESSAGE(cerr, "dyn_index::hd_to_key():");
79 if ( v_static_key.get() )
80 debug(cerr, v_static_key.get());
81 MESSAGE(cerr, "************");
84 return new data_t(v_static_key.get(), v_static_key.size());
88 dyn_index::insert_key_loc(const handler& t, const oid_t& id)
91 //MESSAGE(cerr, "dyn_index::insert_key_loc()");
92 //id.asciiOut(cerr); cerr << "\n";
95 data_t* intKey = hd_to_key(t);
97 _insert_loc( *intKey, id );
104 dyn_index::insert_key_loc(const oid_t& t, const oid_t& id)
106 data_t intKey(int(t.icode()), voidPtr(-1));
107 return _insert_loc( intKey, id );
111 dyn_index::_insert_loc(data_t& intKey, const oid_t& id)
114 MESSAGE(cerr, "in dyn_index insert()");
120 if ( v_idx_agent_ptr -> member( intKey ) == true ) {
122 int hash = int(long((intKey.dt)));
124 //MESSAGE(cerr, "update inv list");
127 /**************************/
128 // just update the inv list
129 /**************************/
130 oid_list_handler* list_hd =
131 (*v_inv_lists_hd) -> get_list(hash);
134 throw(stringException("NULL oidlist ptr"));
137 MESSAGE(cerr, "insert to list before");
138 (*list_hd) -> asciiOut(cerr); cerr << "\n";
141 (*list_hd) -> insert_component(id);
142 //list_hd -> commit();
145 MESSAGE(cerr, "insert to list after");
146 (*list_hd) -> asciiOut(cerr); cerr << "\n";
153 //MESSAGE(cerr, "create inv list");
155 /**************************/
156 // create a new inv list
157 /**************************/
159 list.insert_component(id);
161 (*v_inv_lists_hd) -> append_list(list);
163 intKey.dt = (voidPtr)(size_t)(*v_inv_lists_hd) -> count();
164 //debug(cerr, int(intKey.dt));
166 v_idx_agent_ptr -> insert( intKey );
170 MESSAGE(cerr, "dyn_index::_insert_loc(): ");
171 v_idx_agent_ptr -> asciiOut(cerr);
172 MESSAGE(cerr, "=========================");
179 dyn_index::remove_loc(handler& t, const oid_t& id)
181 data_t* intKey = hd_to_key(t);
186 Boolean ok = _remove_loc(*intKey, id);
193 dyn_index::remove_loc(const oid_t& t, const oid_t& id)
195 data_t intKey(int(t.icode()), voidPtr(-1));
196 return _remove_loc(intKey, id);
199 Boolean dyn_index::_remove_loc(data_t& intKey, const oid_t& id)
201 //MESSAGE(cerr, "_remove_loc()");
203 Boolean ok = v_idx_agent_ptr -> member( intKey );
205 if ( ok == false ) return true; // no key in the hash table.
207 //MESSAGE(cerr, "in hash table");
208 int hash = int(long(intKey.dt));
210 oid_list_handler *list_hd =
211 (*v_inv_lists_hd) -> get_list(hash);
214 throw(stringException("NULL oid list ptr"));
216 //MESSAGE(cerr, "remove_component():");
217 (*list_hd) -> remove_component(id);
219 //list_hd -> commit();
221 //MESSAGE(cerr, "remove_component() done");
225 //MESSAGE(cerr, "_remove_loc() done");
229 Boolean dyn_index::update_streampos(handler& /* old_obj */,
230 handler& /* new_obj */,
237 oid_list_handler* dyn_index::get_loc_list(const oid_t& id)
239 data_t intKey((int)id.icode());
241 if ( v_idx_agent_ptr -> member( intKey ) == true ) {
243 return (*v_inv_lists_hd) -> get_list(int(long(intKey.dt)));
252 oid_list_handler* dyn_index::get_loc_list(const handler& t)
254 //MESSAGE(cerr, "dyn_index::get_loc_list()");
255 //debug(cerr, (*v_inv_lists_hd) -> get_store() -> my_path());
256 //debug(cerr, (*v_inv_lists_hd) -> get_store() -> my_name());
258 if ( OK() == false ) {
260 "dyn_index::get_loc_list(): bad index object status");
266 if ( ( intKey = hd_to_key(t)) != 0 &&
267 v_idx_agent_ptr -> member( *intKey ) == true
269 //MESSAGE(cerr, "in hash table");
271 int pos = int(long(intKey -> dt));
274 //MESSAGE(cerr, "dyn_index::get_loc_list() done");
276 return (*v_inv_lists_hd) -> get_list(pos);
279 //MESSAGE(cerr, "not in hash table");
285 int dyn_index::invlist_length(handler& t)
287 oid_list_handler* locs = get_loc_list(t);
290 throw(stringException("NULL oid list ptr"));
292 return (*locs) -> count();
295 io_status dyn_index::asciiOut(ostream& )