Hashmap new & newEx
git-svn-id: https://spexeah.com:8443/svn/Asuro@1311 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
e89b2e05b3
commit
06c50df49d
@ -22,7 +22,12 @@ type
|
||||
Table : DPHashItem;
|
||||
end;
|
||||
|
||||
function new(size : uint32) : PHashMap;
|
||||
const
|
||||
HASHMAP_DEFAULT_SIZE = 16;
|
||||
HASHMAP_DEFAULT_LOADFACTOR = 0.75;
|
||||
|
||||
function new : PHashMap;
|
||||
function newEx(size : uint32; loadFactor : Single) : PHashMap;
|
||||
procedure add(map : PHashMap; key : pchar; value : void);
|
||||
function get(map : PHashMap; key : pchar) : void;
|
||||
procedure delete(map : PHashMap; key : pchar; freeItem : boolean);
|
||||
@ -66,22 +71,15 @@ var
|
||||
c : uint32;
|
||||
|
||||
begin
|
||||
tracer.push_trace('hashmap.putItem.1');
|
||||
ExistingItem:= table[idx];
|
||||
tracer.push_trace('hashmap.putItem.2');
|
||||
if ExistingItem = nil then begin
|
||||
tracer.push_trace('hashmap.putItem.3');
|
||||
table[idx]:= item;
|
||||
end else begin
|
||||
tracer.push_trace('hashmap.putItem.4');
|
||||
c:=0;
|
||||
while ExistingItem^.Next <> nil do begin
|
||||
tracer.push_trace('hashmap.putItem.5');
|
||||
ExistingItem:= ExistingItem^.Next;
|
||||
end;
|
||||
tracer.push_trace('hashmap.putItem.6');
|
||||
ExistingItem^.Next:= item;
|
||||
tracer.push_trace('hashmap.putItem.6');
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -182,7 +180,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function new(size : uint32) : PHashMap;
|
||||
function newEx(size : uint32; loadFactor : Single) : PHashMap;
|
||||
var
|
||||
Map : PHashMap;
|
||||
i : uint32;
|
||||
@ -191,12 +189,17 @@ begin
|
||||
Map:= PHashMap(kalloc(sizeof(THashMap)));
|
||||
Map^.size:= size;
|
||||
Map^.Table:= DPHashItem(Kalloc(sizeof(PHashItem) * Size));
|
||||
Map^.LoadFactor:= 0.75;
|
||||
Map^.LoadFactor:= loadFactor;
|
||||
Map^.Count:= 0;
|
||||
for i:=0 to size-1 do begin
|
||||
Map^.Table[i]:= nil;
|
||||
end;
|
||||
new:= Map;
|
||||
newEx:= Map;
|
||||
end;
|
||||
|
||||
function new : PHashMap;
|
||||
begin
|
||||
new:= newEx(HASHMAP_DEFAULT_SIZE, HASHMAP_DEFAULT_LOADFACTOR);
|
||||
end;
|
||||
|
||||
procedure delete(map : PHashMap; key : pchar; freeItem : boolean);
|
||||
|
@ -212,7 +212,7 @@ begin
|
||||
{ Bus Drivers }
|
||||
tracer.push_trace('kmain.BUSDRV');
|
||||
console.outputln('KERNEL', 'BUS DRIVERS: INIT BEGIN.');
|
||||
//USB.init();
|
||||
USB.init();
|
||||
pci.init();
|
||||
console.outputln('KERNEL', 'BUS DRIVERS: INIT END.');
|
||||
|
||||
@ -240,11 +240,11 @@ begin
|
||||
writestringln(' ');
|
||||
|
||||
tracer.push_trace('kmain.END');
|
||||
rand.srand((getDateTime.Seconds SHR 24) OR (getDateTime.Minutes SHR 16) OR (getDateTime.Hours SHR 8) OR (getDateTime.Day));
|
||||
rand.srand((getDateTime.Seconds SHL 24) OR (getDateTime.Minutes SHL 16) OR (getDateTime.Hours SHL 8) OR (getDateTime.Day));
|
||||
|
||||
tracer.push_trace('kmain.TICK');
|
||||
|
||||
HM:= hashmap.new(16);
|
||||
HM:= hashmap.newEx(16, 0.1);
|
||||
hashmap.add(HM, 'testificate', void(1));
|
||||
hashmap.add(HM, 'asuro', void(10));
|
||||
hashmap.add(HM, 'myfirstos', void(100));
|
||||
@ -280,9 +280,7 @@ begin
|
||||
hashmap.add(HM, 'Laptop', void(50000000));
|
||||
hashmap.add(HM, 'Salmon', void(500000000));
|
||||
hashmap.add(HM, 'OnionBurger', void(60));
|
||||
|
||||
hashmap.printmap(HM);
|
||||
|
||||
writeintln(uint32(hashmap.get(HM, 'Ana')));
|
||||
|
||||
// Testing getting into userspace
|
||||
|
Loading…
x
Reference in New Issue
Block a user