-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
67 lines (58 loc) · 1.93 KB
/
server.h
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
/* Copyright 2023 <Cretu Mihnea Tudor> */
#ifndef SERVER_H_
#define SERVER_H_
#include "hashtable.h"
typedef struct server_memory {
int id;
int label;
unsigned int hash;
hashtable_t *ht;
} 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);
/**
* label_formula() - Computes the label for a server.
* The label is computed as follows:
* - server_id + pos * 100000
* - server_id is the id of the server
* - pos is the position of the server on the hash ring
*/
int label_formula(int server_id, int pos);
#endif /* SERVER_H_ */