Subversion Repositories Kolibri OS

Rev

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

Rev 7420 Rev 7430
Line 5... Line 5...
5
// If key don't exists then value == 0
5
// If key don't exists then value == 0
6
:struct Array
6
:struct Array
7
{
7
{
8
	dword memory;
8
	dword memory;
9
	dword offsetMemory;
9
	dword offsetMemory;
-
 
10
	dword lenInitSize;
10
	dword recursiveIndex(dword i, address);
11
	dword recursiveIndex(dword i, address);
11
	byte set(dword key, data);
12
	byte set(dword key, data);
12
	dword get(dword key);
13
	dword get(dword key);
-
 
14
	void reallocMemory(dword newSize);
13
	//dword del(dword key);
15
	//dword del(dword key);
14
	byte init(dword size);
16
	byte init(dword size);
15
};
17
};
Line -... Line 18...
-
 
18
 
-
 
19
:void Array::reallocMemory(dword newSize)
-
 
20
{
-
 
21
	memory = realloc(memory, newSize);
-
 
22
	lenInitSize = newSize;
-
 
23
}
16
 
24
 
17
:dword Array::recursiveIndex(dword key, address)
25
:dword Array::recursiveIndex(dword key, address)
18
{
26
{
19
	dword flags = 0;
-
 
20
	flags = DSBYTE[address + 4];
27
	dword flags = 0;
-
 
28
	IF (DSDWORD[address] == key) RETURN address;
21
	IF (DSDWORD[address] == key) RETURN address;
29
	flags = DSBYTE[address + 4];
22
	//IF (flags & 100b) RETURN address; // if delete
30
	//IF (flags & 100b) RETURN address; // if delete
23
	IF (flags & 010b) && (DSDWORD[address] < key) RETURN recursiveIndex(key, DSDWORD[address + 5]); // left tree
31
	IF (flags & 010b) && (DSDWORD[address] < key) RETURN recursiveIndex(key, DSDWORD[address + 5]); // left tree
24
	IF (flags & 001b) && (DSDWORD[address] > key) RETURN recursiveIndex(key, DSDWORD[address + 9]); // right tree
32
	IF (flags & 001b) && (DSDWORD[address] > key) RETURN recursiveIndex(key, DSDWORD[address + 9]); // right tree
25
	RETURN address;
33
	RETURN address;
26
}
34
}
27
:byte Array::init(dword size)
35
:byte Array::init(dword size)
28
{
36
{
29
	IF(!size) RETURN 0;
37
	IF(!size) RETURN 0;
30
	IF(!memory)
38
	IF(!memory)
-
 
39
	{
31
	{
40
		lenInitSize = size * 17;
32
		memory = malloc(size * 17);
41
		memory = malloc(lenInitSize);
33
		EBX = memory;
42
		EBX = memory;
34
		DSDWORD[EBX] = 0;
43
		DSDWORD[EBX] = 0;
35
		DSBYTE[EBX + 4] = 0;
44
		DSBYTE[EBX + 4] = 0;
36
		DSDWORD[EBX + 5] = 0;
45
		DSDWORD[EBX + 5] = 0;
37
		DSDWORD[EBX + 9] = 0;
46
		DSDWORD[EBX + 9] = 0;
38
		DSDWORD[EBX + 13] = 0;
47
		DSDWORD[EBX + 13] = 0;
39
		offsetMemory = 17;
48
		offsetMemory = 17;
40
		RETURN 0xFF;
49
		RETURN 0xFF;
-
 
50
	}
-
 
51
	IF(size > lenInitSize)
41
	}
52
	{
42
	memory = realloc(size * 17);
53
		reallocMemory(size * 17);
43
	RETURN 0xFF;
54
		RETURN 0xFF;
-
 
55
	}
-
 
56
	RETURN 0;
44
}
57
}
45
:byte Array::set(dword key, data)
58
:byte Array::set(dword key, data)
46
{
59
{
47
	dword address = 0;
60
	dword address = 0;
-
 
61
	dword newOffset = 0;
48
	dword newOffset = 0;
62
	IF(offsetMemory > lenInitSize) reallocMemory(offsetMemory << 1);
49
	address = recursiveIndex(key, memory);
63
	address = recursiveIndex(key, memory);
50
	/*IF(DSBYTE[address + 4] & 100b)
64
	/*IF(DSBYTE[address + 4] & 100b)
51
	{
65
	{
52
		IF(DSDWORD[address] < key)
66
		IF(DSDWORD[address] < key)
Line 66... Line 80...
66
		}
80
		}
67
	}*/
81
	}*/
68
	newOffset = memory + offsetMemory;
82
	newOffset = memory + offsetMemory;
69
	IF(DSDWORD[address] < key)
83
	IF(DSDWORD[address] < key)
70
	{
84
	{
71
		DSBYTE[address + 4] |= 10b;
85
		DSBYTE[address + 4] |= 010b; // set flag left address
72
		DSDWORD[address + 5] = newOffset;
86
		DSDWORD[address + 5] = newOffset;
73
	}
87
	}
74
	ELSE IF(DSDWORD[address] > key)
88
	ELSE IF(DSDWORD[address] > key)
75
	{
89
	{
76
		DSBYTE[address + 4] |= 01b;
90
		DSBYTE[address + 4] |= 001b; // set flag right address
77
		DSDWORD[address + 9] = newOffset;
91
		DSDWORD[address + 9] = newOffset;
78
	}
92
	}
79
	ELSE
93
	ELSE
80
	{
94
	{
81
		DSDWORD[address + 13] = data;
95
		DSDWORD[address + 13] = data;
Line 112... Line 126...
112
	byte set(dword key, value);
126
	byte set(dword key, value);
113
	dword get(dword key);
127
	dword get(dword key);
114
	byte init(dword size);
128
	byte init(dword size);
115
};
129
};
Line 116... Line 130...
116
 
130
 
117
:dword Dictionary::hash(dword text)
131
:dword Dictionary::hash(dword text) // max 255 bytes as strings => 4 byte or duble word hash
118
{
132
{
119
	dword s1 = 1;
133
	dword checkSum1 = 1;
-
 
134
	dword checkSum2 = 0;
Line -... Line 135...
-
 
135
	dword beginAddress = 0;
120
	dword s2 = 0;
136
	
121
	
137
	beginAddress = text;
122
	WHILE(DSBYTE[text])
138
	WHILE(DSBYTE[text])
123
	{
139
	{
124
		s1 += DSBYTE[text];
140
		checkSum1 += DSBYTE[text];
125
		s2 += s1;
141
		checkSum2 += checkSum1;
126
		text++;
142
		text++;
127
	}
143
	}
-
 
144
	//IF(h1 > 0x03FFF) RETURN h1 << 8 ^ h2;
-
 
145
	//IF(h2 > 0x3FFFF) RETURN h1 << 8 ^ h2;
128
	IF(s1>0x3FFF) RETURN 0;
146
	EAX = text - beginAddress;
129
	IF(s2>0x3FFFF) RETURN 0;
147
	EAX <<= 23;
Line 130... Line 148...
130
	RETURN s2<<14|s1;
148
	RETURN EAX | checkSum2;
131
}
149
}
132
 
150