home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
cprog
/
btree.zip
/
DBFILES.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-16
|
4KB
|
172 lines
// C++ B+Tree
// (c) 1990,1991 Larry A. Walker
// This source is proprietary information which cannot be distributed
// without written permission of Larry A. Walker
#ifndef DBFILES_H
#define DBFILES_H
// Combined Block File Handler Header and
// B+Tree Header
void fail_que(int);
void display_que();
// Define one of these three:
/*
#define UNIX
#define XENIX
*/
#define MSDOS
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <time.h>
#ifdef UNIX
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <osfcn.h>
#else
#include <sys\stat.h>
#include <io.h>
#endif
#ifdef ZORTECH
#define main void main
#endif
#define SUCCESS 1
#define FAIL 0
#define NEAR_MATCH 2
#define NODE_EOF -1
#define CREATE 1
#define CLEAN 0
#define DIRTY 1
#define EXACT 1
#define INSERT 2
#define UNLINK 1
#define UNDEF_KEY 0
#define VAR_LNG_KEY 1
#define FIX_LNG_KEY 2
#define LONG_KEY 3
#define DOUBLE_KEY 4
#define SEARCH_LEVELS 1
#define DUPLICATES 2
#define TYPE_OF_KEY 3
#define KEY_LENGTH 4
#define ACTIVE_LEVEL 5
#define NUMBER_OF_KEYS 6
#define LAST_ACCESS 7
#define MAXVARSTR 64
#define EQ 0
#define LT -1
#define LE -2
#define GT 1
#define GE 2
#define ANY 3
#define FirstKeyOffset ((2*sizeof(int)) + sizeof(long))
// The definition TreeBlockSize is physical size of the block
// as it lays on the disk. There is a one byte overhead used
// by the bfh class. The archecture of he machine may ultim-
// ately decide the value used when creating an index. Use
// only to open a bfh file. To get the block size of an already
// created bfh file use GetBFHSize()
#define TreeBlockSize (1024-1)
#define KeySpace (TreeBlockSize - FirstKeyOffset)
#define MaxKeySize 255
#define MaxHierarchyPointers 10 // same as the number of allowable levels
#define AllowableLevels MaxHierarchyPointers
int create_index_string(char *,char *);
int create_c_string(char *,char *);
// The block file handler data block header
// bfh_data and the following data structure combined size cannot exceed
// BUFSIZ
struct bfh_data {
long magic; // magic id insures only properly marked
time_t date_opened; // files are used
time_t date_updated;
int block_size;
long first_free_block_addr;
long last_free_block_addr; // last free block has its own addr
long add_block_addr;
};
// This identifier describes a free block
struct free_block_id {
// bit 0x1 = Full Bit Set
char switches; // the switch always resides outside the
// user block area
long previous_block;
long next_block;
};
// The trunk is the tree information storage block
// It follows in the block file handler directly behind bfh data
struct Trunk {
long magic;
int search_levels;
int duplicates;
int type_of_key;
int fix_lng_key_lng;
long rootnode;
long number_of_keys;
time_t time_of_last_use;
};
// if the total_node_keys = -1 then this is an empty node
// if the next free block addr is -1, this is the last
// free block address
struct Node {
int total_node_keys;
int next_free_position;
union {
long left_node;
long next_free_block_addr;
};
char key_space[KeySpace];
};
union Key{
long long_key;
double double_key;
char key[MaxKeySize]; // null terminated string
};
struct KeyGroup {
long right_node;
long address;
union Key k ;
};
// The position status is returned from the position in node function
struct posn_status {
struct KeyGroup * prev_key;
int term_status;
int compare_status;
};
// This hierarchy differs from a cache in that its purpose is not to store nodes
// for more efficient rapid access, but to hold the linear parent list for
// more efficient movement through the tree
struct HierarchyBlock {
long block_id;
int state; // CLEAN or DIRTY
struct Node hierarchy_node;
};
#endif DBFILES_H