-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.h
More file actions
90 lines (74 loc) · 2.47 KB
/
Copy pathserver.h
File metadata and controls
90 lines (74 loc) · 2.47 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Copyright 2023 <Gheţa Andrei-Cristian> */
#ifndef SERVER_H_
#define SERVER_H_
typedef struct ll_node_t {
void* data;
struct ll_node_t* next;
} ll_node_t;
typedef struct ll_node_t ll_node_t;
typedef struct linked_list_t {
ll_node_t* head;
unsigned int data_size;
unsigned int size;
} linked_list_t;
typedef struct linked_list_t linked_list_t;
linked_list_t *ll_create(unsigned int data_size);
void ll_add_nth_node(linked_list_t* list, unsigned int n, const void* new_data);
ll_node_t *ll_remove_nth_node(linked_list_t* list, unsigned int n);
unsigned int ll_get_size(linked_list_t* list);
void ll_free(linked_list_t** pp_list);
struct info {
char *key;
char *value;
};
typedef struct info info;
struct server_memory {
linked_list_t **buckets;
unsigned int size;
int server_id;
unsigned int hash;
};
typedef struct server_memory server_memory;
/** init_server_memory() - Initializes the memory for a new server struct.
* Make sure to check what is returned by malloc using DIE.
* Use the linked list implementation from the lab.
*
* Return: pointer to the allocated server_memory struct.
*/
server_memory *init_server_memory();
/** free_server_memory() - Free the memory used by the server.
* Make sure to also free the pointer to the server struct.
* You can use the server_remove() function for this.
*
* @arg1: Server to free
*/
void free_server_memory(server_memory *server);
/**
* server_store() - Stores a key-value pair to the server.
*
* @arg1: Server which performs the task.
* @arg2: Key represented as a string.
* @arg3: Value represented as a string.
*/
void server_store(server_memory *server, char *key, char *value);
/**
* server_remove() - Removes a key-pair value from the server.
* Make sure to free the memory of everything that is related to the entry removed.
*
* @arg1: Server which performs the task.
* @arg2: Key represented as a string.
*/
void server_remove(server_memory *server, char *key);
/**
* server_retrieve() - Gets the value associated with the key.
* @arg1: Server which performs the task.
* @arg2: Key represented as a string.
*
* Return: String value associated with the key
* or NULL (in case the key does not exist).
*/
char *server_retrieve(server_memory *server, char *key);
int server_has_key(server_memory *server, char *key);
unsigned int hash_function_key(void *a);
info *server_retrieve_all(server_memory *server, int *nr_information);
#endif /* SERVER_H_ */