aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorMartin Kobetic <mkobetic@gmail.com>2014-04-13 10:58:02 -0400
committerSteven Normore <snormore@gmail.com>2014-04-16 13:27:48 +0000
commit8a24e16dfd8f24a970af68ed2f4757887ee025c6 (patch)
treec26bd61d783eff13a0c133485a25cbd81505eb2b /c
parentfirst draft (diff)
downloaddedo-8a24e16dfd8f24a970af68ed2f4757887ee025c6.tar.gz
dedo-8a24e16dfd8f24a970af68ed2f4757887ee025c6.tar.xz
minor cleanup
Diffstat (limited to 'c')
-rw-r--r--c/cursor.go40
1 files changed, 26 insertions, 14 deletions
diff --git a/c/cursor.go b/c/cursor.go
index 5874b20..436bece 100644
--- a/c/cursor.go
+++ b/c/cursor.go
@@ -53,49 +53,58 @@ typedef struct bolt_cursor {
unsigned int stackp;
} bolt_cursor;
+// public functions
+
void bolt_cursor_init(bolt_cursor* c, void *data, size_t pgsz, pgid root) {
c->data = data;
c->pgid = pgid;
c->pgsz = pgsz;
}
-// public functions
-
int bolt_cursor_first(bolt_cursor* c, bolt_val *key, bolt_val *value) {
leaf_elem* leaf;
elem_ref* ref;
+
+ // reset stack to initial state
c->stackp = 0;
ref = &c->stack[c->stackp]
ref->page = page(c, c->pgid);
ref->index = 0;
- return next_element(c, key, value);
+
+ // get current leaf element
+ return leaf_element(c, key, value);
}
int bolt_cursor_next(bolt_cursor* c, bolt_val *key, bolt_val *value) {
elem_ref* ref= &c->stack[c->stackp];
+
+ // increment element index
ref->index++;
+ // if we're past last element pop the stack and repeat
while (ref->index >= ref->page->count ) {
c->stackp--;
ref = &c->stack[c->stackp];
ref->index++;
}
+ // increment element pointer
if(ref->page | BRANCH_PAGE)
ref->element += sizeof(branch_elem);
else
ref->element += sizeof(leaf_elem);
- return next_element(c, key, value);
+
+ // get current leaf element
+ return leaf_element(c, key, value);
}
// int bolt_cursor_seek(bolt_cursor* c, bolt_val key, bolt_val *actual_key, bolt_val *value)
-
// private functions
page* page(bolt_cursor* c, pgid id) {
return (page*)(c->data + (c->pgsz * id));
}
-branch_elem* branch_page_element(*p, elemid index) {
+branch_elem* branch_page_element(page* p, elemid index) {
return p + sizeof(page) + index * sizeof(branch_elem);
}
@@ -103,14 +112,10 @@ leaf_elem* leaf_page_element(page* p, elemid index) {
return p + sizeof(page) + index * sizeof(leaf_elem);
}
-set_key_value(leaf_elem* leaf, bolt_val* key, bolt_val *value) {
- key.size = leaf->ksize;
- key.data = leaf + leaf->pos;
- value.size = leaf->vsize;
- value.data = key.data + key.size;
-}
-
-int next_element(bolt_cursor* c, bolt_val *key, bolt_val *value) {
+// return current leaf element
+// if stack points at a branch page descend down to the first elemenet
+// of the first leaf page
+int leaf_element(bolt_cursor* c, bolt_val *key, bolt_val *value) {
elem_ref* ref = &c->stack[c->stackp];
branch_elem* branch;
for(ref->page->flags | BRANCH_PAGE) {
@@ -125,6 +130,13 @@ int next_element(bolt_cursor* c, bolt_val *key, bolt_val *value) {
return 0
}
+set_key_value(leaf_elem* leaf, bolt_val* key, bolt_val *value) {
+ key.size = leaf->ksize;
+ key.data = leaf + leaf->pos;
+ value.size = leaf->vsize;
+ value.data = key.data + key.size;
+}
+
*/
import "C"
import "github.com/boltdb/bolt"