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