Command Parsers, continued

Nathan Yospe yospe at hawaii.edu
Sun Nov 24 15:14:57 CET 1996


As mentioned in my previous post, I am using unique namespaces to refer
to both hard and softcoded functions. The namespaces take the form of a
case insensitive string of length ~7 characters, at most. (they can be
longer, but internal functionality discourages it. Now, on to searching
through the db for functions (and anything else named, for that matter,
which means virtually everything in the entire db.)

Let me introduce the alphatree.

class alphatree{   // perhaps templatize the class?
protected:
  named * member;
public:
  virtual named * search(mudstring &name);
  virtual void addmember(named * member, mudstring &name);
  virtual void remmember(mudstring &name);
};

class ATleaf: public alphatree{
public:
  named * search(mudstring &name){
    if(member.check(name))
      return member;
    else
      return NULL;
  }
  void addmember(named * member, mudstring &name);
  void remmember(mudstring &name);
};

class ATmononode: public alphatree{
  alphatree *branch;
  char name;
public:
  . . .
};

class ATbinode: public alphatree{
  alphatree *branch[2];
  char name[2];
public:
  . . .
};

class ATtrinode. . . . class AThexnode

class ATfull: public alphatree{
  alphatree *branch[36];
public:
   . . .
};

For the fullnode, the 36 branches are direct linked to the coresponding
characters by an enumeration switch. Its a lot faster than any other
library tree I've found, and saves memory over most of them for large
namespaces ( > 4000 names ) I think I'm losing a bit on the smaller lists,
but what the hell... its adaptable. That's important. If anyone knows a
better way to do this, let me know.

   __    _   __  _   _   ,  ,  , ,  
  /_  / / ) /_  /_) / ) /| /| / /\            First Light of a Nova Dawn
 /   / / \ /_  /_) / \ /-|/ |/ /_/            Final Night of a World Gone
Nathan F. Yospe - University of Hawaii Dept of Physics - yospe at hawaii.edu



More information about the mud-dev-archive mailing list