Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
XCOMM $XConsortium: Imakefile /main/9 1996/08/21 15:51:40 drk $
XCOMM ** WARNING **
XCOMM
XCOMM The files named here may appear in many different Imakefiles.
XCOMM If you add or remove a file, be sure to update all locations.
XCOMM It's unfortunate, but all this redundancy serves a purpose.
XCOMM
XCOMM Other possible locations are:
XCOMM .../lib/DtMmdb/Imakefile
XCOMM .../lib/DtMmdb/<subdir>/Imakefile
XCOMM .../programs/dtinfo/mmdb/Imakefile
XCOMM .../programs/dtinfo/mmdb/<subdir>/Imakefile
#define DoNormalLib NormalLibDtMmdb
#define DoSharedLib SharedLibDtMmdb
#define DoDebugLib DebugLibDtMmdb
#define DoProfileLib ProfileLibDtMmdb
#define LibName DtMmdb
#define SoRev SODTMMDBREV
#define LibHeaders NO
#define LibCreate NO
#define LargePICTable YES
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
XCOMM In DtMmdb we compile as C_API sources.
DEFINES = -DC_API
INCLUDES = -I.. $(EXCEPTIONS_INCLUDES)
SRCS = disk_bucket.C bucket_array.C disk_hash.C
OBJS = $(SRCS:.C=.o)
#include <Library.tmpl>
SubdirLibraryRule($(OBJS))
DependTarget()

View File

