-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathg6tools.h
97 lines (84 loc) · 1.86 KB
/
g6tools.h
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
#ifndef G6TOOLS
#define G6TOOLS
namespace g6
{
long long int GetSize (const char* g6);
bool** GetMatrix (const char* g6);
long long int GetSize (const char* g6)
{
long long unsigned int size = 0;
int index = 0;
if(g6[0]<126 && g6[0]>62)
{
size = g6[0]-63;
return size;
}else if(g6[1]<126 && g6[0]>62)
{
size = (g6[1]-63);
for(int i=2; i<4; i++)
{
if(g6[i]<63)
return 0;//unexpected end of string
size <<= 6;
size = (g6[i]-63) | size;//note: the eight bit of asccii is alway 1
//size = ((g6[i]-63) | 127) | size;//safe version?
}
return size;
}else if(g6[2]>62)
{
size = (g6[2]-63) | size;
for(int i=3; i<8; i++)
{
if(g6[i]<63)
return 0;//unexpected end of string
size <<= 6;
size = (g6[i]-63) | size;
}
return size;
}
return 0; //unexpected end of string
};
bool** GetMatrix (const char* g6)
{
long long unsigned int size = GetSize(g6);
if(size == 0)
return NULL; //bad data
bool** matrix;
long long unsigned int index;
if(g6[0]!='~')
index = 1;
else if(g6[1]!='~')
index = 4;
else
index = 8;
char bit=32;//values 1,2,4,8,16,32
matrix = new bool*[size];
for(long long unsigned int i =0; i< size; i++)
{
matrix[i] = new bool[size];
matrix[i][i] = false;
for(long long unsigned int j =0; j< i; j++)
{
if(((g6[index]-63)&bit)==bit)
{
matrix[j][i] = true;
matrix[i][j] = true;
}
else
{
matrix[j][i] = false;
matrix[i][j] = false;
}
if(bit>1)
bit >>= 1;
else
{
bit = 32;
index++;
}
}
}
return matrix;
}
}
#endif