-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrList.h
More file actions
executable file
·101 lines (90 loc) · 1.69 KB
/
StrList.h
File metadata and controls
executable file
·101 lines (90 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* StrList.h
*
* Created on: 13 Aug 2013
* Author: lester
*/
#ifndef STRLIST_H_
#define STRLIST_H_
#include "MemPage.h"
/*!
char* values will be store on nodes.
the nodes will on a list
use sizeof - sizeof (a)
*/
struct _str_node
{
struct _str_node* next;
unsigned short size;
char c[2];
};
/*!
Alphabetical ordered string list
this object store char* ordered alphabetically
main idea is save memory reusing similar strings values.
JSON objects have this characteristic
*/
class StrList
{
public:
StrList(MemPage* mem);
virtual ~StrList();
void push(const char* val, unsigned short size, char* &str);
void clear();
void Print();
private:
MemPage *mem;
struct _str_node* f_node; // first node
struct _str_node*newNode(struct _str_node* next, const char* val, unsigned short size);
unsigned int save_space;
unsigned int waste_space;
unsigned int string_count; // how many string has been push
};
/*
* TODO ; string iterators
* zstring iterator end = (null) compare (a==b) or (*a == 0) && (b==null)
* lstring iterator easy way
*/
class zstring
{
class iterator
{
iterator() :
ptr(0)
{
}
iterator(char * p) :
ptr(p)
{
}
iterator(const iterator& it) : ptr(it.ptr){
}
bool operator==(const iterator& it)
{
return ((ptr == it.ptr) || ((ptr == 0) && (*it.ptr == 0)));
}
bool operator>(const iterator& it)
{
return ((ptr == 0) || (ptr > it.ptr));
}
bool operator<(const iterator& it)
{
return ((ptr != 0) && (ptr < it.ptr));
}
void operator++()
{
++ptr;
}
iterator operator++(int)
{
return (*this).ptr++;
/*
iterator i = *this;
ptr++;
return i;
*/
}
char* ptr;
};
};
#endif /* STRLIST_H_ */