source: src/examples/strings/src/internal/VbyteSM.h@ 8243cf9

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

implemented some of code of vbytesm

  • Property mode set to 100644
File size: 1.9 KB
Line 
1#pragma once
2
3#include <stdlib>
4
5typedef char char_t;
6
7//######################### HandleNode #########################
8struct VbyteHeap_t;
9
10struct HandleNode_t
11{
12 char_t* string;
13 unsigned short int length;
14
15 HandleNode_t* next;
16 HandleNode_t* previous;
17};
18
19void DeleteNode(HandleNode_t* const this);
20void AddThisAfter(HandleNode_t* const this, HandleNode_t* other);
21
22void MoveThisAfter(HandleNode_t* const this, const HandleNode_t* rhs);
23void MoveThisBefore(HandleNode_t* const this, const HandleNode_t* rhs);
24
25//######################### VbyteHeap #########################
26struct 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
41void compaction(VbyteHeap* const this);
42void garbage(VbyteHeap* const this);
43void extend(VbyteHeap* const this, int);
44void reduce(VbyteHeap* const this, int);
45
46//######################### HandleNode #########################
47static inline ctor(HandleNode_t* const this)
48{
49 this->string = (void*)0;
50 this->length = 0;
51}
52
53static 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
61static inline dtor(HandleNode_t* const this)
62{
63 DeleteNode(this);
64}
65
66//######################### VbyteHeap #########################
67static 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
86static inline dtor(VbyteHeap* const this)
87{
88 free(this->StartVbyte);
89}
Note: See TracBrowser for help on using the repository browser.