This repository was archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.h
More file actions
61 lines (46 loc) · 1.31 KB
/
table.h
File metadata and controls
61 lines (46 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef peach_table_h
#define peach_table_h
#include "common.h"
#include "value.h"
typedef struct {
ObjectString* key;
Value value;
} Entry;
typedef struct {
size_t count;
size_t capacity;
Entry* entries;
} Table;
void Table_init(Table* table);
void Table_free(Table* table);
/**
* Set/update an entry in the table.
* Returns true if a new entry was created, or false Otherwise.
*/
bool Table_set(Table* table, ObjectString* key, Value value);
/**
* Retrive a value from table belogning to given key.
*
* If the key exists in the table, `value` is updated to point
* to the value it is set to and true is returned.
* Otherwise, false is returned and `value` is left unchanged.
*/
bool Table_get(Table* table, ObjectString* key, Value* value);
/**
* Delete an entry from the table.
* Returns false if the given key did not exist in the table
* and nothing was deleted. True otherwise.
*/
bool Table_delete(Table *table, ObjectString *key);
/**
* Adds all entries from the `source` table to a
* table.
*/
void Table_add_all(Table* table, Table* source);
void Table_print(Table* table);
ObjectString* Table_find_str(Table* table, const char* str, size_t length);
ObjectString* Table_find_str_combined(
Table* table, const char* a, size_t a_len,
const char* b, size_t b_len
);
#endif // !peach_table_h