[Oberon] How to mimic an associative array
Duke Normandin
dukeofperl at ml1.net
Thu Dec 2 05:26:36 CET 2010
On Wed, 1 Dec 2010, Douglas G. Danforth wrote:
>
> 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. :)
> >
>
> 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;
>
Thanks Doug! That's the solution I'm looking for - I think. Over the
years I've been "pointer-challenged" with C et al, but I hope to get
over it with the Pascal family of languages, because of the
terminology. So I'll have to skip forward in Nikitin's book to the
"pointers" section :) Could there be a non-pointer rendition of a
Perl-like "associative array"? Maybe not as efficient, but equally
effective? TIA...
--
Duke
More information about the Oberon
mailing list