[Oberon] How to mimic an associative array

Aubrey.McIntosh at Alumni.UTexas.Net Aubrey.McIntosh at Alumni.UTexas.Net
Thu Dec 2 19:39:23 CET 2010


A strong part of the Oberon culture is that things like this are kept
in libraries and out of the language, to avoid a bloated language and
slow development environment.  That is, almost everything is "not
built in" to Oberon.  This even applies to basic input/output.

You have taken a strong first step to identify a data structure.  In
addition to your data structure, you will need to have some methods,
or procedures that work on the data structure.

These are some that come to mind in a minute of thinking.

  myHashPtr = POINTER TO myHash;

PROCEDURE Init* (VAR t : myHash);  This probably just sets t := NIL,
or does a NEW(t), or such.
PROCEDURE Enter* (VAR t: myHash, key: keyType, value: valueType);
PROCEDURE This* (t : myHash, key: keyType, VAR valueType);
PROCEDURE Remove* (VAR t: myHash, key : keyType);
PROCEDURE Enumerate* (t : myHash, handler : someProcType);

You can write a different implementation module of these methods every
Saturday morning for a while to practice your Oberon skills.  Perhaps
a brute force memory list, perhaps a disk based B tree, perhaps
something that spends all night trying to calculate perfect hashes for
the table as it is at that moment.

On Wed, Dec 1, 2010 at 11:23 AM, Duke Normandin <dukeofperl at ml1.net> 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
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon

Aubrey McIntosh, Ph.D.
1502 Devon Circle
Austin TX 78723-1814

More information about the Oberon mailing list