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: mphf_index.cc /main/5 1996/07/18 14:38:37 drk $
26 * Copyright (c) 1992 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.
51 #include "index/mphf_index.h"
54 #define v_static_key (*v_static_key_ptr)
58 mphf_index::mphf_index() : c_index(MPHF_INDEX_CODE), f_key_file_name(0)
60 //MESSAGE(cerr, " mphf_index::mphf_index():");
61 //debug(cerr, (void*)this);
67 void mphf_index::init_data_member(fast_mphf_handler* mp,
68 inv_lists_handler* inv)
71 MESSAGE(cerr, " mphf_index::init_data_member():");
72 debug(cerr, (void*)v_mphf);
73 debug(cerr, (void*)(v_mphf->operator->()));
77 set_mode(HEALTH, true);
81 mphf_index::~mphf_index()
83 delete f_key_file_name;
85 ////////////////////////////////////////////////////////
86 // Need not to delete index object handlers, as they
87 // are handled by the object cache. qfc 6-17-93
88 ////////////////////////////////////////////////////////
92 mphf_index::insert_key_loc(const oid_t& id, const oid_t& loc)
96 *v_key_loc_pair_out << v_static_key << "\n";
97 loc.asciiOut(*v_key_loc_pair_out);
98 *v_key_loc_pair_out << "\n";
104 mphf_index::insert_key_loc(const handler& hd, const oid_t& loc)
108 *v_key_loc_pair_out << v_static_key << "\n";
109 loc.asciiOut(*v_key_loc_pair_out);
110 *v_key_loc_pair_out << "\n";
115 Boolean mphf_index::remove_loc(const oid_t&, const oid_t&)
117 throw(stringException("mphf_index::remove_index(): not applicable"));
121 Boolean mphf_index::remove_loc(handler&, const oid_t&)
123 throw(stringException("remove_index(): not applicable"));
127 Boolean mphf_index::update_streampos(handler& ,
132 throw(stringException("update_index(): not applicable"));
137 Boolean mphf_index::load(const char* key_set)
140 MESSAGE(cerr, " mphf_index::load():");
141 debug(cerr, (void*)this);
142 debug(cerr, (void*)(v_mphf->operator->()));
145 (*v_mphf) -> build(key_set);
147 fstream in(key_set, ios::in);
149 v_sz = (*v_mphf) -> keysetsize();
150 (*v_inv_lists_hd) -> expand_space(v_sz);
152 key_type key(LBUFSIZ);
158 while ( in >> key ) {
160 oid_t key_id(c_code_t(0), 0);
165 if ( i % 1000 == 0 && i != 0 ) {
167 MESSAGE(cerr, " keys processed");
168 MESSAGE(cerr, "========");
174 int hash = (*v_mphf) -> hashTo(key);
176 (*v_inv_lists_hd) -> insert_to_list(hash+1, key_id);
181 del_file(key_set, 0);
184 set_mode(HEALTH, true);
185 set_mode(UPDATE, true);
190 oid_list_handler* mphf_index::get_loc_list(const oid_t& )
192 MESSAGE(cerr, "get_loc_list(): not implemented yet");
196 int mphf_index::handler_to_inv_idx(const handler& t)
199 //debug(cerr, v_static_key);
200 return (*v_mphf) -> hashTo(v_static_key);
203 oid_list_handler* mphf_index::get_loc_list(const handler& t)
205 return (*this)(handler_to_inv_idx(t) + 1) ;
208 int mphf_index::invlist_length(handler& t)
210 oid_list_handler* x = get_loc_list(t);
211 return (*x) -> count();
214 ostream& operator << (ostream&s, mphf_index& v)
223 Boolean mphf_index::batch_index_begin()
226 MESSAGE(cerr, "batch_index_begin()");
227 debug(cerr, cmp_selector);
228 debug(cerr, count());
229 debug(cerr, int(this));
233 throw(stringException("batch_index_begin(): index exists"));
237 strdup(form("%s/keys.%d_%d",
238 get_store() -> my_path(), f_oid.ccode(), f_oid.icode()));
240 v_key_loc_pair_out = new fstream(f_key_file_name, ios::out);
242 return (( *v_key_loc_pair_out ) ? true : false );
245 Boolean mphf_index::batch_index_end()
247 v_key_loc_pair_out -> close();
248 delete v_key_loc_pair_out;
250 return load(f_key_file_name);
253 oid_t mphf_index::first_of_invlist(int ind)
255 oid_t x((*v_inv_lists_hd) -> operator()(ind+1));
257 if ( x.ccode() == OID_LIST_CODE ) {
258 oid_list_handler* y = (*this)(ind);
259 if ( (*y) -> count() > 0 ) {
260 return (*y) -> operator()(1);
262 throw(stringException("first_of_invlist(): empty list"));
269 oid_t mphf_index::first_of_invlist(const handler& t)
271 int hash = handler_to_inv_idx(t);
277 oid_t x((*v_inv_lists_hd) -> operator()(hash+1));
281 if ( x.ccode() == OID_LIST_CODE ) {
282 oid_list_handler* y = (*this)(hash);
283 if ( (*y) -> count() > 0 ) {
284 return (*y) -> operator()(1);
286 throw(stringException("first_of_invlist(): empty list"));
293 MMDB_BODIES(mphf_index)
294 HANDLER_BODIES(mphf_index)