@@ -0,0 +1,92 @@
/*
* $XConsortium: bucket_array.cc /main/3 1996/06/11 17:15:51 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* 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 INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the 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 INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#include "diskhash/bucket_array.h"
bucket_array::bucket_array(int bs, page_storage* k_store):
v_key_store(k_store), v_cached_bucket_ptr(0)
{
//////////////////////////////////////
// physically add buckets to the store
//////////////////////////////////////
if ( v_key_store -> pages() == 1 ) {
v_buckets = 0;
expandWith(bs);
} else
v_buckets = bs;
}
bucket_array::~bucket_array()
{
delete v_cached_bucket_ptr;
}
Boolean bucket_array::expandWith(int extra_buckets)
{
v_key_store -> add_page_frames(extra_buckets);
for ( int i=v_buckets; i<v_buckets+extra_buckets; i++ ) {
disk_bucket* x = new disk_bucket(i, v_key_store);
delete x;
}
v_buckets += extra_buckets;
return true;
}
disk_bucket& bucket_array::get_bucket(int i)
{
//MESSAGE(cerr, form("to get bucket %d", i));
if ( v_cached_bucket_ptr == 0 || v_cached_bucket_ptr -> bnum() != i ) {
//if ( v_cached_bucket_ptr )
//MESSAGE(cerr, form("free bucket %d %d",
// v_cached_bucket_ptr -> bnum(), int(v_cached_bucket_ptr)));
delete v_cached_bucket_ptr;
v_cached_bucket_ptr = new disk_bucket(i, v_key_store);
//MESSAGE(cerr, form("new bucket %d %d",
//int(v_cached_bucket_ptr), v_cached_bucket_ptr -> bnum()));
}
return *v_cached_bucket_ptr;
}
ostream& bucket_array::asciiOut(ostream& out, print_func_ptr_t)
{
return out;
}
ostream& operator<<(ostream& out, bucket_array&)
{
return out;
}

View File

@@ -0,0 +1,61 @@
/*
* $XConsortium: bucket_array.h /main/3 1996/06/11 17:15:56 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* 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 INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the 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 INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _bucket_array_h
#define _bucket_array_h
#include "utility/funcs.h"
#include "diskhash/disk_bucket.h"
class bucket_array
{
public:
bucket_array(int buckets, page_storage* key_store);
virtual ~bucket_array();
void reset();
Boolean expandWith(int extra_buckets);
disk_bucket& get_bucket(int i);
int count() { return v_buckets; };
ostream& asciiOut(ostream& out, print_func_ptr_t print_f);
friend ostream& operator<<(ostream&, bucket_array&);
friend class disk_hash;
protected:
int v_buckets;
disk_bucket* v_cached_bucket_ptr;
page_storage* v_key_store;
};
typedef bucket_array* bucket_arrayPtr;
#endif

View File

@@ -0,0 +1,267 @@
/*
* $XConsortium: disk_bucket.cc /main/4 1996/06/11 17:16:00 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* 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 INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the 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 INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#include "diskhash/disk_bucket.h"
#include "api/transaction.h"
//#define BKT_PARAMS_SIZE (sizeof(char) + sizeof(v_k) + sizeof(v_r))
#define BKT_PARAMS_SIZE (sizeof(char))
//static buffer buf(LBUFSIZ);
extern transaction* g_transac;
disk_bucket::disk_bucket(int bnum, page_storage* store) :
v_bucket_num(bnum), v_key_store(store), v_overflowed(false),
buf(store -> aux_buf())
{
buf.set_swap_order(store -> swap_order());
init_params();
}
disk_bucket::~disk_bucket()
{
}
page* disk_bucket::bucket_page()
{
if ( g_transac ) {
g_transac -> book(v_key_store);
}
return (*v_key_store)(v_bucket_num+2, page_storage::READ);
}
void disk_bucket::init_params()
{
page* p = bucket_page();
buf.reset();
if ( p -> count() > 1 ) {
p -> get(1, buf);
char c; buf.get(c); v_overflowed = c;
//buf.get(v_k);
//buf.get(v_r);
} else {
v_key_store -> save_to_log(p);
int slot_num; char* z;
p -> alloc_slot(slot_num, BKT_PARAMS_SIZE, z);
if ( slot_num != 1 ) {
debug(cerr, v_bucket_num+2);
debug(cerr, slot_num);
throw(stringException("corrupted disk bucket"));
}
char c = v_overflowed; buf.put(c);
p -> update_slot(1, buf);
/*
MESSAGE(cerr, "bucket OK");
debug(cerr, int(p));
debug(cerr, v_bucket_num+2);
*/
}
}
void disk_bucket::sync_params()
{
page* p = bucket_page();
v_key_store -> save_to_log(p);
buf.reset();
char c = v_overflowed; buf.put(c);
//buf.put(v_k);
//buf.put(v_r);
p -> update_slot(1, buf);
}
Boolean disk_bucket::member(data_t& v, int& slot_num)
{
//debug(cerr, v);
data_t *x = 0;
////////////////////////////////////
// use the hint, if slot_num != 0
////////////////////////////////////
//debug(cerr, bucket_page() -> count());
//debug(cerr, slot_num);
if ( slot_num != 0 && count() >= slot_num ) {
//MESSAGE(cerr, "probe the slot");
x = (*this)(slot_num);
if ( x && *x == v ) {
v.dt = x -> dt;
delete x;
return true;
}
delete x;
}
/////////////////////////
// do a linear search
/////////////////////////
int ind = first();
//debug(cerr, ind);
while ( ind && ind != slot_num ) {
//MESSAGE(cerr, "linearly search the bucket");
x = (*this)(ind);
//debug(cerr, *x);
if ( x && *x == v ) {
v.dt = x -> dt;
delete x;
slot_num = ind;
return true;
}
delete x;
next(ind);
}
return false;
}
int disk_bucket::insert(data_t* data)
{
//MESSAGE(cerr, "disk_bucket::insert()");
buf.reset();
data -> binaryOut(buf);
//debug(cerr, buf.content_sz());
int slot_num = 0;
page* p = bucket_page();
v_key_store -> save_to_log(p);
if ( p -> free_bytes() > buf.content_sz() ) {
p -> put( slot_num, buf );
} else {
set_overflow(true);
sync_params();
}
return slot_num;
}
Boolean disk_bucket::remove(int ind)
{
page* p = bucket_page();
v_key_store -> save_to_log(p);
p -> del_slot(ind);
return true;
}
void disk_bucket::remove_all()
{
bucket_page() -> clean_all();
init_params();
}
/*
int disk_bucket::first()
{
int ind = 0;
next(ind);
return ind;
}
*/
data_t* disk_bucket::operator()(int ind)
{
buf.reset();
if ( bucket_page() -> get( ind+1, buf ) == false ) return 0;
data_t *x = new data_t;
x-> binaryIn(buf);
return x;
}
/*
void disk_bucket::next(int& ind)
{
ind = ( ind >= count() ) ? 0 : ind+1;
}
int disk_bucket::count()
{
return MAX(0, bucket_page() -> count() - 2);
}
Boolean disk_bucket::empty()
{
return ( count() == 0 ) ? true : false;
}
*/
ostream& disk_bucket::asciiOut(ostream& out, print_func_ptr_t print_f)
{
int ind = first();
while ( ind != 0 ) {
data_t* x = (*this)(ind);
if ( x )
x -> asciiOut(out, print_f);
delete x;
next(ind);
}
return out;
}
ostream& operator<<(ostream& out, disk_bucket& bt)
{
//MESSAGE(cerr, "in disk_bucket::<<");
//debug(cerr, bt.bucket_page() -> count());
int ind = bt.first();
while ( ind != 0 ) {
data_t* x = bt(ind);
if ( x )
out << *x << "\n";
delete x;
bt.next(ind);
}
return out;
}

