msg00628.html

1999Q1/msg00628.html · 11.4 KB

From the archive 1999Q1.zip

Download the archive   « Back to the archive contents

<!-- MHonArc v2.4.4 -->
<!--X-Subject: Re: [MUD&#45;Dev] Naming and Directories? -->
<!--X-From-R13: Ayn Tbfurvz =?vfb&#45;8859&#45;1?C?Ue=T8fgnq?= <byntNvsv.hvb.ab> -->
<!--X-Date: Wed, 17 Mar 1999 00:43:28 &#45;0800 -->
<!--X-Message-Id: 36EFD828.9059B5D#ifi,uio.no -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: 199903170846.CAA09676@dfw&#45;ix7.ix.netcom.com -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, Re: [MUD-Dev] Naming and Directories?</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:olag#ifi,uio.no">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00627.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00629.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00626.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00638.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00628">Author</A>
&nbsp;|&nbsp;<A HREF="#00628">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00628">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>Re: [MUD-Dev] Naming and Directories?</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Subject</em>: Re: [MUD-Dev] Naming and Directories?</LI>
<LI><em>From</em>: Ola Fosheim Grøstad &lt;<A HREF="mailto:olag#ifi,uio.no">olag#ifi,uio.no</A>&gt;</LI>
<LI><em>Date</em>: Wed, 17 Mar 1999 17:28:24 +0100</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Sender</em>: <A HREF="mailto:mud-dev-admin#kanga,nu">mud-dev-admin#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
"Jon A. Lambert" wrote:
&gt; But you have changed your requirements above from speed to memory. 
&gt; No fair. ;)

fragmented memory access == slow =&gt; memory == speed

&gt; The alphabet trie above has some pros and cons:
&gt; 
&gt; 1) avoids the overhead of string hashing

Uh? Hashing is most likely faster, unless you deliberately make it slow. 
It isn't too difficult to come up with a reasonable hashing scheme for
small sets (without delete, or with lazy delete)

first hash = 
	RANDOMLUT[string[0]] + 
	RANDOMLUT[string[stringlength/2]+OFFSET1] + 
	RANDOMLUT[string[stringlength-1]+OFFSET2] + stringlength;

on collision, use a second hash, e.g. =

	hash=stringlength;
	switch(stringlength){
		default: do whatever for string[8..stringlength]
		case 8: hash += RANDOMLUT[string[7]+OFFSET10];
		case 7: hash += RANDOMLUT[string[6]+OFFSET9];
		case 6: hash += RANDOMLUT[string[5]+OFFSET8];
		case 5: hash += RANDOMLUT[string[4]+OFFSET7];
		case 4: hash += RANDOMLUT[string[3]+OFFSET6];
		case 3: hash += RANDOMLUT[string[2]+OFFSET5];
		case 2: hash += RANDOMLUT[string[1]+OFFSET4];
		case 1: hash += RANDOMLUT[string[0]+OFFSET3];
	}


&gt; 2) provides intrinsic support for abbreviations

I don't think abbreviations is very good from a usability point of view,
it can lead to unexpected results. Besides, you can get that with hashing
too, just insert the substrings as well.

&gt; 1) based on English and may not support blanks, puntuation, or other 
&gt; characters   (of course this can be altered or enforced)

Easily for limited charsets using a translation table, which would be
handy because you could make it case insensitive at the same time.

N-ary tree example:

	unsigned char table[256];
	fill table with the value 0;
	table['a']=table['A']=1; 
        ...
	table['z']=table['Z']=27;
	table['æ']=table['Æ']=28;
	table['ø']=table['Ø']=29;
	table['å']=table['Å']=30;

	struct node {
	  node *branches[31];
          object *obj;
          node(){ branches[0..31] = obj = NULL; }
	};

	object *findobj(const string &amp;s,const node *n){
	  for(int i=0; i&lt;s.length(); i++){
	    n = n-&gt;branches[table[s[i]]];
            if(n==NULL) return NULL;
	  }
          return n-&gt;obj;
	}

	object *findobj(const char *s,const node *n){
	  while(*s) {
	    n = n-&gt;branches[table[*s++]];
            if(n==NULL) return NULL;
	  }
          return n-&gt;obj;
	}

I suspect you can make it faster for successfull hits with zero
terminated strings by making zero a symbol... (avoiding the n==NULL test,
which isn't too expensive anyways btw)  Hmmm, could be fun to
implement... Would be useful as you could allow " ,.:;" to function as
string terminators as well. An advanced version could use multiple
translation tables and compress the N-ary tree nodes based on profiling
information.

Sketchy:

        unsigned char emptytable[256] = {0,0,0,0,0...};
        unsigned char terminatortable[256] = x in "\0 ,.:;" ? 1 : 0;
        unsigned char smalltable[256] = terminatortable + alphas...
        unsigned char largetable[256] = smalltable + rare characters
        
	class node { public:
          object *obj;
	  unsigned char *table;
	  node *branches[1]; //have to fake this size with malloc :-x
          node(){obj=NULL; table=emptytable; branches[0]=&amp;errornode; }
	};

        node emptynode = {NULL, emptytable, NULL};
        node errnornode = {NULL, emptytable, emptynode};

	findobj(s,n){
	  do {
            m = n;
	    n = n-&gt;branches[n-&gt;table[*s]];
	    s++;
	  } while(n);
	  return m-&gt;obj;
	}

Bwahahaha, I love hacks like these...

	findobj(char *s,node *n){
          s-=2;
	  do {
	    s+=2;
	    m = n-&gt;branches[n-&gt;table[s[0]]];
	    if(!m) return n-&gt;obj;
	    n = m-&gt;branches[m-&gt;table[s[1]]];
	  } while(n);
	  return m-&gt;obj;
	}

:*)

