Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / hmphf / buckets.h
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 librararies 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: buckets.h /main/3 1996/06/11 17:19:58 cde-hal $
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
50
51
52 #ifndef _buckets_h
53 #define _buckets_h 1
54
55 #include <stdio.h>
56 #include "utility/atoi_pearson.h"
57 #include "dstr/slist_void_ptr_cell.h"
58 #include "hmphf/params.h"
59 #include "hmphf/pattern.h"
60
61 class bucket 
62 {
63
64 public:
65    bucket(char*, int orig_pos = 0, Boolean copy = true);
66    ~bucket();
67    int add_key(char*, Boolean copy = true);
68
69    short no_keys() { return v_no_keys; };
70    int g_value() { return v_g_value; };
71    int control_bit() { return v_control_bit; };
72    int orig_pos() { return v_orig_pos; };
73
74    void set_count(int i) { v_count = i; };
75    void set_control_bit(int cb) { v_control_bit = cb; };
76    void set_g_value(int gv) { v_g_value = gv; };
77
78    friend ostream& operator<<(ostream&, bucket&);
79
80 protected:
81    short v_no_keys;
82    int v_count;
83    int v_control_bit;
84    int v_g_value;
85    int v_orig_pos;
86    slist_void_ptr_cell* key_ptr;
87
88    friend class buckets;
89    friend class sorter;
90 };
91
92 typedef bucket* bucketPtr;
93
94 class buckets 
95 {
96
97 public:
98    //buckets(char* key_file, params& params);
99    buckets(char** keys, params& params);
100    ~buckets();
101
102    void set_control_bit(int cb);
103
104    int get_pattern(int i, int_pattern&, params&);
105    int use_current_params(int i, int_pattern&, params& pms, 
106                           Boolean use_g_value = false);
107
108    int no_buckets() { return v_no_buckets; };
109    int max_bucket_sz() { return v_max_bucket_sz; };
110
111    bucket* operator[](int i) { return v_bucket_array[i]; };
112
113    friend ostream& operator<<(ostream&, buckets&);
114
115 protected:
116    void sort_by_size();
117    int bucket_num(char* k, params& pms);
118
119    inline int hash_value(char* k, int offset, int range)
120    {
121       return h_convertor.atoi(k, strlen(k), offset+1, range);
122    };
123
124 protected:
125    bucket** v_bucket_array;
126    int v_no_buckets;
127    int v_max_bucket_sz;
128
129    pm_random rnd;
130    atoi_pearson b_convertor;
131    atoi_pearson h_convertor;
132 };
133
134 #endif