-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreeList.cpp
More file actions
63 lines (61 loc) · 1.28 KB
/
Copy pathFreeList.cpp
File metadata and controls
63 lines (61 loc) · 1.28 KB
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
#include"Common.h"
#include"FreeList.h"
void FreeList::Push(void* obj)
{
if (obj == nullptr) throw(FreeListException("Function Push: Push nullptr\n"));
//Í·²å
NextObj(obj) = m_freeList;
m_freeList = obj;
m_size++;
}
void FreeList::PushRange(void* start, void* end,size_t n)
{
if (start == nullptr || end==nullptr ) throw(FreeListException("Function PushRange: start or end is nullptr\n"));
/*void* cur = start;
int i = 0;
while (cur)
{
cur = NextObj(cur);
i++;
}
if (i != n)
{
int x = 0;
}*/
NextObj(end) = m_freeList;
m_freeList = start;
m_size += n;
}
void FreeList::PopRange(void*& start, void*& end, size_t n)
{
if (n>m_size) throw(FreeListException("Function PopRange: n is greater than m_size \n"));
start = end = m_freeList;
for (int i = 0; i < n-1; i++)
{
end = NextObj(end);
}
m_freeList = NextObj(end);
NextObj(end) = nullptr;
m_size -= n;
}
void* FreeList::Pop()
{
if (m_freeList == nullptr) throw(FreeListException("Pop is called in a empty FreeList\n"));
//ͷɾ
void* obj = m_freeList;
m_freeList = NextObj(m_freeList);
m_size--;
return obj;
}
bool FreeList::empty()
{
return m_freeList == nullptr;
}
size_t& FreeList::MaxSize()
{
return m_maxSize;
}
size_t FreeList::size()
{
return m_size;
}