[MUD-Dev] Re: let's call it a spellcraft

T. Alexander Popiel popiel at snugharbor.com
Thu Sep 24 08:15:23 CEST 1998


In message:  <199809240523.AAA14210 at dfw-ix10.ix.netcom.com>
             "Jon A. Lambert" <jlsysinc at ix.netcom.com> writes:
>
>I agree,  we should always attempt an implementation  in terms 0, 1 
>and many(unknown/infinity/X).  There are exceptions and instances 
>where we must pay homage at some level to the failings of our 
>silicon, but these should be rare and abstracted if possible.   
>
>It begs the question, "Is the fixed dimensional array evil?"

I'd tend to say that no, fixed dimensional arrays are not evil,
if properly marked.  I submit these excerpts from the string
table code I mentioned a few posts ago as my defending argument:

/* This is a string table implemented as a red-black tree.
 *
 * There are a couple of peculiarities about this implementation:
 *
 * (1) Parent pointers are not stored.  Instead, insertion and
 *     deletion remember the search path used to get to the
 *     current point in the tree, and use that path to determine
 *     parents.
 *
 * (2) A usage count is kept on items in the tree; when items
 *     have 127 concurrent uses, they become permanent, and
 *     may never be fully deleted.
 *
 * (3) The red/black coloring is stored as the low order bit
 *     in the same byte as the usage count (which takes up
 *     the other 7 bits of that byte).
 *
 * (4) The data string is stored directly in the tree node,
 *     instead of hung in a pointer off the node.  This means
 *     that the nodes are of variable size.  What fun.
 *
 * (5) The strings are stored in the table _unaligned_.  If
 *     you try to use this for anything other than strings,
 *     expect alignment problems.
 */
/* This string table is _NOT_ reentrant.  If you try to use this
 * in a multithreaded environment, you will probably get burned.
 */

/* Various constants.  Their import is either bleedingly obvious
 * or explained below. */
#define ST_MAX_DEPTH 64

/* Here we have a global for the path info, just so we don't
 * eat tons of stack space.  (This code isn't reentrant no
 * matter where we put this, so might as well save stack.)
 * The fixed size of this array puts a limit on the maximum
 * size of the string table... but with ST_MAX_DEPTH == 64,
 * the tree can hold between 4 billion and 8 quintillion
 * strings.  I don't think capacity is a problem.
 */
static StrTree *path[ST_MAX_DEPTH];

- Alex




More information about the mud-dev-archive mailing list