blob: ecf2474038e6deceac065e51831b1d70ef18bc65 (
plain) (
blame)
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
|
#pragma once
#include "common.h"
class CPtrNode
{
public:
void *item;
CPtrNode *prev;
CPtrNode *next;
void *operator new(size_t);
void operator delete(void *p, size_t);
};
class CPtrList
{
public:
CPtrNode *first;
CPtrList(void) { first = nil; }
~CPtrList(void) { Flush(); }
CPtrNode *FindItem(void *item){
CPtrNode *node;
for(node = first; node; node = node->next)
if(node->item == item)
return node;
return nil;
}
CPtrNode *InsertNode(CPtrNode *node){
node->prev = nil;
node->next = first;
if(first)
first->prev = node;
first = node;
return node;
}
CPtrNode *InsertItem(void *item){
CPtrNode *node = new CPtrNode;
node->item = item;
InsertNode(node);
return node;
}
void RemoveNode(CPtrNode *node){
if(node == first)
first = node->next;
if(node->prev)
node->prev->next = node->next;
if(node->next)
node->next->prev = node->prev;
}
void DeleteNode(CPtrNode *node){
RemoveNode(node);
delete node;
}
void RemoveItem(void *item){
CPtrNode *node, *next;
for(node = first; node; node = next){
next = node->next;
if(node->item == item)
DeleteNode(node);
}
}
void Flush(void){
CPtrNode *node, *next;
for(node = first; node; node = next){
next = node->next;
DeleteNode(node);
}
}
};
class CSector;
// This records in which sector list a Physical is
class CEntryInfoNode
{
public:
CPtrList *list; // list in sector
CPtrNode *listnode; // node in list
CSector *sector;
CEntryInfoNode *prev;
CEntryInfoNode *next;
void *operator new(size_t);
void operator delete(void *p, size_t);
};
class CEntryInfoList
{
public:
CEntryInfoNode *first;
CEntryInfoList(void) { first = nil; }
~CEntryInfoList(void) { Flush(); }
CEntryInfoNode *InsertNode(CEntryInfoNode *node){
node->prev = nil;
node->next = first;
if(first)
first->prev = node;
first = node;
return node;
}
CEntryInfoNode *InsertItem(CPtrList *list, CPtrNode *listnode, CSector *sect){
CEntryInfoNode *node = new CEntryInfoNode;
node->list = list;
node->listnode = listnode;
node->sector = sect;
InsertNode(node);
return node;
}
void RemoveNode(CEntryInfoNode *node){
if(node == first)
first = node->next;
if(node->prev)
node->prev->next = node->next;
if(node->next)
node->next->prev = node->prev;
}
void DeleteNode(CEntryInfoNode *node){
RemoveNode(node);
delete node;
}
void Flush(void){
CEntryInfoNode *node, *next;
for(node = first; node; node = next){
next = node->next;
DeleteNode(node);
}
}
};
|