tldm-universe/Ardent/UV/gcidir/include/btree.h
2024-09-09 17:51:08 -04:00

361 lines
12 KiB
C
Executable File

#ifndef h_btree
#define h_btree
/******************************************************************************
*
* Declarations for UniVerse Database btree data file routines
*
* Module %M% Version %I% Date %H%
*
* (c) Copyright 1998 Ardent Software Inc. - All Rights Reserved
* This is unpublished proprietary source code of Ardent Software Inc.
* The copyright notice above does not evidence any actual or intented
* publication of such source code.
*
*******************************************************************************
*
* Maintenence log - insert most recent change descriptions at top
* Date.... GTAR# WHO Description.........................................
* 04/26/99 24742 GMH Correct typing
* 04/19/99 24742 GMH Correct size of bt_lmaxrec64
* 04/12/99 24742 GMH Implement 64bit T25 files
* 10/14/98 23801 SAP Change copyrights.
* 05/20/98 21718 LPC/WSM Add support for file suspension
* 05/07/98 22910 JBG Define DBfindt25 input param
* 03/11/96 18125 GMH Move bit declarations to disk.h
* 03/08/96 17832 GMH Add comment
* 01/02/96 17832 HSB new flag bitSQLITYP for SQL I type indices.
* 11/16/95 17538 TMC Allow type 1/19 joins, remove scandir scant25 glob
* 04/10/95 16244 GMM Changed ino_t to uv_ino_t
* 05/24/94 8788 GMH Add mode descriptions
* 04/22/94 8964 GMH Add ak_update structure
* 08/02/93 10978 SHK Port to DEC AXP
* 12/17/92 10752 RM Added bit flags for type 25 file header
* 04/13/92 9192 GMH Added bt_lmerge value
* 10/30/91 8874 RM btree optimizations
* 09/09/91 8690 RM change item padding
* 07/30/89 6060 JWT fix type 25 overflow handling
* 03/15/89 4715 JWT Type 25 file fixes
* 07/25/88 - - Maintenence log purged at 5.2.1, see release 5.1.10.
*
*****************************************************************************/
/* modes for get_overt25 function in DBidxupd.c module */
#define fchainCREATE 0 /* position and create new page clearing DBbuf */
#define fchainCHECK 1 /* 0 if page on freechain exists or page created*/
/* -1 if failure to create freechain page */
#define fchainPLACE 2 /* position and create new page retaining DBbuf */
#define bt_ibfact 384 /* branching factor of internal nodes */
#define bt_lbfact 128 /* branching factor of leaf nodes */
#define bt_asplit 32 /* asymmetric split factor for seq keys */
#define bt_pgsiz 8192 /* page size for read/write operations */
#define bt_intag 0x0001 /* tag bit - internal node */
#define bt_lntag 0x0002 /* tag bit - leaf node */
#define bt_fbtag 0x0004 /* tag bit - free node */
#define bt_obtag 0x0008 /* tag bit - overflow node */
#define bt_osrec 0x4000 /* index item flag for oversize record */
#define bt_padinrec 0x2000 /* item is padded with SM */
#define bt_newstyle 0x1000 /* item uses newstyle padding */
/* mode parameter of DBfindt25 */
#define bt_read 1 /* use read algorithm */
#define bt_write 2 /* use write algorithm , lock left or write sibling */
#define bt_delete 4 /* use write algorithm */
#define bt_functmsk 0x0f /* function mask */
#define bt_testrl 0x10 /* Use inputted key to test for record lock */
/* mode parameter of DBscant25 */
#define bt_order 0x01 /* 0 = ascending, 1 = descending */
#define bt_usekey 0x02 /* 0 = regular leaf, 1 = use kstr */
#define bt_bscan 0x04 /* 1 = BASIC BSCAN */
#define bt_bscanv 0x08 /* 0 = bscan switch variable, 1 = don't */
/* mask for keys */
#define bt_masks ( bt_osrec | bt_padinrec | bt_newstyle )
/* Definition of structures for INTERNAL (key) nodes */
#define bt_imaxrec32 ( bt_pgsiz - (2 * sizeof(short) +\
(bt_ibfact * sizeof(DBDADDR32)) + sizeof(short) +\
(2 * (bt_ibfact * sizeof(short)))))
#define bt_imaxrec64 ( bt_pgsiz - (2 * sizeof(short) + 4 +\
(bt_ibfact * sizeof(DBDADDR)) + sizeof(short) +\
(2 * (bt_ibfact * sizeof(short)))))
#define BT_ISPACE(x) (x->addr_support!=NEW64?bt_imaxrec32:bt_imaxrec64)
/* For OLD32 and NEW32 files */
struct bt_inode32
{ short tags,
freehead;
DBDADDR32 nptr[bt_ibfact];
short kcnt,
kptr[bt_ibfact],
klen[bt_ibfact];
char bdata[bt_imaxrec32];
};
/* For NEW64 only. Use padspace to insure 8-byte alignment of structure */
struct bt_inode64
{ short tags,
freehead;
char padspace[4];
DBDADDR nptr[bt_ibfact];
short kcnt,
kptr[bt_ibfact],
klen[bt_ibfact];
char bdata[bt_imaxrec64];
};
union bt_inode
{
struct bt_inode32 is32;
struct bt_inode64 is64;
};
#define INTERNAL_NODE union bt_inode
#define INTERNAL_NODE32 struct bt_inode32
#define INTERNAL_NODE64 struct bt_inode64
/* Definition of structures for TERMINAL (data) nodes */
#define bt_lmaxrec32 ( bt_pgsiz - (2 * sizeof(short) +\
(2 * sizeof(DBDADDR32)) + sizeof(short) +\
(2 * (bt_lbfact * sizeof(short)))))
#define bt_lmaxrec64 ( bt_pgsiz - (2 * sizeof(short) + 4 +\
(2 * sizeof(DBDADDR)) + sizeof(short) +\
(2 * (bt_lbfact * sizeof(short)))))
#define BT_LSPACE(x) (x->addr_support!=NEW64?bt_lmaxrec32:bt_lmaxrec64)
#define bt_lsplit (1024)
#define bt_lmerge (256)
/* for OLD32 and NEW32 files */
struct bt_lnode32
{ short tags,
freehead;
DBDADDR32 l_sibling,
r_sibling;
short kcnt,
kptr[bt_lbfact],
klen[bt_lbfact];
char bdata[bt_lmaxrec32];
};
/* NEW64 only. Use padspace to insure 8-byte alignment of structure */
struct bt_lnode64
{ short tags,
freehead;
char padspace[4];
DBDADDR l_sibling,
r_sibling;
short kcnt,
kptr[bt_lbfact],
klen[bt_lbfact];
char bdata[bt_lmaxrec64];
};
union bt_lnode
{
struct bt_lnode32 is32;
struct bt_lnode64 is64;
};
#define TERMINAL_NODE union bt_lnode
#define TERMINAL_NODE32 struct bt_lnode32
#define TERMINAL_NODE64 struct bt_lnode64
/* Definition of structures for OVERSIZED (data) nodes */
#define bt_omaxrec32 (bt_pgsiz-(2*sizeof(short)+sizeof(DBDADDR32)+sizeof(int)))
#define bt_omaxrec64 (bt_pgsiz-(2*sizeof(short)+sizeof(DBDADDR)+sizeof(int)))
#define BT_OSPACE(x) (x->addr_support!=NEW64?bt_omaxrec32:bt_omaxrec64)
struct bt_onode32
{ short tags,fill;
DBDADDR32 nptr;
int bcnt;
char bdata[bt_omaxrec32];
};
/* For NEW64 only. Move bcnt to insure 8-byte alignment of structure */
struct bt_onode64
{ short tags,fill;
int bcnt;
DBDADDR nptr;
char bdata[bt_omaxrec64];
};
union bt_onode
{
struct bt_onode32 is32;
struct bt_onode64 is64;
};
#define OVERSIZE_NODE union bt_onode
#define OVERSIZE_NODE32 struct bt_onode32
#define OVERSIZE_NODE64 struct bt_onode64
/* Definition of structures for FREE (on freechain) nodes */
struct bt_fnode32
{ short tags,fill;
DBDADDR32 nextfree;
};
/* For NEW64 only. Use padspace to insure 8-byte alignment of structure */
struct bt_fnode64
{ short tags,fill;
char padspace[4];
DBDADDR nextfree;
};
union bt_fnode
{
struct bt_fnode32 is32;
struct bt_fnode64 is64;
};
#define FREE_NODE union bt_fnode
#define FREE_NODE32 struct bt_fnode32
#define FREE_NODE64 struct bt_fnode64
/* Definition of header structures for BDATA records */
struct bt_index
{
short slotptr;
char data[1];
};
#define BT_INDEX struct bt_index
#define T25ovhdr32 (sizeof(short)+sizeof(DBDADDR32))
#define T25ovhdr64 (sizeof(short)+sizeof(DBDADDR))
/* Structure used within trans.c and DBidxupd.c to allow for the
reference of current record without having a lock conflict.
Use of TRANS, Tfile or XLATE to main data file same record
id will no longer wait on write lock. Read and Readu will
still wait.
*/
struct ak_update
{ int refs;
uv_ino_t inode;
uUVLONG dev;
STRING *key;
STRING *data;
};
/* function prototyping */
EXTERN DBDADDR get_t25info(
DBFILE *fdesc,
INTERNAL_NODE *nodeptr,
int element,
int cell,
DBDADDR *value);
EXTERN int set_t25info(
DBFILE *fdesc,
INTERNAL_NODE *nodeptr,
int element,
int cell,
DBDADDR value);
EXTERN char *get_t25bdata(
DBFILE *fdesc,
INTERNAL_NODE *inodeptr);
/* Used as 'element' argument to get_t25info & set_t25info function */
#define BT_FREE 1 /* 2 byte value defining new bdata insert location */
#define BT_PREV 2 /* DBDADDR address of previous node (LNODE l_sibling) */
#define BT_NEXT 3 /* DBDADDR address of successive node (LNODE r_sibling)*/
#define BT_NODE 4 /* table of DBDADDR address to other nodes (INODE nptr table) */
#define BT_KCNT 5 /* 2 byte counter of kptr entries (INODE & LNODE tables) */
#define BT_KPTR 6 /* table of 2 byte offsets into bdata (INODE & LNODE tables) */
#define BT_KLEN 7 /* table of 2 byte bdata lengths (INODE & LNODE tables) */
#define BT_BCNT 8 /* 4 byte counter of used bytes (ONODE only) */
/* macro to retrieve Bdata pointer */
#define GET_T25BDATA(fdesc, nodeptr) get_t25bdata(fdesc, (INTERNAL_NODE*)nodeptr)
/* retrieval function macro calls */
#define GET_T25FREE(fdesc, nodeptr, value)\
get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_FREE, 0, value)
#define GET_T25PREV(fdesc, nodeptr, value)\
get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_PREV, (int)0, (DBDADDR)value)
#define GET_T25NEXT(fdesc, nodeptr, value)\
get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_NEXT, (int)0, (DBDADDR)value)
#define GET_T25NODE(fdesc, nodeptr, cell, value)\
get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_NODE, (int)cell, (DBDADDR)value)
#define GET_T25KCNT(fdesc, nodeptr, value)\
get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_KCNT, (int)0, (DBDADDR)value)
#define GET_T25KPTR(fdesc, nodeptr, cell, value)\
get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_KPTR, (int)cell, (DBDADDR)value)
#define GET_T25KLEN(fdesc, nodeptr, cell, value)\
get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_KLEN, (int)cell, (DBDADDR)value)
#define GET_T25BCNT(fdesc, nodeptr, value)\
get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_BCNT, (int)0, (DBDADDR)value)
/* set function macro calls */
#define SET_T25FREE(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_FREE, (int)0, (DBDADDR)value)
#define SET_T25PREV(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_PREV, (int)0, (DBDADDR)value)
#define SET_T25NEXT(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_NEXT, (int)0, (DBDADDR)value)
#define SET_T25NODE(fdesc, nodeptr, cell, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_NODE, (int)cell, (DBDADDR)value)
#define SET_T25KCNT(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_KCNT, (int)0, (DBDADDR)value)
#define SET_T25KPTR(fdesc, nodeptr, cell, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_KPTR, (int)cell, (DBDADDR)value)
#define SET_T25KLEN(fdesc, nodeptr, cell, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_KLEN, (int)cell, (DBDADDR)value)
#define SET_T25BCNT(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_BCNT, (int)0, (DBDADDR)value)
#define INC_T25KCNT(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_KCNT, (int)0, \
(DBDADDR)((int)get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_KCNT, (int)0, (DBDADDR)NULL) +\
(int)value))
#define DEC_T25KCNT(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_KCNT, (int)0, \
(DBDADDR)((int)get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_KCNT, (int)0, (DBDADDR)NULL) -\
(int)value))
#define INC_T25FREE(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_FREE, (int)0, \
(DBDADDR)((int)get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_FREE, 0, (DBDADDR)NULL) +\
(int)value))
#define DEC_T25FREE(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_FREE, (int)0, \
(DBDADDR)((int)get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_FREE, 0, (DBDADDR)NULL) -\
(int)value))
#define INC_T25BCNT(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_BCNT, (int)0, \
(DBDADDR)((int)get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_BCNT, 0, (DBDADDR)NULL) +\
(int)value))
#define DEC_T25BCNT(fdesc, nodeptr, value)\
set_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_BCNT, (int)0, \
(DBDADDR)((int)get_t25info(fdesc, (INTERNAL_NODE*)nodeptr, BT_BCNT, 0, (DBDADDR)NULL) -\
(int)value))
#endif /* end of btree.h */