odczyt z wartościami
This commit is contained in:
parent
4f9181b25b
commit
4be782ddd6
13
index.c
13
index.c
@ -650,6 +650,19 @@ btree_entry_t *btree_get_entry(btree_node_t* node, unsigned n)
|
||||
return (btree_entry_t*)(node->entries + NODE_ENTRY_OFFSET(n));
|
||||
}
|
||||
|
||||
page_t btree_read_record(btree_t *tree, record_key_t key, record_t *record)
|
||||
{
|
||||
btree_entry_t entry;
|
||||
page_t page = btree_find(tree, key, &entry, NULL, NULL);
|
||||
|
||||
if (page == PAGE_NONE) {
|
||||
return PAGE_NONE;
|
||||
}
|
||||
|
||||
tape_read(tree->main, entry.location, record, sizeof(record_t));
|
||||
return page;
|
||||
}
|
||||
|
||||
void btree_close(btree_t* tree)
|
||||
{
|
||||
printfv(VERBOSITY_DEBUG, "[btree] Closing index %s.\n", tree->file->filename);
|
||||
|
2
index.h
2
index.h
@ -78,6 +78,8 @@ page_t btree_remove(btree_t *tree, record_key_t key);
|
||||
bool btree_update(btree_t *tree, record_key_t key, record_t record);
|
||||
page_t btree_find(btree_t *tree, record_key_t key, btree_entry_t *entry, btree_node_t *node, unsigned *index);
|
||||
|
||||
page_t btree_read_record(btree_t *tree, record_key_t key, record_t *record);
|
||||
|
||||
btree_entry_t *btree_get_entry(btree_node_t* node, unsigned n);
|
||||
|
||||
void btree_close(btree_t* tree);
|
||||
|
24
readidx.c
24
readidx.c
@ -6,11 +6,13 @@
|
||||
#include "common.h"
|
||||
#include "index.h"
|
||||
|
||||
typedef struct {
|
||||
char* index;
|
||||
} opts_t;
|
||||
#define OPTION_KEYS_ONLY 1
|
||||
|
||||
struct {
|
||||
char* index;
|
||||
uint8_t flags;
|
||||
} options;
|
||||
|
||||
opts_t options;
|
||||
btree_t tree;
|
||||
|
||||
void init_args(int args, char* argv[])
|
||||
@ -20,6 +22,9 @@ void init_args(int args, char* argv[])
|
||||
|
||||
for (char opt; opt != -1; opt = optparse(&opts, "qv")) {
|
||||
switch (opt) {
|
||||
case 'k':
|
||||
options.flags |= OPTION_KEYS_ONLY;
|
||||
break;
|
||||
case 'q':
|
||||
verbosity--;
|
||||
break;
|
||||
@ -54,10 +59,17 @@ void print_page(page_t page)
|
||||
memcpy(&node.entries, buffer + sizeof(node.header), NODE_SIZE_MAX);
|
||||
|
||||
btree_entry_t *entry;
|
||||
record_t record;
|
||||
for (int i = 0; i < node.header.entries; i++) {
|
||||
entry = btree_get_entry(&node, i);
|
||||
print_page(entry->left);
|
||||
printf("%u\n", entry->key);
|
||||
|
||||
if (~options.flags & OPTION_KEYS_ONLY) {
|
||||
btree_read_record(&tree, entry->key, &record);
|
||||
printf("%u: (%lf, %lf)\n", entry->key, record.x, record.y);
|
||||
} else {
|
||||
printf("%u\n", entry->key);
|
||||
}
|
||||
}
|
||||
print_page(entry->right);
|
||||
}
|
||||
@ -72,7 +84,7 @@ int main(int argc, char* argv[])
|
||||
init_args(argc, argv);
|
||||
|
||||
if (btree_open(&tree, options.index) != 0) {
|
||||
fprintf(stderr, "Cannot open indes %s for reading.", options.index);
|
||||
fprintf(stderr, "Cannot open index %s for reading.", options.index);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user