View File

@@ -0,0 +1,87 @@
/*
* $XConsortium: disk_bucket.h /main/4 1996/06/11 17:16:05 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* 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 INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the 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 INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _disk_bucket_h
#define _disk_bucket_h
#include "storage/page.h"
#include "storage/page_storage.h"
class disk_bucket
{
public:
disk_bucket(int bucket_num, page_storage* store);
virtual ~disk_bucket();
// update
//void set_k(int new_k) { v_k = new_k; };
//void set_r(int new_rotate) { v_r = new_rotate; } ;
void set_overflow(Boolean ov) { v_overflowed = ov; } ;
//int k() { return v_k; };
//int r() { return v_r; };
Boolean overflow() { return v_overflowed; };
// update
int insert(data_t*);
Boolean remove(int ind);
void remove_all();
Boolean member(data_t& v, int& slot_num);
int first() { int ind = 0; next(ind); return ind; };
data_t* operator()(int ind);
void next(int& ind) { ind = ( ind >= count() ) ? 0 : ind+1; };
int count() { return MAX(0, bucket_page() -> count() - 2); };
Boolean empty() { return ( count() == 0 ) ? true : false; };
int bnum() { return v_bucket_num; };
ostream& asciiOut(ostream& out, print_func_ptr_t print_f);
friend ostream& operator<<(ostream&, disk_bucket&);
protected:
void init_params();
void sync_params();
page* bucket_page();
protected:
Boolean v_overflowed;
//unsigned int v_k;
//unsigned int v_r;
int v_bucket_num;
page_storage* v_key_store;
buffer& buf;
};
typedef disk_bucket* disk_bucketPtr;
#endif

View File

@@ -0,0 +1,459 @@
/*
* $XConsortium: disk_hash.cc /main/5 1996/07/18 14:28:19 drk $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* 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 INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the 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 INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#include "diskhash/disk_hash.h"
#include "api/transaction.h"
extern transaction* g_transac;
int dsteps[] = { 2, 3, 5, 7, 11, 13, 17, 21, 23, 29, 31 };
int no_dsteps;
#define KPB 20 // keys per bucket
#define REHASHS 5 // number of rehashs in a row with
// fixed bucket size
#define TOP_LEVEL_PARAMS (sizeof(k) + sizeof(p) + sizeof(M) + \
sizeof(n) + sizeof(v))
//static buffer buf(LBUFSIZ);
disk_hash::disk_hash(page_storage* store, int prime, int expected_n) :
index_agent(), key_store(store), buf(store -> aux_buf())
{
if ( g_transac ) {
g_transac -> book(store);
}
buf.set_swap_order(store -> swap_order());
rand_generator.seed();
no_dsteps = sizeof(dsteps) / sizeof(int);
init_params(prime, expected_n);
bucket_vector = new bucket_array(M+v, store);
hash_vector = new void_ptr_array(2*MAX(expected_n, n));
k_vector = new void_ptr_array(M+v);
r_vector = new void_ptr_array(M+v);
k_vector -> reset_vptr(voidPtr(1));
}
disk_hash::~disk_hash()
{
delete bucket_vector;
delete hash_vector;
delete k_vector;
delete r_vector;
}
void disk_hash::init_params(int prime, int expected_n)
{
int pgs = key_store -> pages();
if ( pgs > 0 ) {
if ( (*key_store)(1, page_storage::READ) -> count() != 2 ) {
throw(stringException("corruptted primary bucket"));
}
/////////////////////////////////
// read in params from the store
/////////////////////////////////
buf.reset();
(*key_store)(1, page_storage::READ) -> get(1, buf);
buf.get(k).get(p).get(M).get(n).get(v);
} else {
///////////////////////////////////////
// init the store. bucket 1 is reserved
// for top level function params
///////////////////////////////////////
set_p(prime);
set_k(rand_generator.rand());
set_M(MAX(1, expected_n/KPB));
set_v(MAX(1, M/4));
set_n(0);
key_store -> add_page_frames(1);
int slot_num; char* z;
(*key_store)(1, page_storage::WRITE) ->
alloc_slot(slot_num, TOP_LEVEL_PARAMS, z);
if ( slot_num != 1 ) {
throw(stringException("corruptted primary bucket"));
}
sync_params();
}
}
void disk_hash::sync_params()
{
buf.reset();
buf.put(k).put(p).put(M).put(n).put(v);
(*key_store)(1, page_storage::WRITE) -> update_slot(1, buf);
}
void disk_hash::clean()
{
throw(stringException("void disk_hash::clean(): not implemented yet"));
}
///////////////////////////////////////////////////////////////
// rehash all keys
///////////////////////////////////////////////////////////////
Boolean disk_hash::rehash(data_t& w)
{
//MESSAGE(cerr, "REHASH:");
char tmp_name[PATHSIZ];
sprintf(tmp_name, "%s.tmp", key_store -> my_name());
fstream pool(form("%s/%s", key_store -> my_path(), tmp_name),
ios::in | ios::out
);
for ( int i=0; i<bucket_vector -> count(); i++ ) {
pool << bucket_vector -> get_bucket(i);
}
pool << w;
Boolean ok = false;
for ( int rehashs=0; rehashs<REHASHS; rehashs++ ) {
/////////////////////
// adjust params
/////////////////////
int old_M = M;
int old_v = v;
set_M(MAX(n/KPB, 2*M));
set_v(M/4);
int delta = M + v - old_M - old_v;
k_vector -> expandWith(delta);
r_vector -> expandWith(delta);
//////////////////////////////////////////
// expand the buckets and the hash table
//////////////////////////////////////////
bucket_vector -> expandWith(MAX(0, M+v - bucket_vector -> count()));
hash_vector -> expandWith(MAX(0, 2*n - hash_vector -> count()));
/////////////////////
// clean buckets
/////////////////////
for ( int i=0; i<bucket_vector -> count(); i++ ) {
bucket_vector -> get_bucket(i).remove_all();
}
if ( _rehash(pool) == true ) {
ok = true;
break;
}
}
if ( ok == false )
throw(stringException("rehash() failed"));
del_file(tmp_name, key_store -> my_path());
return true;
}
Boolean disk_hash::_rehash(fstream& pool)
{
pool.clear(); pool.seekg(0, ios::beg);
hash_vector -> reset_vptr(voidPtr(0));
k_vector -> reset_vptr(voidPtr(1));
r_vector -> reset_vptr(voidPtr(0));
set_k(rand_generator.rand());
data_t x((char*)0, 0, 0);
while ( pool >> x ) {
if ( _insert(x, false) == false )
return false;
}
return true;
}
/************************************/
// insert
/************************************/
Boolean disk_hash::insert(data_t& w)
{
if ( _insert(w, true) == false )
throw(stringException("disk_hash::insert() failed"));
n++;
sync_params();
return true;
}
Boolean disk_hash::_insert(data_t& w, Boolean rehash_if_fail)
{
int hash = w.bucket_num(k, p, M);
//int hash = w.key.int_key;
//debug(cerr, hash);
disk_bucket& b = bucket_vector -> get_bucket(hash);
int slot_num = b.insert(&w);
if ( slot_num != 0 ) {
caching(b, w, slot_num);
} else {
///////////////////////////////////
// insert into the overflow bucket
///////////////////////////////////
//MESSAGE(cerr, "INSERT to overflow buckets");
//debug(cerr, hash);
for ( hash %= v; hash < v; hash++ ) {
disk_bucket& overflowb = bucket_vector -> get_bucket(hash+M);
slot_num = overflowb.insert(&w);
if ( slot_num != 0 ) {
caching(overflowb, w, slot_num);
break;
}
}
if ( slot_num == 0 && rehash_if_fail == true )
return rehash(w);
}
if ( slot_num != 0 )
return true;
else
return false;
}
void disk_hash::caching(disk_bucket& b, data_t& w, int slot_num)
{
//debug(cerr, b.bnum());
//debug(cerr, k_vector -> count());
int k = int((long)(*k_vector)[b.bnum()]);
int r = int((long)(*r_vector)[b.bnum()]);
///////////////////////////////////////////
// cache all keys in the bycket except w.
// In fact, only need to cache keys whose
// hash vector slots have been updated.
// It is to be enhanced.
///////////////////////////////////////////
int ind = b.first();
while ( ind != 0 && ind != slot_num ) {
data_t* x = b(ind);
if ( x ) {
hash_vector -> insert(
voidPtr(ind),
x -> slot_num(k, r, p, hash_vector -> count())
);
}
delete x;
b.next(ind);
}
////////////////////////////////////////
// cache w. it is always in the cache.
// others may be overwritten.
////////////////////////////////////////
hash_vector -> insert(
voidPtr(slot_num),
w.slot_num(k, r, p, hash_vector -> count())
);
}
/******************************************/
// remove operation
/******************************************/
Boolean disk_hash::remove(data_t& w)
{
int slot_num;
disk_bucket* b = 0;
if ( member(w, b, slot_num) == true ) {
b -> remove(slot_num);
n--;
sync_params();
return true;
} else
return false;
}
Boolean disk_hash::member(data_t& w)
{
//MESSAGE(cerr, "disk_hash::member():");
//asciiOut(cerr);
//MESSAGE(cerr, "+++++++++++++");
disk_bucket* b = 0;
int slot_num;
return member(w, b, slot_num);
}
Boolean disk_hash::member(data_t& w, disk_bucket*& b, int& slot_num) const
{
int hash = w.bucket_num(k, p, M);
//int hash = w.key.int_key;
//debug(cerr, hash);
b = &bucket_vector -> get_bucket(hash);
int k = int((long)(*k_vector)[b -> bnum()]);
int r = int((long)(*r_vector)[b -> bnum()]);
slot_num =
int((long)(*hash_vector)[w.slot_num(k, r, p, hash_vector -> count())]);
//debug(cerr, slot_num);
if ( b -> member(w, slot_num) == true )
return true;
if ( b -> overflow() == true ) {
for ( hash %= v; hash<v; hash++ ) {
b = &bucket_vector -> get_bucket(hash+M);
if ( b -> member(w, slot_num) == true ) {
return true;
}
}
}
return false;
}
int disk_hash::first_bucket()
{
return ( M > 0 ) ? 0 : -1;
}
disk_bucket* disk_hash::get_bucket(int& ind)
{
return &bucket_vector -> get_bucket(ind);
}
void disk_hash::next_bucket(int& ind)
{
ind = ( ind >= M+v-1 ) ? -1 : (ind+1);
}
/*******************************************************/
// print operation
/*******************************************************/
ostream& disk_hash::asciiOut(ostream& out)
{
int ind = first_bucket();
while ( ind != -1 ) {
//MESSAGE(cerr, "New Bucket:");
//debug(cerr, ind);
disk_bucket* bucket = get_bucket(ind);
if ( bucket ) {
out << *bucket;
}
next_bucket(ind);
}
return out;
}
istream& disk_hash::asciiIn(istream& in)
{
data_t actor;
while ( in >> actor ) {
_insert(actor, true);
n++;
}
sync_params();
return in;
}
ostream& disk_hash::asciiOut(ostream& out, print_func_ptr_t print_f)
{
int ind = first_bucket();
while ( ind != -1 ) {
disk_bucket* bucket = get_bucket(ind);
if ( bucket ) {
bucket -> asciiOut(out, print_f);
}
next_bucket(ind);
}
return out;
}
void disk_hash::out_params()
{
debug(cerr, k);
debug(cerr, p);
debug(cerr, M);
debug(cerr, v);
debug(cerr, n);
}

