-C :-)\s(CVS\s214)
-D 2001-04-28T16:52:41
+C :-)\s(CVS\s215)
+D 2001-04-29T23:32:56
F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
F Makefile.in acef0f0275a5ca8e68bda165f7f05d810a207664
F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
F notes/notes2.txt 80a0c3e3a0063b81fa8df6aab01bd014353dde01
F notes/notes3.txt cd5e7bd2167d7ef89b1077abdfa68f0af6337744
F src/TODO 38a68a489e56e9fd4a96263e0ff9404a47368ad4
-F src/btree.c 71381fdaec3122f80c53f7f4f38887bcff19d273
+F src/btree.c eb7eec19f54e758c86a231f97fd366cc2d4cffc1
F src/btree.h f21c240d0c95f93e2a128106d04a6c448ed0eb94
F src/build.c 4f6a2d551c56342cd4a0420654835be3ad179651
F src/dbbe.c b18259f99d87240cbe751021cf14dd3aa83a48af
F www/sqlite.tcl cb0d23d8f061a80543928755ec7775da6e4f362f
F www/tclsqlite.tcl 06f81c401f79a04f2c5ebfb97e7c176225c0aef2
F www/vdbe.tcl 0c8aaa529dd216ccbf7daaabd80985e413d5f9ad
-P 8e0476f9004a7db8a3426e57f477393645ff5629
-R 3f48b136215cd8bc470d216a44941a5e
+P 73a1ed61265040925f1a41c9c0cfeea50db70b01
+R 6983c25437d4d42e0292396f95237df8
U drh
-Z f40f8ecab433b0ffb267dc5ca6c7154e
+Z 352332e9d2b2a7ec788ddf63618fa616
** http://www.hwaci.com/drh/
**
*************************************************************************
-** $Id: btree.c,v 1.2 2001/04/28 16:52:41 drh Exp $
+** $Id: btree.c,v 1.3 2001/04/29 23:32:56 drh Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
typedef unsigned int u32;
+
+/*
+** The first page contains the following additional information:
+**
+** MAGIC-1
+** MAGIC-2
+** First free block
+*/
+#define EXTRA_PAGE_1_CELLS 3
+#define MAGIC_1 0x7264dc61
+#define MAGIC_2 0x54e55d9e
+
+/*
+** Each database page has a header as follows:
+**
+** page1_header Extra numbers found on page 1 only.
+** leftmost_pgno Page number of the leftmost child
+** first_cell Index into MemPage.aPage of first cell
+** first_free Index of first free block
+**
+** MemPage.pStart always points to the leftmost_pgno. First_free is
+** 0 if there is no free space on this page. Otherwise it points to
+** an area like this:
+**
+** nByte Number of free bytes in this block
+** next_free Next free block or 0 if this is the end
+*/
+
/*
** The maximum number of database entries that can be held in a single
** page of the database. Each entry has a 16-byte header consisting of
** be at least 4 bytes in the key/data packet, so each entry consumes at
** least 20 bytes of space on the page.
*/
-#define MX_CELL (SQLITE_PAGE_SIZE/20)
-
-/*
-** Freeblocks are divided by cells, so there can be at most one more
-** free block than there are cells.
-*/
-#define MX_FREE (MX_CELL+1)
+#define MX_CELL ((SQLITE_PAGE_SIZE-12)/20)
/*
** The maximum amount of data (in bytes) that can be stored locally for a
Pgno left; /* Left sibling page. 0==none */
Pgno right; /* Right sibling page. 0==none */
int idxStart; /* Index in aPage[] of real data */
+ int nFree; /* Number of free elements of aPage[] */
int nCell; /* Number of entries on this page */
u32 *aCell[MX_CELL]; /* All entires in sorted order */
- int nFree; /* Number of free blocks on this page */
- int nFreeSlot; /* Number of free elements of aPage[] */
- FreeBlk aFree[MX_FREE]; /* Free blocks in no particular order */
}
typedef struct MemPage;
BtIdxpt aLevel[MX_LEVEL]; /* The index levels */
};
-/*
-** The first page contains the following additional information:
-**
-** MAGIC-1
-** MAGIC-2
-** First free block
-*/
-#define EXTRA_PAGE_1_CELLS 3
-#define MAGIC_1 0x7264dc61
-#define MAGIC_2 0x54e55d9e
-
-/*
-** Each database page has a header as follows:
-**
-** page1_header Extra numbers found on page 1 only.
-** leftmost_pgno Page number of the leftmost child
-** first_cell Index into MemPage.aPage of first cell
-**
-** MemPage.pStart always points to the leftmost_pgno.
-*/
-
/*
** Mark a section of the memory block as in-use.
*/
/* Space at the end of the block */
p->size -= size;
}else{
- /* Space in the middle of the freeblock. We have to split the
- ** freeblock in two */
- /******* TBD *********/
+ /* Space in the middle of the freeblock. */
+ FreeBlk *pNew;
+ assert( p->nFreeSlot < MX_FREE );
+ pNew->idx = start+size;
+ pNew->size = p->idx+p->size - pNew->idx;
+ p->size = start - p->idx;
}
pPage->nFreeSlot -= size;
}
** Return a section of the MemPage.aPage[] to the freelist.
*/
static void freeSpace(MemPage *pPage, int start, int size){
+ int end = start+size;
+ int i;
+ FreeBlk *pMatch = 0;
+ FreeBlk *
+ for(i=0; i<pPage->nFreeSlot; i++){
+ FreeBlk *p = &pPage->aFree[i];
+ if( p->idx==end+1 ){
+ if( pMatch ){
+
+ }else{
+ p->idx = start;
+ p->size += size;
+ pMatch = p;
+ }
+ }
+ if( p->idx+p->size+1==start ){
+ p->size += size;
+ break;
+ }
+ }
}
/*