MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / FastList

Class FastList

Kernel/include/list.h:80–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78// Type is required to be a pointer with the members next and prev
79template<typename T>
80class FastList {
81public:
82 FastList()
83 {
84 front = NULL;
85 back = NULL;
86 num = 0;
87 }
88
89 ~FastList() {
90 }
91
92 void clear() {
93 front = NULL;
94 back = NULL;
95 num = 0;
96 }
97
98 void add_back(const T& obj) {
99 if (!front) {
100 front = obj;
101 obj->prev = obj;
102 } else if (back) {
103 back->next = obj;
104 obj->prev = back;
105 }
106 back = obj;
107 obj->next = front;
108 num++;
109 }
110
111 void add_front(const T& obj) {
112 if (!back) {
113 back = obj;
114 }
115 else if(front) {
116 front->prev = obj;
117 obj->next = front;
118 }
119 front = obj;
120 obj->prev = back;
121 num++;
122 }
123
124 T operator[](unsigned pos) {
125 return get_at(pos);
126 }
127
128 T get_at(unsigned pos) {
129 assert(num > 0 && pos < num && front);
130 /*if (num <= 0 || pos >= num || front == NULL) {
131 return nullptr;
132 }*/
133
134 T current = front;
135
136 for (unsigned int i = 0; i < pos && i < num && current->next; i++) current = current->next;
137

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected