with Ada.Unchecked_Conversion, ada.text_io; use ada.text_io;
with ada.integer_text_io; use ada.integer_text_io;
procedure hash is
type str is new String(1..2);
function toInt is new Ada.Unchecked_Conversion(str, Long_Integer);
--hash node, self aware of address and key
type hNode is record
key: String(1..16);
link: integer;
address: Long_Integer;
end record;
--size of hash table
tableSize: integer := 128;
--hash table
type hTable is array(1..tableSize) of hNode;
--buffer for reading in hNode
bufferNode: hNode;
--selection at menu prompt
selection: integer :=0;
--empty value of key
emptyVal: String (1..16):= (others=>' ');
linkedEmptyVal: String(1..16):=(others=>'&');
function hFunct return hNode is
buffer: String(1..16);
tempNode:hNode;
begin
put("Enter Key:: ");
get(buffer);
tempNode.key:=buffer; --double check this syntax
sum:=abs(toInt(buffer(3..4))) +abs(toInt(buffer(7..8))) + abs(toInt(buffer(11..12))) + abs(toInt(buffer(15..16)));
sum:=sum mod tableSize;
tempNode.address:=sum;
return tempNode;
end hFunct;
procedure insert is
tNode:hNode;
count:long_integer:=0;
begin
put("enter string '&&&&&&&&&&&&&&&&' (16 of them) to end insertion");
loop
tNode:=hFunct;
exit when tnode.key=linkedEnptyVal;
count:=tNode.address;
loop
if hTable(count).key = emptyVal or hTable(count).key = linkedEmptyVal then
hTable(count).key:=tNode.key;
exit;
else
count:=count+1;
end if;
end loop;
end loop;
end insert;
begin
--initialize hash table to default values (space holders)
for x in 1..tableSize loop
hTable(x).link:=-1;
hTable(x).key:=(others=>' ');
hTable(x).address:=0;
end loop;
put_line("+++++++++++++++++++++++++++++++++++++++++++++++");
put_line("+++ Welcome to the Hash Table Program +++ ");
put_line("+++++++++++++++++++++++++++++++++++++++++++++++");
loop
put_line("+Menu::");
put_line("1: Insert into hash table");
put_line("2: Lookiup in hash table");
put_line("3: Print stats");
put_line("4: Exit");
put("Please Enter a Selection:: ");
get(selection);
exit when selection = 4;
if selection = 1 then
insert;
--elsif selection = 2 then
--elsif selection = 3 then
--elsif selection = 4 then
end if;
end loop;
end hash;