-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_list.h
56 lines (46 loc) · 1.35 KB
/
node_list.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
#pragma once
/**
* @file node_list.h
* @brief Parsing and handling of a list of nodes (= list of servers until week 11).
* This data structure is required only from week 06.
*
* @author Valérian Rousset
*/
#include <netinet/in.h>
#include <stddef.h>
#include "node.h"
/**
* @brief list of nodes
*/
typedef struct {
size_t size;
node_t* nodes;
} node_list_t;
/**
* @brief creates a new, empty, node_list_t
* @return (a pointer to) the new list of nodes
*/
node_list_t *node_list_new();
/**
* @brief parse the PPS_SERVERS_LIST_FILENAME file and return the corresponding list of nodes
* @return the list of nodes initialized from the server file (PPS_SERVERS_LIST_FILENAME)
*/
node_list_t *get_nodes();
/**
* @brief add a node to a list of nodes
* @param list list of nodes where to add to (modified)
* @param node the node to be added
* @return some error code indicating whether addition fails or not
*/
error_code node_list_add(node_list_t *list, node_t node);
/**
* @brief sort node list according to node comparison function
* @param list list of nodes to be sorted
* @param comparator node comparison function
*/
void node_list_sort(node_list_t *list, int (*comparator)(const node_t *, const node_t *));
/**
* @brief free the given list of nodes
* @param list list of nodes to clean
*/
void node_list_free(node_list_t *list);