aktualizacja
This commit is contained in:
parent
4c83ba3036
commit
4f9181b25b
2
index.c
2
index.c
@ -636,6 +636,8 @@ bool btree_update(btree_t *tree, record_key_t key, record_t record)
|
||||
return false;
|
||||
}
|
||||
|
||||
tape_write(tree->main, entry.location, &record, sizeof(record));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
2
index.h
2
index.h
@ -5,6 +5,7 @@
|
||||
#include "record.h"
|
||||
#include "tape.h"
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define SIZEOF_ENTRIES(n) (sizeof(btree_node_header_t) + (sizeof(btree_entry_t) - sizeof(page_t))*(n) + ((n) > 0 ? 1 : 0) * sizeof(page_t))
|
||||
#define NODE_SIZE(node) SIZEOF_ENTRIES(node->header.entries)
|
||||
@ -74,6 +75,7 @@ int btree_open(btree_t *tree, char* filename);
|
||||
|
||||
page_t btree_insert(btree_t *tree, record_t record);
|
||||
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);
|
||||
|
||||
btree_entry_t *btree_get_entry(btree_node_t* node, unsigned n);
|
||||
|
19
openidx.c
19
openidx.c
@ -64,6 +64,7 @@ result_t records_command(const char* command, char* args);
|
||||
result_t find_command(const char* command, char* args);
|
||||
result_t read_command(const char* command, char* args);
|
||||
result_t delete_command(const char* command, char* args);
|
||||
result_t update_command(const char* command, char* args);
|
||||
result_t verbosity_command(const char* command, char* args);
|
||||
|
||||
static command_t commands[] = {
|
||||
@ -76,6 +77,7 @@ static command_t commands[] = {
|
||||
{ "find", "Finds record", find_command },
|
||||
{ "read", "Reads record", read_command },
|
||||
{ "delete", "Deletes record", delete_command },
|
||||
{ "update", "Updates record", update_command },
|
||||
{ "verbosity", "Changes the verbosity", verbosity_command },
|
||||
};
|
||||
|
||||
@ -188,6 +190,23 @@ result_t delete_command(const char* command, char* args)
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
result_t update_command(const char* command, char* args)
|
||||
{
|
||||
record_t record;
|
||||
|
||||
if (sscanf(args, "%u %lf %lf", &record.key, &record.x, &record.y) == 3) {
|
||||
if (btree_update(&tree, record.key, record)) {
|
||||
printf("Record %u updated.\n", record.key);
|
||||
} else {
|
||||
printf("404 Not found\n");
|
||||
}
|
||||
} else {
|
||||
printf("Usage: find key\n");
|
||||
}
|
||||
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
result_t records_command(const char* command, char* args)
|
||||
{
|
||||
page_t page;
|
||||
|
Loading…
Reference in New Issue
Block a user