Become a part of the TranceAddict community!Frequently Asked Questions - Please read this if you haven'tSearch the forums
TranceAddict Forums > Main Forums > Chill Out Room > Anyone any good at Delphi.... very basic question but frustrating
  Last Thread   Next Thread
Share
Author
Thread    Post A Reply
adrian_nicholl
tranceaddict



Registered: Jan 2006
Location: Ireland
Anyone any good at Delphi.... very basic question but frustrating

I have a Unit written out, but how the frigg do i get it to run? Its a pasfile but pascal doesnt know what to do with it at all, and i dont know how to make delphi make it work.

I tried opening a new project and adding a unit, and then renaming the code deplhi added for me, but it says cant find the file 'hashtable.dcu'

below is the unit code, i am sure its real simple how to get it to run but i cant find anything on google about it

quote:

unit HashTable;

///////////////////////////////
// "White Box" Hash Table 1 //
///////////////////////////////

(* This unit implements a hash table using *
* open addressing and double hashing. *
* It is designed to store URLs *)

interface

const
tableSize = 893;

type
HTable = array [0..tableSize-1] of String;


function hash(str: String): integer;
// Computes the hash function

function hash2(str: String): integer;
// Computes the secondary hash function

procedure initialise(var h: HTable);
// pre: TRUE
// post: h is initialised to the empty hash table,
// (i.e. every string in the array is an empty string)

function search(h: HTable; searchurl: String): boolean;
// pre: searchurl<>''
// post: the result is true if and only if the given string
// searchurl is stored in the hash table h

procedure insert(var h: HTable; url: String);
// pre: url<>''
// post: If there is still an empty slot in the table
// (ie the hash table is not full) then the url is
// (if it isn't in the table already) inserted into
// an empty slot in the table in accordance with the double
// hashing scheme, leaving all other strings in the table
// unchanged.
// If there is no empty slot in the table (i.e. the table
// is full), then the table is unchanged and an error message
// 'Error: table full.' is printed to the console window.

////////////////////////////////////////////////////////////////////

implementation

var opCount: integer;

function hash(str: String): integer;
// Computes the hash function
var count, i: integer;
begin
count := 0;
for i := 0 to length(str)-1 do
count := (count + ord(str[i])) mod tableSize;
hash := count
end;

function hash2(str: String): integer;
// Computes the secondary hash function
const primesArray : array [0..5] of integer
= (1289, 197, 563, 223, 373, 1637); // using these primes to
// multiply the chr numbers by
// mixes up the hash2 function,
// making it more different from
// the hash value itself
var count, i: integer;
begin
count := 0;
for i := 0 to length(str)-1 do
count := (count + (primesArray[i mod 6]*ord(str[i]))) mod (tableSize - 1);
hash2 := count + 1
end;

procedure initialise(var h: HTable);
// pre: TRUE
// post: h is initialised to the empty hash table,
// i.e. every string in the array is an empty string
var i: integer;
begin
if opCount=0 then
for i := 0 to tableSize-1 do
h[i] := ''
end; // initialise

function search(h: HTable; searchurl: String): boolean;
// pre: searchurl<>''
// post: the result is true if and only if the given string
// searchurl is stored in the hash table h
var count, initial, current, h2: integer;
begin
inc(opCount);
initial := hash(searchurl);
h2 := hash2(searchurl);
current := initial;
count := 0;
while (count and (h[current]<>'') // not empty, keep searching
and (h[current]<>searchurl) // not what we're looking for
do
begin
inc(count);
current := (current+h2) mod tableSize;
end;
search := (h[current]=searchurl);
end;



procedure insert(var h: HTable; url: String);
// pre: url<>''
// post: If the given url string is in the table already, then
// the table is unchanged by the insert procedure.
// Otherwise, if there is still an empty slot in the table
// (ie the hash table is not full) then the url is
// inserted into an empty slot in the table in accordance with
// the double hashing scheme, leaving all other strings in the
// table unchanged.
// If there is no empty slot in the table to insert the
// url string in (i.e. the table is full), then the table is
// left unchanged and an error message
// 'Error: table full.' is printed to the console window.
var count, initial, current, h2: integer;
begin
inc(opCount);
initial := hash(url);
h2 := hash2(url);
current := initial;
count := 0;
while (count and (h[current]<>'') // not empty, keep going
and (h[current]<>url) // not what we're looking for
do
begin
inc(count);
current := (current+h2) mod tableSize;
end;
if count>=tableSize then // table is full
writeln('Error: table full.')
else if h[current]='' then // can insert here
h[current] := url
// else it must be the case that (h[current]=url) so do nothing
end;

begin
opCount := 0
end.

Old Post Nov-10-2007 01:42  United Kingdom
Click Here to See the Profile for adrian_nicholl Click here to Send adrian_nicholl a Private Message Visit adrian_nicholl's homepage! Add adrian_nicholl to your buddy list Report this Post Reply w/Quote Edit/Delete Message
aquila
Supreme Pantsaddict



Registered: Feb 2005
Location: Mayfair

hmm try this:

quote:



___________________
-~-

Old Post Nov-10-2007 07:18 
Click Here to See the Profile for aquila Click here to Send aquila a Private Message Visit aquila's homepage! Add aquila to your buddy list Report this Post Reply w/Quote Edit/Delete Message

TranceAddict Forums > Main Forums > Chill Out Room > Anyone any good at Delphi.... very basic question but frustrating
Post New Thread    Post A Reply

 
Last Thread   Next Thread
Click here to listen to the sample!Pause playbackMelodic prog trancer needs ID [2004] [3]

Click here to listen to the sample!Pause playbackNewton - Streamline [2007]

Show Printable Version | Subscribe to this Thread
Forum Jump:

All times are GMT. The time now is 13:09.

Forum Rules:
You may not post new threads
You may not post replies
You may not edit your posts
HTML code is ON
vB code is ON
[IMG] code is ON
 
Search this Thread:

 
Contact Us - return to tranceaddict

Powered by: Trance Music & vBulletin Forums
Copyright ©2000-2026, Jelsoft Enterprises Ltd.
Privacy Statement / DMCA
Support TA!