head     1.4;
branch   ;
access   ;
symbols  Version_2_1:1.4 C_Demo_1:1.3;
locks    ; strict;
comment  @ * @;


1.4
date     90.09.25.16.15.21;  author kemnitz;  state Exp;
branches ;
next     1.3;

1.3
date     89.09.05.16.57.38;  author mao;  state C_Demo_1;
branches ;
next     1.2;

1.2
date     89.03.22.17.30.35;  author muir;  state Stab;
branches ;
next     1.1;

1.1
date     89.01.17.05.52.18;  author cimarron;  state Exp;
branches ;
next     ;


desc
@@


1.4
log
@Updating from revision 1.3 to revision 1.4
@
text
@/* ----------------------------------------------------------------
 * btpage.c --
 *	B-Tree page code.
 * ----------------------------------------------------------------
 */

#include "access/btree.h"

RcsId("$Header: RCS/btpage.c,v 1.4 90/08/13 17:23:49 cimarron Exp $");

/*|----------------------------------------------------------------
 *| btpage.c --
 *|	BTreePage Copy
 *|	BTreePage Get MaxIndex
 *|	BTreePage Get LinkItemPointer
 *|	BTreePage Get PrevItemPointer
 *|	BTreePage Set LinkItemPointer
 *|	BTreePage Set PrevItemPointer
 *|	BTreePage Get FreeSpace
 *|	BTreePage IsSafe
 *|----------------------------------------------------------------
 */

int BTreeDebuggingUnusablePageSpace = 7000;

/* ----------------------------------------------------------------
 *	BTreePage Copy
 *
 *	this copies the memory image of one page onto another.
 * ----------------------------------------------------------------
 */

/**** xxref:
 *           BTreeNodeCopy
 ****/
void FUNCTION
   BTreePageCopy(fromPage, toPage)
Page fromPage;
Page toPage;
{
   Size	pageSize;

   pageSize = PageGetPageSize(toPage);
   MemoryCopy((char *) toPage,	 /* to */
	      (char *) fromPage, /* from */
	      (int) pageSize);   /* size */
}

/* ----------------------------------------------------------------
 *	BTreePage Get MaxIndex
 *
 *	this returns the index of the highest indexed item on
 *	the page.
 * ----------------------------------------------------------------
 */
 
/**** xxref:
 *           DumpBTreePage
 *           SimpleDumpBTreePage
 *           BTreeSearchKeyScan
 ****/
Index FUNCTION
   BTreePageGetMaxIndex(page)
Page page;
{
   return PageGetActualMaxOffsetIndex(page);
}

/* ----------------------------------------------------------------
 *	BTreePage Get LinkItemPointer
 *
 *	this returns the link pointer stored in the special
 *	space on the given page.
 * ----------------------------------------------------------------
 */

/**** xxref:
 *           BTreeNodeGetLinkItemPointer
 *           BTreeSearchKeyFindAdjacent
 ****/
ItemPointer FUNCTION
   BTreePageGetLinkItemPointer(page)
Page page;
{
   ItemPointer itemPtr;
   BTreeHeader header;

   header =  PageGetBTreeHeader(page);
   itemPtr = BTreeHeaderGetLinkItemPointer(header);
   return itemPtr;
}

/* ----------------------------------------------------------------
 *	BTreePage Get PrevItemPointer
 *
 *	this returns the "prev" pointer stored in the special
 *	space on the given page.
 * ----------------------------------------------------------------
 */

/**** xxref:
 *           BTreeSearchKeyFindAdjacent
 ****/
ItemPointer FUNCTION
   BTreePageGetPrevItemPointer(page)
Page page;
{
   ItemPointer itemPtr;
   BTreeHeader header;

   header =  PageGetBTreeHeader(page);
   itemPtr = BTreeHeaderGetPrevItemPointer(header);
   return itemPtr;
}

/* ----------------------------------------------------------------
 *	BTreePage Set LinkItemPointer
 * ----------------------------------------------------------------
 */

/**** xxref:
 *           BTreeAdjustRoot
 ****/
void FUNCTION
   BTreePageSetLinkItemPointer(page, itemPtr)
Page	page;
ItemPointer itemPtr;
{
   BTreeHeader header;

   header =  PageGetBTreeHeader(page);
   BTreeHeaderSetLinkItemPointer(header, itemPtr);
}

/* ----------------------------------------------------------------
 *	BTreePage Set PrevItemPointer
 * ----------------------------------------------------------------
 */

/**** xxref:
 *           BTreeAdjustRoot
 *           BTreeNodeSetPrevItemPointer
 ****/
void FUNCTION
   BTreePageSetPrevItemPointer(page, itemPtr)
Page	page;
ItemPointer itemPtr;
{
   BTreeHeader header;
   header =  PageGetBTreeHeader(page);
   BTreeHeaderSetPrevItemPointer(header, itemPtr);
}


/* ----------------------------------------------------------------
 *	BTreePage Get FreeSpace
 *
 *	this returns the amount of usable space remaining on
 *	the page. Note: when debugging the split code we pretend
 *	we have less space in order to cause the structure to
 *	become reasonable complicated without requiring a large
 *	base relation.
 * ----------------------------------------------------------------
 */

/**** xxref:
 *           BTreePageIsSafe
 ****/
PageFreeSpace FUNCTION
   BTreePageGetFreeSpace(page)
Page page;
{
#ifdef DebuggingBtreeSplitStuff
   return (PageFreeSpace)
      PageGetFreeSpace(page) - BTreeDebuggingUnusablePageSpace;
#else
   return
      PageGetFreeSpace(page);
#endif
}

/* ----------------------------------------------------------------
 *	BTreePage IsSafe
 *
 *	this returns true if inserting an item of the given
 *	size would not cause the page to split.
 * ----------------------------------------------------------------
 */

/**** xxref:
 *           BTreeNodeIsSafe
 ****/
bool FUNCTION
   BTreePageIsSafe(page, tupsize)
Page page;
Size tupsize;
{
   int freespace;

   Assert(PageIsValid(page));

   freespace = BTreePageGetFreeSpace(page);
   return (bool)
      (freespace > (tupsize + sizeof(ItemIdData)));
}
@


1.3
log
@Working version of C-only demo
@
text
@d7 1
a7 1
#include "btree.h"
d9 1
a9 1
RcsId("$Header: /usr6/postgres/mao/postgres/src/access/index-btree/RCS/btpage.c,v 1.2 89/03/22 17:30:35 muir Stab $");
@


1.2
log
@copyright removal
@
text
@d9 1
a9 1
RcsId("$Header: /usr6/postgres/muir/postgres/src/access/index-btree/RCS/btpage.c,v 1.1 89/01/17 05:52:18 cimarron Exp $");
@


1.1
log
@Initial revision
@
text
@a0 27

/*
 * 
 * POSTGRES Data Base Management System
 * 
 * Copyright (c) 1988 Regents of the University of California
 * 
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for educational, research, and non-profit purposes and
 * without fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation, and that
 * the name of the University of California not be used in advertising
 * or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Permission to incorporate this
 * software into commercial products can be obtained from the Campus
 * Software Office, 295 Evans Hall, University of California, Berkeley,
 * Ca., 94720 provided only that the the requestor give the University
 * of California a free licence to any derived software for educational
 * and research purposes.  The University of California makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 * 
 */



d9 1
a9 1
RcsId("$Header: btpage.c,v 1.1 88/11/11 16:35:53 postgres Exp $");
@
