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: fast_mphf.h /main/5 1996/07/18 14:36:28 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 #define _fast_mphf_h 1
55 #include "index/hash.h"
56 #include "utility/atoi_pearson.h"
57 #include "object/long_pstring.h"
58 #include "utility/xtime.h"
59 #include "hmphf/mphf_funcs.h"
60 #include "hmphf/sorter.h"
63 ///////////////////////////////////////////////////////////////
64 // A fast MPHF contruct method proposed by Chen Qi Fan in 4/91.
65 // Usually it will compute MPHFs using 2-3 bits/key.
66 // Random number table size is reduced to 128 chars.
67 // Computation is fast due to the pattern matching
68 // used in the searching stage.
70 // Reference: VaTech Technical Report TR92-2, SIGIR92 paper.
73 // convert to mmdb version (task started on 9-15-92)
74 ///////////////////////////////////////////////////////////////
85 tbl_record(int sd = 0, atoi_pearson* t1 =0, atoi_pearson* t2 =0) :
86 v_seed(sd), v_tbl0(t1), v_tbl1(t2) {};
93 void_ptr_array f_array;
100 void init_table(int hash_table_sz, int seed, atoi_pearson*&, atoi_pearson*&);
102 friend class fast_mphf;
105 class fast_mphf : public long_pstring, public hash
110 fast_mphf(c_code_t = FAST_MPHF_CODE);
111 virtual ~fast_mphf();
113 MMDB_SIGNATURES(fast_mphf);
115 void init_persistent_info(persistent_info*);
118 // init the two ascii->integer map tables
119 Boolean init_map_tbls();
121 // load the MPHF from files
122 virtual io_status asciiIn(istream&);
124 // compute a hash value for a key.
125 virtual int hashTo(const key_type&);
128 virtual Boolean build(const char* data_path);
129 virtual Boolean build(istream& data_stream);
131 // show the mapping from keys to hash values and verify the mphf.
132 // option = 0: no print, only check;
133 // option = 1: print and check.
134 void print_mapping( const char*key_file, int option = 0) ;
136 void print_gvalues(ostream&out = cerr) ;
138 virtual int cdr_sizeof();
139 virtual io_status cdrOut(buffer&);
140 virtual io_status cdrIn(buffer&);
144 // return the ith g value from the g array (in packed form)
145 int gValue(int, int& gvalue, int& ctl_bit) ;
147 void print_tbls(ostream&out = cerr) ;
148 int print_bits(unsigned, ostream& = cout);
153 static tbl_cache *v_tbl_cache_ptr;
155 static tbl_cache v_tbl_cache;
158 atoi_pearson *v_tbl0 , // table1
161 Boolean v_long_string_core_indexed;
163 unsigned int v_no_ps, // number of partitions (buckets)
164 v_p1, v_p2, // parameters p1 and p2.
171 HANDLER_SIGNATURES(fast_mphf)