Update library array.

git-svn-id: svn://kolibrios.org@7741 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pavelyakov 2020-03-21 13:38:17 +00:00
parent eed7aee495
commit 1db21b9e5d
2 changed files with 84 additions and 15 deletions

View File

@ -0,0 +1,61 @@
#define MEMSIZE 4096*200
#include "../lib/window.h"
#include "../lib/array.h"
window win1=0;
void main()
{
win1.background = 0xFFFFFF;
win1.left = 200;
win1.top = 200;
win1.caption = "Stress test";
win1.ondraw = #draw_window;
win1.create();
}
Array a = {0};
Dictionary b = {0};
void draw_window()
{
dword size = 10000;
dword i = 0;
dword y = 10;
i = size;
/* ints */
a.init(0);
while(i){
a.set(i,i);
i--;
}
a.set(120,222);
a.set(9990,345);
i = size;
while(i){
if (a.get(i) != i)
{
WriteText(15, y, 0x81, 0xFF0000, itoa(i));
WriteText(95, y, 0x81, 0xFF0000, itoa(a.get(i)));
y += 25;
}
i--;
}
/* strs */
b.init(0);
i = size;
while(i){
b.set(itoa(i),i);
i--;
}
b.set("123","Okey");
i = size;
while(i){
if (b.get(itoa(i)) != i)
{
WriteText(15, y, 0x81, 0xFF0000, itoa(i));
WriteText(95, y, 0x81, 0xFF0000, b.get(itoa(i)));
y += 25;
}
i--;
}
}

View File

@ -3,6 +3,8 @@
#ifndef INCLUDE_ARRAY_H #ifndef INCLUDE_ARRAY_H
#define INCLUDE_ARRAY_H #define INCLUDE_ARRAY_H
#include "../lib/crc32.h"
// Array memory: [dword key][byte flags][dword left][dword right][dword value] -> 17 bytes = 1 position // Array memory: [dword key][byte flags][dword left][dword right][dword value] -> 17 bytes = 1 position
// If key don't exists then value == 0 // If key don't exists then value == 0
:struct Array :struct Array
@ -20,6 +22,7 @@
:void Array::reallocMemory(dword newSize) :void Array::reallocMemory(dword newSize)
{ {
newSize *= 17;
memory = realloc(memory, newSize); memory = realloc(memory, newSize);
lenInitSize = newSize; lenInitSize = newSize;
} }
@ -34,25 +37,27 @@
IF (flags & 001b) && (DSDWORD[address] > key) RETURN recursiveIndex(key, DSDWORD[address + 9]); // right tree IF (flags & 001b) && (DSDWORD[address] > key) RETURN recursiveIndex(key, DSDWORD[address + 9]); // right tree
RETURN address; RETURN address;
} }
:byte Array::init(dword size) :byte Array::init(dword size)
{ {
IF(!size) RETURN 0; dword pointer = 0;
if (!size) size = 8;
IF(!memory) IF(!memory)
{ {
lenInitSize = size * 17; lenInitSize = size * 17;
memory = malloc(lenInitSize); memory = malloc(lenInitSize);
EBX = memory; pointer = memory;
DSDWORD[EBX] = 0; DSDWORD[pointer] = 0; pointer += 4;
DSBYTE[EBX + 4] = 0; DSBYTE[pointer] = 0; pointer += 1;
DSDWORD[EBX + 5] = 0; DSDWORD[pointer] = 0;pointer += 4;
DSDWORD[EBX + 9] = 0; DSDWORD[pointer] = 0;pointer += 4;
DSDWORD[EBX + 13] = 0; DSDWORD[pointer] = 0;
offsetMemory = 17; offsetMemory = 17;
RETURN 0xFF; RETURN 0xFF;
} }
IF(size > lenInitSize) IF(size > lenInitSize)
{ {
reallocMemory(size * 17); reallocMemory(size);
RETURN 0xFF; RETURN 0xFF;
} }
RETURN 0; RETURN 0;
@ -97,11 +102,11 @@
DSDWORD[address + 13] = data; DSDWORD[address + 13] = data;
RETURN 0xFF; RETURN 0xFF;
} }
DSDWORD[newOffset] = key; DSDWORD[newOffset] = key; newOffset+=4;
DSBYTE[newOffset+4] = 0; DSBYTE[newOffset] = 0; newOffset+=1;
DSDWORD[newOffset+5] = 0; DSDWORD[newOffset] = 0; newOffset+=4;
DSDWORD[newOffset+9] = 0; DSDWORD[newOffset] = 0; newOffset+=4;
DSDWORD[newOffset+13] = data; DSDWORD[newOffset] = data;
offsetMemory += 17; offsetMemory += 17;
RETURN 0xFF; RETURN 0xFF;
} }
@ -130,8 +135,10 @@
byte init(dword size); byte init(dword size);
}; };
:dword Dictionary::hash(dword text) // max 255 bytes as strings => 4 byte or duble word hash :dword Dictionary::hash(dword text)
{ {
RETURN crc32(text, strlen(text));
/*
dword checkSum1 = 1; dword checkSum1 = 1;
dword checkSum2 = 0; dword checkSum2 = 0;
dword beginAddress = 0; dword beginAddress = 0;
@ -148,6 +155,7 @@
EAX = text - beginAddress; EAX = text - beginAddress;
EAX <<= 23; EAX <<= 23;
RETURN EAX | checkSum2; RETURN EAX | checkSum2;
*/
} }
:byte Dictionary::set(dword key, value) :byte Dictionary::set(dword key, value)
@ -165,4 +173,4 @@
RETURN array.init(size); RETURN array.init(size);
} }
#endif #endif