mirror of https://github.com/hak5/bolt.git
Move all C code into repo.
parent
ebc9f0da9e
commit
f922c1d2bc
51
node.go
51
node.go
|
@ -38,3 +38,54 @@ func (n *node) size() int {
|
|||
|
||||
// TODO: #define MDB_GET_KEY(node, keyptr) { if ((keyptr) != NULL) { (keyptr)->mv_size = NODEKSZ(node); (keyptr)->mv_data = NODEKEY(node); } }
|
||||
// TODO: #define MDB_GET_KEY2(node, key) { key.mv_size = NODEKSZ(node); key.mv_data = NODEKEY(node); }
|
||||
|
||||
// Compact the main page after deleting a node on a subpage.
|
||||
// @param[in] mp The main page to operate on.
|
||||
// @param[in] indx The index of the subpage on the main page.
|
||||
func (n *node) shrink(index int) {
|
||||
/*
|
||||
MDB_node *node;
|
||||
MDB_page *sp, *xp;
|
||||
char *base;
|
||||
int nsize, delta;
|
||||
indx_t i, numkeys, ptr;
|
||||
|
||||
node = NODEPTR(mp, indx);
|
||||
sp = (MDB_page *)NODEDATA(node);
|
||||
delta = SIZELEFT(sp);
|
||||
xp = (MDB_page *)((char *)sp + delta);
|
||||
|
||||
// shift subpage upward
|
||||
if (IS_LEAF2(sp)) {
|
||||
nsize = NUMKEYS(sp) * sp->mp_pad;
|
||||
if (nsize & 1)
|
||||
return; // do not make the node uneven-sized
|
||||
memmove(METADATA(xp), METADATA(sp), nsize);
|
||||
} else {
|
||||
int i;
|
||||
numkeys = NUMKEYS(sp);
|
||||
for (i=numkeys-1; i>=0; i--)
|
||||
xp->mp_ptrs[i] = sp->mp_ptrs[i] - delta;
|
||||
}
|
||||
xp->mp_upper = sp->mp_lower;
|
||||
xp->mp_lower = sp->mp_lower;
|
||||
xp->mp_flags = sp->mp_flags;
|
||||
xp->mp_pad = sp->mp_pad;
|
||||
COPY_PGNO(xp->mp_pgno, mp->mp_pgno);
|
||||
|
||||
nsize = NODEDSZ(node) - delta;
|
||||
SETDSZ(node, nsize);
|
||||
|
||||
// shift lower nodes upward
|
||||
ptr = mp->mp_ptrs[indx];
|
||||
numkeys = NUMKEYS(mp);
|
||||
for (i = 0; i < numkeys; i++) {
|
||||
if (mp->mp_ptrs[i] <= ptr)
|
||||
mp->mp_ptrs[i] += delta;
|
||||
}
|
||||
|
||||
base = (char *)mp + mp->mp_upper;
|
||||
memmove(base + delta, base, ptr - mp->mp_upper + NODESIZE + NODEKSZ(node));
|
||||
mp->mp_upper += delta;
|
||||
*/
|
||||
}
|
||||
|
|
26
page.go
26
page.go
|
@ -17,6 +17,26 @@ const (
|
|||
KeepPage = 0x8000 /**< leave this page alone during spill */
|
||||
)
|
||||
|
||||
// maxCommitPages is the maximum number of pages to commit in one writev() call.
|
||||
const maxCommitPages 64
|
||||
|
||||
/* max bytes to write in one call */
|
||||
const maxWriteByteCount 0x80000000U // TODO: #define MAX_WRITE 0x80000000U >> (sizeof(ssize_t) == 4))
|
||||
|
||||
// TODO:
|
||||
// #if defined(IOV_MAX) && IOV_MAX < MDB_COMMIT_PAGES
|
||||
// #undef MDB_COMMIT_PAGES
|
||||
// #define MDB_COMMIT_PAGES IOV_MAX
|
||||
// #endif
|
||||
|
||||
// TODO: #define MDB_PS_MODIFY 1
|
||||
// TODO: #define MDB_PS_ROOTONLY 2
|
||||
// TODO: #define MDB_PS_FIRST 4
|
||||
// TODO: #define MDB_PS_LAST 8
|
||||
|
||||
// TODO: #define MDB_SPLIT_REPLACE MDB_APPENDDUP /**< newkey is not new */
|
||||
|
||||
|
||||
type page struct {
|
||||
header struct {
|
||||
id int
|
||||
|
@ -28,6 +48,11 @@ type page struct {
|
|||
metadata []byte
|
||||
}
|
||||
|
||||
type pageState struct {
|
||||
head int /**< Reclaimed freeDB pages, or NULL before use */
|
||||
last int /**< ID of last used record, or 0 if !mf_pghead */
|
||||
}
|
||||
|
||||
// nodeCount returns the number of nodes on the page.
|
||||
func (p *page) nodeCount() int {
|
||||
return 0 // (p.header.lower - unsafe.Sizeof(p.header) >> 1
|
||||
|
@ -42,3 +67,4 @@ func (p *page) remainingSize() int {
|
|||
func (p *page) remainingSize() int {
|
||||
return p.header.upper - p.header.lower
|
||||
}
|
||||
|
||||
|
|
1506
transaction.go
1506
transaction.go
File diff suppressed because it is too large
Load Diff
|
@ -6,3 +6,4 @@ type xcursor struct {
|
|||
bucketx *bucketx
|
||||
bucketFlag int
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue