1
0
mirror of https://github.com/fumiama/fumidb.git synced 2026-06-07 18:02:38 +08:00

add some funcs of table

This commit is contained in:
源文雨
2022-05-03 21:14:30 +08:00
parent 19e09bc630
commit d17f36b255
7 changed files with 174 additions and 16 deletions

View File

@@ -25,6 +25,8 @@ int set_first_unused_block(int fd, uint64_t ptr);
// 获得 ptr of unused blk 字段
uint64_t get_first_unused_block(int fd);
uint64_t get_next_unused_block(int fd, uint64_t ptr);
// 设置 ptr of next table 字段
// 返回:
// 0 成功
@@ -35,4 +37,6 @@ int set_first_table(int fd, uint64_t ptr);
// 获得 ptr of next table 字段
uint64_t get_first_table(int fd);
uint64_t get_next_table(int fd, uint64_t ptr);
#endif

View File

@@ -7,16 +7,18 @@
// 创建表,可变参数为本表的一行的 types详见 types.h
// 如果 types 为外键,需要紧跟一个 uint64_t ptr
// 指示外键链接到的表位置
// len(buf) >= 4096+8+2=4106
// 返回:
// NULL 失败,详见 errno
// table 指向表头的指针
void* create_table(int fd, const char* name, ...);
void* create_table(int fd, char* buf, const char* name, uint16_t row_len, ...);
// 加载 ptr 位置的表
// len(buf) >= 4096+8+2=4106
// 返回:
// NULL 失败,详见 errno
// table 指向表头的指针
void* load_table(int fd, uint64_t ptr);
void* load_table(int fd, char* buf, uint64_t ptr);
// 获得表名长度包含结尾0
uint16_t get_table_name_length(void* table);
@@ -45,7 +47,7 @@ int remove_table_index(int fd, void* table, uint16_t pos);
// 返回:
// 0 失败,详见 errno
// ptr 本行插入的位置
uint64_t insert_row(int fd, void* table, ...);
uint64_t insert_row(int fd, void* table, uint16_t row_len, ...);
// 根据主键的匹配值查找行
// 如果主键不为 stringk 直接装填其值
@@ -63,7 +65,7 @@ uint64_t find_row_by_pk(int fd, void* table, key_t k);
// 返回:
// 非 0 失败,详见 errno
// 0 成功
int find_row_by(int fd, void* table, int (*f)(uint64_t), ...);
int find_row_by(int fd, void* table, int (*f)(uint64_t), uint16_t row_len, ...);
// 根据主键的匹配值删除行
// 如果主键不为 stringk 直接装填其值
@@ -80,6 +82,6 @@ int remove_row_by_pk(int fd, void* table, key_t k);
// 返回:
// 非 0 失败,详见 errno
// 0 成功
int remove_row_by(int fd, void* table, ...);
int remove_row_by(int fd, void* table, uint16_t row_len, ...);
#endif

View File

@@ -21,6 +21,9 @@
typedef uint8_t type_t;
typedef uint64_t key_t;
// 获得本类型 index 相对于 buffer 头的偏移
int type_offset(type_t t);
// 为类型 type 创建索引
// 返回:索引头节点的指针 index
void* create_index(int fd, type_t t, void* buf);