YACDB
Yet Another C(rappy) Database
record.h
Go to the documentation of this file.
1
9#pragma once
10#include <stdlib.h>
11#include <stdio.h>
12#include <string.h>
13
18struct record
19{
20 unsigned char type;
21 void *data;
22};
23
30#define LAST_RECORD_TYPE 7
31
46{
47 RECORD_TYPE_NULL = 0,
48 RECORD_TYPE_CHAR = 1,
49 RECORD_TYPE_SHORT = 2,
50 RECORD_TYPE_INT = 3,
51 RECORD_TYPE_LONG = 4,
52 RECORD_TYPE_FLOAT = 5,
61};
62
66size_t record_size(struct record *record);
67
68size_t record_type_size(char type);
69
70int record_get_char(struct record *record, char **buffer);
71int record_get_string(struct record *record, char **buffer);
72int record_get_short(struct record *record, short *buffer);
73int record_get_long(struct record *record, long *buffer);
74
79int *record_get_int(struct record *record, int *buffer);
80
85float *record_get_float(struct record *record, float *buffer);
86
91struct record *record_from_char(char *data);
92
97struct record *record_from_short(short *data);
98
103struct record *record_from_int(int *data);
104
109struct record *record_from_long(long *data);
110
115struct record *record_from_float(float *data);
116
121struct record *record_from_string(char **data);
122
133int compress_records(struct record **records, size_t nb_records, size_t *size, void **buffer);
134
139struct record *extract_record(void *buffer, size_t n);
140
148int replace_record(void **buffer, size_t *size, size_t n, struct record *record);
149
155int compare_r(struct record *r1, struct record *r2);
156
157void free_record(struct record *record);
struct record * record_from_string(char **data)
Creates a pointer to a record from a string.
Definition: record.c:362
int compress_records(struct record **records, size_t nb_records, size_t *size, void **buffer)
Takes a list of records and returns a single buffer that is the concatenation of all the records.
record_type
The type stored inside the record.
Definition: record.h:46
@ RECORD_TYPE_0
Definition: record.h:56
@ RECORD_TYPE_1
Definition: record.h:60
struct record * record_from_float(float *data)
Creates a pointer to a record from a float.
Definition: record.c:333
struct record * record_from_short(short *data)
Creates a pointer to a record from a short.
Definition: record.c:246
struct record * record_from_long(long *data)
Creates a pointer to a record from a long.
Definition: record.c:304
int * record_get_int(struct record *record, int *buffer)
struct record * extract_record(void *buffer, size_t n)
Extracts the nth record from a compressed group of records.
Definition: record.c:443
int compare_r(struct record *r1, struct record *r2)
Compares 2 records r1 r2.
Definition: record.c:553
struct record * record_from_char(char *data)
Creates a pointer to a record from a ::char.
Definition: record.c:217
float * record_get_float(struct record *record, float *buffer)
size_t record_size(struct record *record)
The size of the data stored in the record in bytes.
Definition: record.c:33
struct record * record_from_int(int *data)
Creates a pointer to a record from an int.
Definition: record.c:275
int replace_record(void **buffer, size_t *size, size_t n, struct record *record)
Replaces the nth record from a compressed group of records.
Definition: record.c:483
Handles the general record type that abstracts away from the actual type of the data.
Definition: record.h:19