forked from KolibriOS/kolibrios
Update library array.
git-svn-id: svn://kolibrios.org@7741 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
eed7aee495
commit
1db21b9e5d
61
programs/cmm/examples/array.c
Normal file
61
programs/cmm/examples/array.c
Normal 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--;
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@
|
||||
#ifndef 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
|
||||
// If key don't exists then value == 0
|
||||
:struct Array
|
||||
@ -20,6 +22,7 @@
|
||||
|
||||
:void Array::reallocMemory(dword newSize)
|
||||
{
|
||||
newSize *= 17;
|
||||
memory = realloc(memory, newSize);
|
||||
lenInitSize = newSize;
|
||||
}
|
||||
@ -34,25 +37,27 @@
|
||||
IF (flags & 001b) && (DSDWORD[address] > key) RETURN recursiveIndex(key, DSDWORD[address + 9]); // right tree
|
||||
RETURN address;
|
||||
}
|
||||
|
||||
:byte Array::init(dword size)
|
||||
{
|
||||
IF(!size) RETURN 0;
|
||||
dword pointer = 0;
|
||||
if (!size) size = 8;
|
||||
IF(!memory)
|
||||
{
|
||||
lenInitSize = size * 17;
|
||||
memory = malloc(lenInitSize);
|
||||
EBX = memory;
|
||||
DSDWORD[EBX] = 0;
|
||||
DSBYTE[EBX + 4] = 0;
|
||||
DSDWORD[EBX + 5] = 0;
|
||||
DSDWORD[EBX + 9] = 0;
|
||||
DSDWORD[EBX + 13] = 0;
|
||||
pointer = memory;
|
||||
DSDWORD[pointer] = 0; pointer += 4;
|
||||
DSBYTE[pointer] = 0; pointer += 1;
|
||||
DSDWORD[pointer] = 0;pointer += 4;
|
||||
DSDWORD[pointer] = 0;pointer += 4;
|
||||
DSDWORD[pointer] = 0;
|
||||
offsetMemory = 17;
|
||||
RETURN 0xFF;
|
||||
}
|
||||
IF(size > lenInitSize)
|
||||
{
|
||||
reallocMemory(size * 17);
|
||||
reallocMemory(size);
|
||||
RETURN 0xFF;
|
||||
}
|
||||
RETURN 0;
|
||||
@ -97,11 +102,11 @@
|
||||
DSDWORD[address + 13] = data;
|
||||
RETURN 0xFF;
|
||||
}
|
||||
DSDWORD[newOffset] = key;
|
||||
DSBYTE[newOffset+4] = 0;
|
||||
DSDWORD[newOffset+5] = 0;
|
||||
DSDWORD[newOffset+9] = 0;
|
||||
DSDWORD[newOffset+13] = data;
|
||||
DSDWORD[newOffset] = key; newOffset+=4;
|
||||
DSBYTE[newOffset] = 0; newOffset+=1;
|
||||
DSDWORD[newOffset] = 0; newOffset+=4;
|
||||
DSDWORD[newOffset] = 0; newOffset+=4;
|
||||
DSDWORD[newOffset] = data;
|
||||
offsetMemory += 17;
|
||||
RETURN 0xFF;
|
||||
}
|
||||
@ -130,8 +135,10 @@
|
||||
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 checkSum2 = 0;
|
||||
dword beginAddress = 0;
|
||||
@ -148,6 +155,7 @@
|
||||
EAX = text - beginAddress;
|
||||
EAX <<= 23;
|
||||
RETURN EAX | checkSum2;
|
||||
*/
|
||||
}
|
||||
|
||||
:byte Dictionary::set(dword key, value)
|
||||
@ -165,4 +173,4 @@
|
||||
RETURN array.init(size);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user