man(1) Manual page archive


     TBL(2)                                                     TBL(2)

     NAME
          tbl - octopus generic integer table module

     SYNOPSIS
          include "tbl.m";
          tbl := load Tbl Tbl->PATH;

          Table: adt[T] {
               items:    array of list of (int, T);
               nilval:   T;

               new: fn(nslots: int, nilval: T): ref Table[T];
               add: fn(t: self ref Table, id: int, x: T): int;
               del: fn(t: self ref Table, id: int): T;
               find:     fn(t: self ref Table, id: int): T;
          };

     DESCRIPTION
          Tbl is a generic hash table, indexed by integer values. It
          is taken (stolen) from the implementation of styxpersist(2).

          New creates a new table with nslots buckets in the hash. The
          nilval argument should be a null value of the appropriate
          type.

          Add adds an element to the table using id as the key. If an
          element with the same key exists it returns -1 and refuses
          to add the given element.

          Del removes an element with the given id from the dable, and
          returns it.

          Find looks up the element with the given id and returns it.

     EXAMPLE
          Create a has table of references to File with 103 buckets,
          and add a file with key 0 to it.
               nullfile: ref File;
               files = Table[ref File].new(103, nullfile); # use a prime number as size.
               files.add(0, ref File("/a/file", nil));

     SOURCE
          /usr/octopus/port/lib/tbl.b