source: src/examples/strings/src/internal/VbyteSM.h@ 7ea1b3a

string
Last change on this file since 7ea1b3a was 7ea1b3a, checked in by Thierry Delisle <tdelisle@…>, 10 years ago

finished translating VbyteSM.h except for malor array

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#pragma once
2
3typedef char char_t;
4
5//######################### HandleNode #########################
6struct VbyteHeap_t;
7
8struct HandleNode_t
9{
10 char_t* string;
11 unsigned short int length;
12
13 HandleNode_t* next;
14 HandleNode_t* previous;
15};
16
17static inline void ctor(HandleNode_t* const this);
18static inline void ctor(HandleNode_t* const this, VbyteHeap_t* heap);
19static inline void dtor(HandleNode_t* const this);
20
21void DeleteNode(HandleNode_t* const this);
22void AddThisAfter(HandleNode_t* const this, HandleNode_t* other);
23
24void MoveThisAfter(HandleNode_t* const this, const HandleNode_t* rhs);
25void MoveThisBefore(HandleNode_t* const this, const HandleNode_t* rhs);
26
27//######################### VbyteHeap #########################
28struct 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
43static inline void ctor(VbyteHeap* const this, int size);
44static inline void dtor(VbyteHeap* const this);
45
46void compaction(VbyteHeap* const this);
47void garbage(VbyteHeap* const this);
48void extend(VbyteHeap* const this, int);
49void reduce(VbyteHeap* const this, int);
50
51//######################### HandleNode #########################
52static inline ctor(HandleNode_t* const this)
53{
54 this->string = (void*)0;
55 this->length = 0;
56}
57
58static 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
66static inline dtor(HandleNode_t* const this)
67{
68 DeleteNode(this);
69}
70
71//######################### VbyteHeap #########################
72static 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
91static inline dtor(VbyteHeap* const this)
92{
93 free(this->StartVbyte);
94}
Note: See TracBrowser for help on using the repository browser.