-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedListSafeSearch.cpp
More file actions
41 lines (37 loc) · 951 Bytes
/
linkedListSafeSearch.cpp
File metadata and controls
41 lines (37 loc) · 951 Bytes
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
// ROM contents
// Tuple Header (3 (2 byte words) = 6 bytes)
// 1: id
// 2: offset of next ptr (units of bytes, all 1s no next)
// 3: payload length in bytes - 16 bit
// Variable Payload
struct tuple_header {
uint16_t id;
uint16_t offset;
uint16_t payload_len;
};
#define ROM_SIZE 65536
// ROM = 65536 / 6
// Finds payload of tuple with given id
uint16_t *find_tuple(const uint16_t *rom, uint16_t id, size_t *len) {
uint16_t sentinel = 0xffff;
struct tuple_header *th = (struct tuple_header *)rom;
uint16_t * payload = NULL;
uint16_t count = 0;
uint16_t max = ROM_SIZE / sizeof(struct tuple_header);
for(;;) {
if(th->id == id) {
*len = th->payload_len;
payload = (uint16_t *)(++th);
return payload;
}
if (th->offset == sentinel) {
return payload;
}
th = (struct tuple_header *)((char *)rom + th->offset);
count++;
if (count > max) {
break;
}
}
return payload;
}