Jump to content

Looking for hashing function


Recommended Posts

Greetings,

First my problem: I'm trying to not mix AutoIt and Perl in my next report. In the past I've fallen back to Perl because of the easy hashing functions.

I've managed to create what amounts to a single hash pointer in AutoIt by creating a two dimensional array. The first dimension holds the key, the second holds the value. Obviously this requires a bit of brute force searching and redimensioning, but so far the performance has been acceptable.

Ex:

_HashAdd( "a", "A" )
_HashAdd( "b", "B" )

_HashGet( "a" ) <- Returns "A"
_HashGet( "b" ) <- Returns "B"

No I find I need multiple multiple hash pointers.

Ex:

$chars = _NewHashPointer
$nums = _NewHashPointer
_HashAdd( $chars, "a", "A" )
_HashAdd( $chars, "b", "B" )
_HashAdd( $nums, "1", "one" )
_HashAdd( $nums, "2", "two" )

_HashGet( $chars, "a" ) <- Returns "A"
_HashGet( $chars, "b" ) <- Returns "B"
_HashGet( $chars, "1" ) <- Returns ERROR (or no such element, or??)

_HashGet( $nums, "1" ) <- Returns "one"
_HashGet( $nums, "2" ) <- Returns "two"
_HashGet( $nums, "a" ) <- Returns ERROR (or no such element, or??)

Has someone already done something like this and I just can't find it? If so, would someone mind sharing or posting a link?

If I'm blazing a new path in the snow, then I need a bit of help:

* It would be possible for me to create a three dimensional array, and then store the various references (e.g. "$chars" versus "$nums") in the extra dimension. This will be even uglier and more brute force than my current version, but it'll be doable. My main objection is that all hashes will have the same number of elements, even if that doesn't make sense. Said another way, if I add "nums" up to 500, there will be 500 "chars" spaces, even though there's only 26 "chars". (Don't take "nums" and "chars" too literally - that's just an example...) Comments?

* I've tried using anonymous pointers. I create a local array, and then store a reference to that array in another variable. This allows me to have multiple arrays - each of a different size. Unfortunately, I don't seem to be able to resize based on an anonymous pointer - instead I resize the pointer (example below). This means that I need to have a static list of hashes ahead of time. Comments?

Ex:

dim $a1[2][2];
$a1[0][0] = "0.0";
$a1[0][1] = "0.1";
$a1[1][0] = "1.0";
$a1[1][1] = "1.1";


dim $ref[2];
$ref[0] = $a1;
$ref[1] = <perhaps another array...>

$ptr = $ref[0];

msgbox( 0, "test", $ptr[0][1] );
;ReDim $ptr[1]; <- NO
$ptr = 0; <- EDIT wrong version posted, sorry
msgbox( 0, "test", IsArray( $a1 ) ); <- EDIT Returns "1" BTW

Any thoughts as to alternative approaches?

Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

Another thought: How much memory does an element of an array use if it doesn't have an assigned value?

EX:

Dim $array[2][2];
$array[0][0] = "BLKFDLKJERLKJELKJ";
$array[0][1] = "lskjdflkjelkrjlkjlkjl ljlKJLKJLKJLKJLKjlkj alkjlkdjflkja";
$array[1][0] = "LKLKL:K";

<-- How much space is used by $array[1][1] here?

I'd be willing to live with the three dimensional array if the answer is "not much" (say a zero'd 32bit address).

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...