Now if Raph could post all the names to all the players of Ultima Online
then we could see what actually would happen in a real life situation...
I guess one could use IRC as well. Hmm...

&gt; The hash algorithm would treat the name string as either a 2 byte or 4 byte
&gt; unsigned int which should be cheaper to hash than the entire string.  Of
&gt; course, you would have to enforce a mininum name length.

Why a minimum name length? All you need is to store the strings zero
padded up to the alignment boundary, which should not be too expensive as
you often end up with such alignments anyway.

Examples: 
	zeropad("hello") == 'hell','o\0\0\0'
	zeorpad("hell") == 'hell', '\0\0\0\0'
	zeropad("?") == '?\0\0\0'

The only trouble would be if you work with pointers directly into string
buffers. There are ways to compensate for this though. For a 32 bit
implementation: write 4 versions and use masking, and make stringlength&lt;3
a special case as you risk to mask out on both ends... (and remember
safe-hex!)

Anyway, it is almost always faster to choose a data structure that only
supports the functionality one looks for. So really, it doesn't make any
sense to discuss this stuff without some more knowledge about what kind
of statistical properties, and operation sequences we are talking about.
--
Ola Fosheim Groestad,Norway      <A  HREF="http://www.stud.ifi.uio.no/~olag/">http://www.stud.ifi.uio.no/~olag/</A>



_______________________________________________
MUD-Dev maillist  -  MUD-Dev#kanga,nu
<A  HREF="http://www.kanga.nu/lists/listinfo/mud-dev">http://www.kanga.nu/lists/listinfo/mud-dev</A>


</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<ul compact><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><A NAME="00644" HREF="msg00644.html">Re: [MUD-Dev] Naming and Directories?</A></strong>
<ul compact><li><em>From:</em> "Jon A. Lambert" &lt;jlsysinc#ix,netcom.com&gt;</li></ul>
<li><strong><A NAME="00638" HREF="msg00638.html">Re: [MUD-Dev] Naming and Directories?</A></strong>
<ul compact><li><em>From:</em> Mark Gritter &lt;mark#erdos,Stanford.EDU&gt;</li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="00625" HREF="msg00625.html">Re: [MUD-Dev] Naming and Directories?</A></STRONG>
<UL><LI><EM>From:</EM> "Jon A. Lambert" &lt;jlsysinc#ix,netcom.com&gt;</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00627.html">Re: [MUD-Dev] Re: pet peeves</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00629.html">Re: [MUD-Dev] On the topic of Mud AI</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00626.html">Re: [MUD-Dev] Naming and Directories?</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00638.html">Re: [MUD-Dev] Naming and Directories?</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00628"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00628"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>Re: [MUD-Dev] Naming and Directories?</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<ul compact>
<ul compact>
<LI><strong><A NAME="00607" HREF="msg00607.html">Re: [MUD-Dev] Naming and Directories?</A></strong>, 
Mik Clarke <a href="mailto:mikclrk#ibm,net">mikclrk#ibm,net</a>, Tue 16 Mar 1999, 12:27 GMT
<UL>
<LI><strong><A NAME="00613" HREF="msg00613.html">Re: [MUD-Dev] Naming and Directories?</A></strong>, 
Mark Gritter <a href="mailto:mark#erdos,Stanford.EDU">mark#erdos,Stanford.EDU</a>, Tue 16 Mar 1999, 13:46 GMT
</LI>
<LI><strong><A NAME="00625" HREF="msg00625.html">Re: [MUD-Dev] Naming and Directories?</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Wed 17 Mar 1999, 00:54 GMT
<UL>
<LI><strong><A NAME="00626" HREF="msg00626.html">Re: [MUD-Dev] Naming and Directories?</A></strong>, 
Hans-Henrik Staerfeldt <a href="mailto:hhs#cbs,dtu.dk">hhs#cbs,dtu.dk</a>, Wed 17 Mar 1999, 02:48 GMT
</LI>
<LI><strong><A NAME="00628" HREF="msg00628.html">Re: [MUD-Dev] Naming and Directories?</A></strong>, 
Ola Fosheim Grøstad <a href="mailto:olag#ifi,uio.no">olag#ifi,uio.no</a>, Wed 17 Mar 1999, 08:43 GMT
<UL>
<LI><strong><A NAME="00638" HREF="msg00638.html">Re: [MUD-Dev] Naming and Directories?</A></strong>, 
Mark Gritter <a href="mailto:mark#erdos,Stanford.EDU">mark#erdos,Stanford.EDU</a>, Wed 17 Mar 1999, 18:03 GMT
<UL>
<LI><strong><A NAME="00652" HREF="msg00652.html">Re: [MUD-Dev] Naming and Directories?</A></strong>, 
Ola Fosheim Grøstad <a href="mailto:olag#ifi,uio.no">olag#ifi,uio.no</a>, Thu 18 Mar 1999, 17:54 GMT
<UL>
<LI><strong><A NAME="00656" HREF="msg00656.html">Re: [MUD-Dev] Naming and Directories?</A></strong>, 
Mark Gritter <a href="mailto:mark#erdos,Stanford.EDU">mark#erdos,Stanford.EDU</a>, Thu 18 Mar 1999, 18:58 GMT
<LI><strong><A NAME="00662" HREF="msg00662.html">Re: [MUD-Dev] Naming and Directories?</A></strong>, 
Ola Fosheim Grøstad <a href="mailto:olag#ifi,uio.no">olag#ifi,uio.no</a>, Sat 20 Mar 1999, 16:15 GMT
</LI>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</ul>
</ul>
</ul>
</ul>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>

Site Stats

Snippets: 1791
Codebases: 571