-
Notifications
You must be signed in to change notification settings - Fork 1
/
list-private.h
175 lines (139 loc) · 4.77 KB
/
list-private.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//
// list-private.h
// SD15-Project
//
// Created by Grupo SD015 on 24/09/14.
// Copyright (c) 2014 Grupo SD015. All rights reserved.
//
#ifndef __SD15_Project__list_private__
#define __SD15_Project__list_private__
#include <stdio.h>
#include "entry.h"
#include "entry-private.h"
/*
* Structure that defines a list
*/
struct list_t {
int size;
struct node_t *head;
struct node_t *tail;
};
/*
* Structure that defines a doubly linked-list node.
*/
typedef struct node_t {
struct node_t *prev;
struct node_t *next;
struct entry_t *entry;
} node_t;
/*
* Defining constants
*/
//constants on Adding/Moving nodes
#define ADD_WITH_CRITERION_KEY 1
#define MOVE_WITH_CRITERION_KEY ADD_WITH_CRITERION_KEY
#define ADD_WITHOUT_CRITERION 0
#define MOVE_WITHOUT_CRITERION ADD_WITHOUT_CRITERION
#define ADD_WITH_CRITERION_TIME 2
#define MOVE_WITH_CRITERION_TIME ADD_WITH_CRITERION_TIME
#define GET_BY_TIME 1
#define GET_BY_TUPLE_MATCH 2
#define KEEP_AT_ORIGIN 2
#define DONT_KEEP_AT_ORIGIN 1
#define JUST_DELETE_NODES 0
#define MUST_DESTROY 1
#define NOT_DESTROY 0
/*
* Creates a node having the prev and next node and its entry.
*/
node_t * node_create( struct node_t * prev, struct node_t* next, struct entry_t * entry) ;
/*
* Creates an empty node - just allocates memory for the structure.
*/
node_t * node_create_empty();
/*
* Duplicates a node.
*/
node_t * node_dup(node_t* node);
/*
* Destroyes a node.
*/
int node_destroy (struct node_t * node);
/*
* Method that checks if a certain tuple matches a template.
* If the tuple and the template have different sizes they dont match.
* If a field of the template is not null and is not equal to element
* at same position of the tuple, they dont match.
* Returns 1 (true) if they match, 0 otherwise.
*/
int tuple_matches_template ( struct tuple_t * tuple , struct tuple_t * template );
/*
* Method thats inserts a node in the list, beforeOrAfter aNode.
* If beforeOrAfter is 0, inserts before aNode, if 1 adds it after it.
* It can get aNode null if list_size(list) == 0.
* Returns 0 in success case, -1 in error case.
*/
int list_insert_node(struct list_t* list, node_t * newNode, node_t* aNode, int beforeOrAfter);
/*
* Method that gets a node from the given list that matches the tup_template.
* It returns the first matching node (head to tail) or NULL if none match.
*/
node_t *list_matching_node(struct list_t *list, struct tuple_t *tup_template);
/*
* Checks if list is empty.
* Returns 1 if its empty, 0 otherwise.
*/
int list_isEmpty(struct list_t* list);
/* Returns the size of the list - the number of elements.
* Retorna -1 em caso de erro.
*/
int list_size(struct list_t *list);
/*
* Method that returns the key of the node.
* Delegates the request to the type of entry it uses.
*/
char * node_key( node_t * node );
/*
* Method that returns the entry of a given node.
*/
struct entry_t * node_entry(node_t* node);
/*
* Method that compares two entry keys with strcmp
* on the same order than the parameters are received.
*/
int entry_keys_compare(struct entry_t * entryA, struct entry_t* entryB);
/*
* Method that increments +1 to the size of the the given list.
*/
int node_matches_criterion( node_t * nodeToAdd, node_t * currentNode, int criterion, long long reference_timestamp);
void list_size_inc(struct list_t * list);
/*
* Method that decrements -1 to the size of the given list.
*/
void list_size_dec( struct list_t * list);
/*
* Method that returns the tail of the given list.
*/
node_t * list_tail ( struct list_t* list);
/*
* Method that returns the head of the given list.
*/
node_t * list_head(struct list_t * list );
/*
* Method to print the given list.
*/
void list_print ( struct list_t * list) ;
node_t* list_get_one ( struct list_t * list, struct tuple_t * tup_template, int mustRemove);
/*
* Gets all the elements of the list that match tup_template
*/
struct list_t * list_get_all ( struct list_t * list, struct tuple_t * tup_template, int mustRemove);
struct list_t * list_matching_nodes (struct list_t *list, struct tuple_t *tup_template, int mustRemove, int getJustOne );
struct list_t * list_entries_newer_than (struct list_t *list, long long timestamp,
int whatToDoWithTheNode, int getJustOne );
int list_move_node (struct list_t * fromList, struct list_t * toList, node_t * node,
int mustMoveWithCriterium, long long reference_timestamp, int mustRemoveFromOrigin );
int list_move_nodes (struct list_t * fromList, struct list_t * toList,
int mustMoveWithCriterium, long long reference_timestamp, int mustRemoveFromOrigin);
int list_add_with_criterion(struct list_t *list, struct entry_t *entry, int move_criterion, long long reference_timestamp);
#endif /* defined(__SD15_Project__list_private__) */