source: src/examples/strings/src/internal/VbyteSM.h @ 020a349

string
Last change on this file since 020a349 was 020a349, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

added some code for the shared heap used by strings (still incomplete)

  • Property mode set to 100644
File size: 1.5 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 #########################
28
29struct VbyteHeap
30{
31        HandleNode_t Header;
32
33        int NoOfCompactions;
34        int NoOfExtensions;
35        int NoOfReductions;
36
37        int InitSize;
38        int CurrSize;
39        char_t* StartVbyte;
40        char_t* EndVbyte;
41        void* ExtVbyte;
42};
43
44static inline void ctor(VbyteHeap* const this, int size);
45static inline void dtor(VbyteHeap* const this);
46
47void compaction(VbyteHeap* const this);
48void garbage(VbyteHeap* const this);
49void extend(VbyteHeap* const this, int);
50void reduce(VbyteHeap* const this, int);
51
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}
Note: See TracBrowser for help on using the repository browser.