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: disk_bucket.cc /main/4 1996/06/11 17:16:00 cde-hal $
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 "diskhash/disk_bucket.h"
53 #include "api/transaction.h"
55 //#define BKT_PARAMS_SIZE (sizeof(char) + sizeof(v_k) + sizeof(v_r))
56 #define BKT_PARAMS_SIZE (sizeof(char))
58 //static buffer buf(LBUFSIZ);
60 extern transaction* g_transac;
62 disk_bucket::disk_bucket(int bnum, page_storage* store) :
63 v_bucket_num(bnum), v_key_store(store), v_overflowed(false),
64 buf(store -> aux_buf())
66 buf.set_swap_order(store -> swap_order());
70 disk_bucket::~disk_bucket()
74 page* disk_bucket::bucket_page()
77 g_transac -> book(v_key_store);
79 return (*v_key_store)(v_bucket_num+2, page_storage::READ);
82 void disk_bucket::init_params()
84 page* p = bucket_page();
87 if ( p -> count() > 1 ) {
89 char c; buf.get(c); v_overflowed = c;
94 v_key_store -> save_to_log(p);
96 int slot_num; char* z;
97 p -> alloc_slot(slot_num, BKT_PARAMS_SIZE, z);
98 if ( slot_num != 1 ) {
99 debug(cerr, v_bucket_num+2);
100 debug(cerr, slot_num);
101 throw(stringException("corrupted disk bucket"));
103 char c = v_overflowed; buf.put(c);
104 p -> update_slot(1, buf);
108 MESSAGE(cerr, "bucket OK");
110 debug(cerr, v_bucket_num+2);
115 void disk_bucket::sync_params()
117 page* p = bucket_page();
119 v_key_store -> save_to_log(p);
123 char c = v_overflowed; buf.put(c);
127 p -> update_slot(1, buf);
130 Boolean disk_bucket::member(data_t& v, int& slot_num)
135 ////////////////////////////////////
136 // use the hint, if slot_num != 0
137 ////////////////////////////////////
139 //debug(cerr, bucket_page() -> count());
140 //debug(cerr, slot_num);
142 if ( slot_num != 0 && count() >= slot_num ) {
144 //MESSAGE(cerr, "probe the slot");
145 x = (*this)(slot_num);
147 if ( x && *x == v ) {
157 /////////////////////////
158 // do a linear search
159 /////////////////////////
162 while ( ind && ind != slot_num ) {
163 //MESSAGE(cerr, "linearly search the bucket");
166 if ( x && *x == v ) {
178 int disk_bucket::insert(data_t* data)
180 //MESSAGE(cerr, "disk_bucket::insert()");
182 data -> binaryOut(buf);
183 //debug(cerr, buf.content_sz());
186 page* p = bucket_page();
188 v_key_store -> save_to_log(p);
190 if ( p -> free_bytes() > buf.content_sz() ) {
191 p -> put( slot_num, buf );
200 Boolean disk_bucket::remove(int ind)
202 page* p = bucket_page();
203 v_key_store -> save_to_log(p);
210 void disk_bucket::remove_all()
212 bucket_page() -> clean_all();
217 int disk_bucket::first()
225 data_t* disk_bucket::operator()(int ind)
229 if ( bucket_page() -> get( ind+1, buf ) == false ) return 0;
231 data_t *x = new data_t;
238 void disk_bucket::next(int& ind)
240 ind = ( ind >= count() ) ? 0 : ind+1;
243 int disk_bucket::count()
245 return MAX(0, bucket_page() -> count() - 2);
248 Boolean disk_bucket::empty()
250 return ( count() == 0 ) ? true : false;
254 ostream& disk_bucket::asciiOut(ostream& out, print_func_ptr_t print_f)
259 data_t* x = (*this)(ind);
262 x -> asciiOut(out, print_f);
271 ostream& operator<<(ostream& out, disk_bucket& bt)
273 //MESSAGE(cerr, "in disk_bucket::<<");
274 //debug(cerr, bt.bucket_page() -> count());
276 int ind = bt.first();