forked from bliksemlabs/rrrr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set.c
78 lines (62 loc) · 1.7 KB
/
set.c
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
#include "config.h"
#include "rrrr_types.h"
#include "set.h"
#if RRRR_MAX_BANNED_STOP_POINTS > 0 || RRRR_BAX_BANNED_STOPS_HARD > 0
void set_add_sp (spidx_t *set,
uint8_t *length, uint8_t max_length,
spidx_t value) {
uint8_t i;
if (*length >= max_length) return;
for (i = 0; i < *length; ++i) {
if (set[i] == value) return;
}
set[*length] = value;
(*length)++;
}
bool set_in_sp (spidx_t *set, uint8_t length, spidx_t value) {
uint8_t i = length;
if (i == 0) return false;
do {
i--;
if (set[i] == value) return true;
} while (i);
return false;
}
#endif
#if RRRR_MAX_BANNED_VEHICLE_JOURNEYS > 0
void set_add_jp (jpidx_t *set,
uint8_t *length, uint8_t max_length,
jpidx_t value) {
uint8_t i;
if (*length >= max_length) return;
for (i = 0; i < *length; ++i) {
if (set[i] == value) return;
}
set[*length] = value;
(*length)++;
}
void set_add_vj (jpidx_t *set1, jp_vjoffset_t *set2,
uint8_t *length, uint8_t max_length,
jpidx_t value1, jp_vjoffset_t value2) {
uint8_t i;
if (*length >= max_length) return;
for (i = 0; i < *length; ++i) {
if (set1[i] == value1 &&
set2[i] == value2) return;
}
set1[*length] = value1;
set2[*length] = value2;
(*length)++;
}
bool set_in_vj (jpidx_t *set1, jp_vjoffset_t *set2, uint8_t length,
jpidx_t value1, jp_vjoffset_t value2) {
uint8_t i = length;
if (i == 0) return false;
do {
i--;
if (set1[i] == value1 &&
set2[i] == value2) return true;
} while (i);
return false;
}
#endif