Subversion Repositories Kolibri OS

Rev

Rev 7521 | Rev 7881 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7521 Rev 7741
Line 1... Line 1...
1
// Author: Pavel Iakovlev by. pavelyakov
1
// Author: Pavel Iakovlev by. pavelyakov
Line 2... Line 2...
2
 
2
 
3
#ifndef INCLUDE_ARRAY_H
3
#ifndef INCLUDE_ARRAY_H
Line -... Line 4...
-
 
4
#define INCLUDE_ARRAY_H
-
 
5
 
4
#define INCLUDE_ARRAY_H
6
#include "../lib/crc32.h"
5
 
7
 
6
// Array memory: [dword key][byte flags][dword left][dword right][dword value] -> 17 bytes = 1 position
8
// Array memory: [dword key][byte flags][dword left][dword right][dword value] -> 17 bytes = 1 position
7
// If key don't exists then value == 0
9
// If key don't exists then value == 0
8
:struct Array
10
:struct Array
Line 18... Line 20...
18
	byte init(dword size);
20
	byte init(dword size);
19
};
21
};
Line 20... Line 22...
20
 
22
 
21
:void Array::reallocMemory(dword newSize)
23
:void Array::reallocMemory(dword newSize)
-
 
24
{
22
{
25
	newSize *= 17;
23
	memory = realloc(memory, newSize);
26
	memory = realloc(memory, newSize);
24
	lenInitSize = newSize;
27
	lenInitSize = newSize;
Line 25... Line 28...
25
}
28
}
Line 32... Line 35...
32
	//IF (flags & 100b) RETURN address; // if delete
35
	//IF (flags & 100b) RETURN address; // if delete
33
	IF (flags & 010b) && (DSDWORD[address] < key) RETURN recursiveIndex(key, DSDWORD[address + 5]); // left tree
36
	IF (flags & 010b) && (DSDWORD[address] < key) RETURN recursiveIndex(key, DSDWORD[address + 5]); // left tree
34
	IF (flags & 001b) && (DSDWORD[address] > key) RETURN recursiveIndex(key, DSDWORD[address + 9]); // right tree
37
	IF (flags & 001b) && (DSDWORD[address] > key) RETURN recursiveIndex(key, DSDWORD[address + 9]); // right tree
35
	RETURN address;
38
	RETURN address;
36
}
39
}
-
 
40
 
37
:byte Array::init(dword size)
41
:byte Array::init(dword size)
38
{
42
{
-
 
43
	dword pointer = 0;
39
	IF(!size) RETURN 0;
44
	if (!size) size = 8;
40
	IF(!memory)
45
	IF(!memory)
41
	{
46
	{
42
		lenInitSize = size * 17;
47
		lenInitSize = size * 17;
43
		memory = malloc(lenInitSize);
48
		memory = malloc(lenInitSize);
44
		EBX = memory;
49
		pointer = memory;
45
		DSDWORD[EBX] = 0;
50
		DSDWORD[pointer] = 0; pointer += 4;
46
		DSBYTE[EBX + 4] = 0;
51
		DSBYTE[pointer] = 0; pointer += 1;
47
		DSDWORD[EBX + 5] = 0;
52
		DSDWORD[pointer] = 0;pointer += 4;
48
		DSDWORD[EBX + 9] = 0;
53
		DSDWORD[pointer] = 0;pointer += 4;
49
		DSDWORD[EBX + 13] = 0;
54
		DSDWORD[pointer] = 0;
50
		offsetMemory = 17;
55
		offsetMemory = 17;
51
		RETURN 0xFF;
56
		RETURN 0xFF;
52
	}
57
	}
53
	IF(size > lenInitSize)
58
	IF(size > lenInitSize)
54
	{
59
	{
55
		reallocMemory(size * 17);
60
		reallocMemory(size);
56
		RETURN 0xFF;
61
		RETURN 0xFF;
57
	}
62
	}
58
	RETURN 0;
63
	RETURN 0;
59
}
64
}
60
:byte Array::set(dword key, data)
65
:byte Array::set(dword key, data)
Line 95... Line 100...
95
	ELSE
100
	ELSE
96
	{
101
	{
97
		DSDWORD[address + 13] = data;
102
		DSDWORD[address + 13] = data;
98
		RETURN 0xFF;
103
		RETURN 0xFF;
99
	}
104
	}
100
	DSDWORD[newOffset] = key;
105
	DSDWORD[newOffset] = key; newOffset+=4;
101
	DSBYTE[newOffset+4] = 0;
106
	DSBYTE[newOffset] = 0; newOffset+=1;
102
	DSDWORD[newOffset+5] = 0;
107
	DSDWORD[newOffset] = 0; newOffset+=4;
103
	DSDWORD[newOffset+9] = 0;
108
	DSDWORD[newOffset] = 0; newOffset+=4;
104
	DSDWORD[newOffset+13] = data;
109
	DSDWORD[newOffset] = data;
105
	offsetMemory += 17;
110
	offsetMemory += 17;
106
	RETURN 0xFF;
111
	RETURN 0xFF;
107
}
112
}
108
:dword Array::get(dword key)
113
:dword Array::get(dword key)
109
{
114
{
Line 128... Line 133...
128
	byte set(dword key, value);
133
	byte set(dword key, value);
129
	dword get(dword key);
134
	dword get(dword key);
130
	byte init(dword size);
135
	byte init(dword size);
131
};
136
};
Line 132... Line 137...
132
 
137
 
133
:dword Dictionary::hash(dword text) // max 255 bytes as strings => 4 byte or duble word hash
138
:dword Dictionary::hash(dword text)
-
 
139
{
-
 
140
	RETURN crc32(text, strlen(text));
134
{
141
/*
135
	dword checkSum1 = 1;
142
	dword checkSum1 = 1;
136
	dword checkSum2 = 0;
143
	dword checkSum2 = 0;
Line 137... Line 144...
137
	dword beginAddress = 0;
144
	dword beginAddress = 0;
Line 146... Line 153...
146
	//IF(h1 > 0x03FFF) RETURN h1 << 8 ^ h2;
153
	//IF(h1 > 0x03FFF) RETURN h1 << 8 ^ h2;
147
	//IF(h2 > 0x3FFFF) RETURN h1 << 8 ^ h2;
154
	//IF(h2 > 0x3FFFF) RETURN h1 << 8 ^ h2;
148
	EAX = text - beginAddress;
155
	EAX = text - beginAddress;
149
	EAX <<= 23;
156
	EAX <<= 23;
150
	RETURN EAX | checkSum2;
157
	RETURN EAX | checkSum2;
-
 
158
*/
151
}
159
}
Line 152... Line 160...
152
 
160
 
153
:byte Dictionary::set(dword key, value)
161
:byte Dictionary::set(dword key, value)
154
{
162
{