[Oberon] How to mimic an associative array

Douglas G. Danforth danforth at greenwoodfarm.com
Wed Dec 1 21:50:29 CET 2010


Duke,

I thought the benefit of a hash table was quick lookup and so I would 
think you
would want an array of values whose index is the key.

     value := hash[key];

Note that value would contain a list of 'strings' all of which hashed to 
the same
location.

     TYPE
         String = POINTER TO ARRAY OF CHAR;
         List = POINTER TO RECORD string: String; next: List END;
         Value = POINTER TO RECORD list: List END;

-Doug Danforth

On 12/1/2010 9:23 AM, Duke Normandin wrote:
> Hello list...
>
> Given that Oberon-2 does not natively support associative arrays (aka
> hash; map - in other languages), I need to come up with a tailor-made
> equivalent. Still very much the Oberon/Modula/Pascal noob, I thinking
> that maybe a Record like:
>
>       TYPE
>          myHash = RECORD
>               key : ARRAY<someLength>  OF CHAR;
>               value : ARRAY<someLength>  OF CHAR;
>          END;
>
> Would that work? Is there a better solution? I'm going to test the
> above, of course, but I just thought that I'd get your input, before
> spinning my wheels too much. There tires/tyres and head are already
> bald enough. :)
>



More information about the Oberon mailing list