HFL Hash Functions

HFL Hash Functions:

  • Below is a list of hash-manipulation functions built into HFL.
  • NOTE: These are normal functions, not object methods.
  • hash ([<init-value-pairs>])
    where:
    <init-value-pairs>
    :=
    <value-pair> [, <value-pair>]*
    <value-pair>
    :=
    <key>, <expresion>
    • Creates a new hash table.
    • Once created, hash entries are accessed using the same syntax as javascript object field values.
    • NOTE: The data structure created by 'hash()' is a true hash table, as opposed to being implemented as a javascript object.
      • The difference is that a true hash table only contains the hash entries, without all of the rest of the object overhead.
      • In particular, this means that the foreach() operator will only find the hash entries, not all of the other properties and method entries that are associated with true javascript-compatible objects.
    • If the initialization value pairs are specified, the hash table is pre-populated with their values. Each entry is specified as a pair, with each odd value being a hash key and each even value being the previous key's value. The value can be any valid expression.
    • EXAMPLE
    • var myhash = hash('dog', 'Spot', 'cat', 'Fluffy', 'num', 1 + 2);

      // Prints "My dog's name is Spot"
      print("My dog's name is "+myhash['dog']);

      // Add new entry to hash table
      myhash['bird'] = 'Tweety';

  • printHash ([<file-handle>,] <label>, <hash-table> [, <quote>]*)
    where:
    <label>
    :=
    Text string to be displayed as a banner
    <quote>
    :=
    Character to be used as a quote around elements
    • Prints the contents of a hash table, with the <label> above the list as a banner header, either to the console, or written to a file.
    • To write to a file, a file must first be opened for 'write' or 'append' access using the openFile() function. Then its file handle is passed to 'printHash' as the optional <file-handle> argument.
    • If the optional <file-handle> is not specified, prints to the console.
    • EXAMPLE
    • var $h = hash('a', 1, 'b', 2, 'c', 3);
      printHash("HASH TABLE CONTENTS", $h);

      • RESULTS:
      • HASH TABLE CONTENTS
        -----------
        a => 1
        b => 2
        c => 3
        -----------

Previous: Array Functions Next: Filename Functions