-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
53 lines (40 loc) · 2.18 KB
/
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
#ifndef CUSTOM_LIST_H
#define CUSTOM_LIST_H
#include <stdbool.h>
typedef struct ListItem ListItem;
// ListItem stores a numerical id in the <0, 1048575> range and
// two pointers (anchors) - beginning and end of it's children list
ListItem* createListItem(const unsigned id);
// Allocates memory for a list item and assigns it an id
// ( id cannot be changed after creation! )
unsigned getIdFromListItem(ListItem * const targetItem);
ListItem* getChildrenListBeginningFromListItem(ListItem * const targetItem);
ListItem* getChildrenListEndFromListItem(ListItem * const targetItem);
ListItem* nextListItem(ListItem * const targetItem);
ListItem* previousListItem(ListItem * const targetItem);
// If targetItem is the last / first item in a list, returns NULL.
ListItem* nextListItemOrAnchor(ListItem * const targetItem);
ListItem* previousListItemOrAnchor(ListItem * const targetItem);
// If targetItem is the last / first item in a list, returns a
// pointer to it's parent (item it was anchored to).
// Returns a NULL if there is no parent and targetItem is first / last.
bool isListItemLeftAnchored(ListItem * const targetItem);
bool isListItemRightAnchored(ListItem * const targetItem);
// NOTE:
// An anchored item will be first/last in the list, BUT
// first/last item in the list DOESN'T have to be anchored.
void leftAnchorListItem(ListItem * const anchor,
ListItem * const targetItem);
void rightAnchorListItem(ListItem * const anchor,
ListItem * const targetItem);
void disconnectListItem(ListItem * const targetItem);
// Connects targetItem's neighbours (or neighbour and an anchor) together.
// targetItem's neighbour pointers are set to NULL.
// If targetItem is anchored from both sides
// (targetItem is the only item in the list), parent's anchors are set to NULL.
void connectListItems(ListItem * const leftItem,
ListItem * const rightItem);
void insertListFragmentInPlaceOfListItem(ListItem * const targetItem,
ListItem * const listBeginning,
ListItem * const listEnd);
#endif /* CUSTOM_LIST_H */