/* * CDE - Common Desktop Environment * * Copyright (c) 1993-2012, The Open Group. All rights reserved. * * These libraries and programs are free software; you can * redistribute them and/or modify them under the terms of the GNU * Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version. * * These libraries and programs are distributed in the hope that * they will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public * License along with these librararies and programs; if not, write * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth * Floor, Boston, MA 02110-1301 USA */ /* * $XConsortium: bucket.cc /main/3 1996/06/11 17:18:55 cde-hal $ * * Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved. * UNPUBLISHED -- rights reserved under the Copyright Laws of the United * States. Use of a copyright notice is precautionary only and does not * imply publication or disclosure. * * This software contains confidential information and trade secrets of HaL * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited * without the prior express written permission of HaL Computer Systems, Inc. * * RESTRICTED RIGHTS LEGEND * Use, duplication, or disclosure by the Government is subject to * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in * Technical Data and Computer Software clause at DFARS 252.227-7013. * HaL Computer Systems, Inc. * 1315 Dell Avenue, Campbell, CA 95008 * */ #include "dynhash/bucket.h" int bucket::upper_limit; bucket::bucket(int new_Mj, int owj) : wj(0), Mj(new_Mj), old_wj(owj) { k = 19; data_array = new data_t[2*Mj*Mj]; } bucket::~bucket() { delete [2 * Mj * Mj] data_array; } /***********************************************/ // rehash the existing keys and the new key // 'data' /***********************************************/ void bucket::rehash_all(data_t& data, shared_t& sh) { int j = 0; int ind = first(); while ( ind != -1 ) { sh.internal_L[j++] = (*this)(ind); data_array[ind].marked = false; next(ind); } sh.internal_L[j] = data; select_h_params(sh); for ( ind = 0; ind <= j; ind++ ) { int hash = h(sh.internal_L[ind].key, sh); data_array[hash] = sh.internal_L[ind]; data_array[hash].marked = true; } } /****************************************/ // select a proper value for parameter k // sh contains useful variables from the // first level hash table. /****************************************/ void bucket::select_h_params(shared_t& sh) { Boolean injective = false; int loops = 0; /******************************************/ // loop until an injective mapping is found /******************************************/ while ( injective == false ) { k = sh.rand_generator.rand() % (sh.p - 1) + 1; injective = true; for ( int i=0; i= 20 ) { // supposedly loop twice debug(cerr, loops); debug(cerr, Mj); debug(cerr, wj); debug(cerr, k); for ( int i=0; i= upper_limit ) { debug(cerr, i); debug(cerr, upper_limit); throw(stringException("hash table is in inconsistent status")); } i++; } return i; } } data_t& bucket::operator()(int ind) { return data_array[ind]; } void bucket::next(int& ind) { for ( int j = ind+1; j < upper_limit; j ++ ) if ( data_array[j].marked == true ) { ind = j; return; } ind = -1; } /***********************************************/ // print operation /***********************************************/ ostream& operator<<(ostream& out, bucket& bt) { int ind = bt.first(); while ( ind != -1 ) { debug(out, bt(ind)); bt.next(ind); } return out; }