Dealing with Hashes

Hash is part of the CategoryAplTree project.

Overview

A hash is a vector of (key/value) pairs. Because this can be easily implemented in APL, you might think there is no need for a hash class.

Believe me, that is wrong.

Such a class cannot only provide what nested arrays provide anyway, it can and should also provide a number of frequently requested and useful methods. The simplest example for this might be the fact that by default keys in the hash class offered here are not case sensitive.

Imagine a class which creates a form. There are lots of parameters the user might or might not want to set. Inside the constructor of the class, you can first establish defaults for the several properties, then overwrite these defaults with values specified from outside.

Using the Hash class this takes only some lines of code:

 ∇ctor parms
 [1] props←⎕NEW #.Hash
 [2] props.Merge('Coord' 'Pixel')('size'(300 400))('Caption'⎕WSID)('Posn'(⍬ ⍬))
 [3] props.updateOnly←1
 [4] props.Merge parms
 [5] props.GetAsMatrix
 [6] ....

line 1: Creates a new instance of the Hash class called props.

line 2: Merge a vector with ordinary key/values pairs into props. These are your defaults'.

line 3: Set updateOnly to 1; one can still change the value of a key but cannot add or delete keys any longer.

line 4: Merge the parms passed as right argument into the hash. If there are keys specified in parms unkown to the Hash, an interrupt is generated. That makes sure that no nonsense-keys are passed as parameters.

line 5: Return the whole contents of the Hash as a matrix with 2 columns

There are lots of useful methods available. There are also a number of properties you can change to make Hash suit your needs.

Find out more by looking into the documentation HashDocumentation.html

Project Page

For bug reports, future enhancements and a full version history see Hash/ProjectPage

Version Information

Original author:

KaiJaeger

Responsible:

KaiJaeger

Email:

kai@aplteam.com

APLTree downloads

Whether you are interested in ...

  • the latest stable version or...
  • any older version or...
  • the full project including development stuff and test cases or...
  • the current development trunk, again with development stuff and test cases...

... all downloads are available at http://download.aplwiki.com/apltree


CategoryAplTree

hash (last edited 2011-08-31 11:55:00 by KaiJaeger)