1 | #pragma once |
---|
2 | |
---|
3 | typedef char char_t; |
---|
4 | |
---|
5 | //######################### HandleNode ######################### |
---|
6 | struct VbyteHeap_t; |
---|
7 | |
---|
8 | struct HandleNode_t |
---|
9 | { |
---|
10 | char_t* string; |
---|
11 | unsigned short int length; |
---|
12 | |
---|
13 | HandleNode_t* next; |
---|
14 | HandleNode_t* previous; |
---|
15 | }; |
---|
16 | |
---|
17 | static inline void ctor(HandleNode_t* const this); |
---|
18 | static inline void ctor(HandleNode_t* const this, VbyteHeap_t* heap); |
---|
19 | static inline void dtor(HandleNode_t* const this); |
---|
20 | |
---|
21 | void DeleteNode(HandleNode_t* const this); |
---|
22 | void AddThisAfter(HandleNode_t* const this, HandleNode_t* other); |
---|
23 | |
---|
24 | void MoveThisAfter(HandleNode_t* const this, const HandleNode_t* rhs); |
---|
25 | void MoveThisBefore(HandleNode_t* const this, const HandleNode_t* rhs); |
---|
26 | |
---|
27 | //######################### VbyteHeap ######################### |
---|
28 | struct VbyteHeap |
---|
29 | { |
---|
30 | int NoOfCompactions; |
---|
31 | int NoOfExtensions; |
---|
32 | int NoOfReductions; |
---|
33 | |
---|
34 | int InitSize; |
---|
35 | int CurrSize; |
---|
36 | char_t* StartVbyte; |
---|
37 | char_t* EndVbyte; |
---|
38 | void* ExtVbyte; |
---|
39 | |
---|
40 | HandleNode_t Header; |
---|
41 | }; |
---|
42 | |
---|
43 | static inline void ctor(VbyteHeap* const this, int size); |
---|
44 | static inline void dtor(VbyteHeap* const this); |
---|
45 | |
---|
46 | void compaction(VbyteHeap* const this); |
---|
47 | void garbage(VbyteHeap* const this); |
---|
48 | void extend(VbyteHeap* const this, int); |
---|
49 | void reduce(VbyteHeap* const this, int); |
---|
50 | |
---|
51 | //######################### HandleNode ######################### |
---|
52 | static inline ctor(HandleNode_t* const this) |
---|
53 | { |
---|
54 | this->string = (void*)0; |
---|
55 | this->length = 0; |
---|
56 | } |
---|
57 | |
---|
58 | static inline ctor(HandleNode_t* const this, VbyteHeap* vh) |
---|
59 | { |
---|
60 | this->string = (void*)0; |
---|
61 | this->length = 0; |
---|
62 | HandleNode_t* const node = &vh->Header; |
---|
63 | AddThisAfter(this, node->previous); |
---|
64 | } |
---|
65 | |
---|
66 | static inline dtor(HandleNode_t* const this) |
---|
67 | { |
---|
68 | DeleteNode(this); |
---|
69 | } |
---|
70 | |
---|
71 | //######################### VbyteHeap ######################### |
---|
72 | static inline ctor(VbyteHeap* const this, int size) |
---|
73 | { |
---|
74 | this->NoOfCompactions = 0; |
---|
75 | this->NoOfExtensions = 0; |
---|
76 | this->NoOfReductions = 0; |
---|
77 | |
---|
78 | this->InitSize = size; |
---|
79 | this->CurrSize = size; |
---|
80 | |
---|
81 | #warning missing malloc |
---|
82 | this->StartVbyte = 0; |
---|
83 | this->EndVbyte = this->StartVbyte; |
---|
84 | this->ExtVbyte = (void*)( this->StartVbyte + this->CurrSize ); |
---|
85 | |
---|
86 | ctor(&this->Header); |
---|
87 | this->Header.next = &this->Header; |
---|
88 | this->Header.previous = &this->Header; |
---|
89 | } |
---|
90 | |
---|
91 | static inline dtor(VbyteHeap* const this) |
---|
92 | { |
---|
93 | free(this->StartVbyte); |
---|
94 | } |
---|