View File

@@ -0,0 +1,120 @@
/*
* $XConsortium: disk_hash.h /main/3 1996/06/11 17:16:15 cde-hal $
*
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
* 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 INTERNATIONAL, LTD. USE,
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
* INTERNATIONAL, LTD.
*
* RESTRICTED RIGHTS LEGEND
* Use, duplication, or disclosure by the Government is subject
* to the 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 INTERNATIONAL, LTD.
* 1315 Dell Avenue
* Campbell, CA 95008
*
*/
#ifndef _disk_hash_h
#define _disk_hash_h
#include "diskhash/bucket_array.h"
#include "diskhash/disk_bucket.h"
#include "dstr/void_ptr_array.h"
#include "dstr/index_agent.h"
#include "storage/page_storage.h"
#define COLLISION_BIT 0x2
extern int steps[];
extern int no_steps;
class disk_hash : public index_agent
{
public:
disk_hash(page_storage* key_oid_store,
int prime = 32801,
int expected_n = 100
);
// prime and expected
// key set size
virtual ~disk_hash();
Boolean insert(data_t& v); // insert a key
Boolean remove(data_t& v); // remove a key
Boolean member(data_t& v); // member test
void clean(); // remove all keys
//int no_keys() const { return n; }; // return key set size
// WARNING: -1 is the terminate condition!!!
int first_bucket();
disk_bucket* get_bucket(int&);
void next_bucket(int&);
// output this with print_f handling the printing of whole data_t.
// pointer to data_t as void* is passed to print_f
ostream& asciiOut(ostream& out, print_func_ptr_t print_f);
ostream& asciiOut(ostream& out);
istream& asciiIn(istream& in);
protected:
void init_params(int prime, int expected_n);
void sync_params();
void set_M(unsigned int newM) { M = newM; };
void set_v(unsigned int newv) { v = newv; };
void set_k(unsigned int newk) { k = newk; };
void set_p(unsigned int newp) { p = newp; };
void set_n(unsigned int newn) { n = newn; };
Boolean rehash(data_t& w); // rehash all keys in buckets + w
Boolean _rehash(fstream& pool); // rehash keys from pool
Boolean _insert(data_t& v, Boolean rehash_if_fail);
Boolean member(data_t& v, disk_bucket*& b, int& slot_num) const;
void caching(disk_bucket& b, data_t& w, int slot_num);
void out_params();
protected:
unsigned int M; // number buckets
unsigned int v; // number of overflow buckets
unsigned int k; // parameter used in the 1st level hash function
unsigned int p; // prime number p
//unsigned int n; // current key set size
bucket_array* bucket_vector; // bucket array
void_ptr_array* hash_vector; // hash array
void_ptr_array* k_vector; // k param array
void_ptr_array* r_vector; // r param array
page_storage* key_store; // key_recordOID store
buffer& buf;
pm_random rand_generator; // rand generator
};
#endif