msg00652.html
1999Q1/msg00652.html · 10.0 KB
From the archive 1999Q1.zip
Download the archive « Back to the archive contents
<!-- MHonArc v2.4.4 -->
<!--X-Subject: Re: [MUD-Dev] Naming and Directories? -->
<!--X-From-R13: Ayn Tbfurvz =?vfb-8859-1?C?Ue=T8fgnq?= <byntNvsv.hvb.ab> -->
<!--X-Date: Thu, 18 Mar 1999 09:54:01 -0800 -->
<!--X-Message-Id: 36F19DEF.CB345660#ifi,uio.no -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: 199903180154.RAA24471#erdos,Stanford.EDU -->
<!--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>
[ <a href="../">Other Periods</a>
| <a href="../../">Other mailing lists</a>
| <a href="/search.php3">Search</a>
]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->
Date:
[ <a href="msg00651.html">Previous</a>
| <a href="msg00653.html">Next</a>
]
Thread:
[ <a href="msg00638.html">Previous</a>
| <a href="msg00656.html">Next</a>
]
Index:
[ <A HREF="author.html#00652">Author</A>
| <A HREF="#00652">Date</A>
| <A HREF="thread.html#00652">Thread</A>
]
<!--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 <<A HREF="mailto:olag#ifi,uio.no">olag#ifi,uio.no</A>></LI>
<LI><em>Date</em>: Fri, 19 Mar 1999 01:44:31 +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>
Mark Gritter wrote:
>
> Ola Fosheim =?iso-8859-1?Q?Gr=F8stad?= writes:
> >
> > "Jon A. Lambert" wrote:
> > > But you have changed your requirements above from speed to memory.
> > > No fair. ;)
> >
> > fragmented memory access == slow => memory == speed
> >
>
> True. But almost _any_ large-scale random-access data structure is gonna
> have bad memory locality, so in general, the fewer accesses, the better.
> I and a couple of my research group members were talking about this, this
> afternoon.
>
> Although a trie could easily use 10x or more memory than a binary tree,
> the number of cache lines you're accessing is likely to be much smaller
> during a lookup, and that's generally a big win. (Assuming you have enough
> memory so you don't have to page, of course.)
Uhm... But a hashtable would only access like... 3-5 cachelines? (I
don't think trees and tries qualifies as random-access structures
either) The benefit of the binary tree is that it is efficient to
traverse... So we agree, we need to know what the datastructure is going
to be used for. For instance, if you want to display a sorted "all
players" list then a binary tree (or a balancing variant) would do ok.
*shrug*
> Binary-tree cache behavior could be improved significantly by limiting the
> key length and adding some space overhead to the node:
> struct node {
> char key[24];
> struct node *left, *right;
> };
sizeof(struct node) == 36... Maybe it would be better if one clustered
those variables whose bytes are most likely to be accessed? ;^)
struct node {
struct node *left, *right;
char key[ANY_LENGTH]; // will usually only access the first few bytes
object *obj; // almost never accessed
}
Of course, if you keep thinking like this then you will never get a MUD
up and running ;) With 1000 names then you would only access about 10
nodes (cachelines) per lookup.. Not too bad?
Another option would be to only store the first 4 bytes in the node, and
revert to the object itself if there is a match (sizeof(node)==16 :).
Sketch:
struct node {struct node *l,*r; uint32 key; object *obj;}
object *findobj(char *key,node *n){
uint32 k; int i=0;
do{k<<=8;k|=key[i++];}while((i&3)&&(!(k&255)));
if(i||(!key[4])){ //strlen(key)<=4
i=4-i;while(i--)k<<=8;
do{
if(k<n->key){n=n->l; continue;}
if(k>n->key){n=n->r; continue;}
return n->obj;
}while(n);
return NULL;
}
do{
if(k<n->key){n=n->l; continue;}
if(k>n->key){n=n->r; continue;}
i=strcmp(key+4,n->obj->key+4);
if(i<0){n=n->l; continue;} //is this right??
if(i>0){n=n->r; continue;}
return n->obj;
}while(n);
return NULL;
}
Don't complain about readability! :)
Oh yeah, while we are at it, why not limit names to 12 characters and
allow only 30 unique symbols (0 used for padding, 1 used for illegal
characters), then we could bitcompress it and fit the key in 60 bits...
Would be nice for client-server protocols as well...
inline long long convert(char *s){
long long k=0;int i=0;
do{
k<<=5;
k|=translationtable[s[i++]];
if(!(k&0x1e)){
if(k&1) throw "illegal character";
i=12-i;
return k<<((i<<2)+i);
}
}while(i<12);
if(!s[12])throw "string too long";
return k;
}
object* findobj(char *key,node *n){
long long k=convert(key);
for(;;){
if(k<n->key){n=n->l; if(n)continue; return 0;}
if(k>n->key){n=n->r; if(n)continue; return 0;}
return n->obj;
}
assert(1);
}
I don't think this would be too slow? Hmm.. I might use that...
--
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="00656" HREF="msg00656.html">Re: [MUD-Dev] Naming and Directories?</A></strong>
<ul compact><li><em>From:</em> Mark Gritter <mark#erdos,Stanford.EDU></li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="00638" HREF="msg00638.html">Re: [MUD-Dev] Naming and Directories?</A></STRONG>
<UL><LI><EM>From:</EM> Mark Gritter <mark#erdos,Stanford.EDU></LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00651.html">Re: [MUD-Dev] Re: pet peeves</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00653.html">Re: [MUD-Dev] Naming and Directories?</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00638.html">Re: [MUD-Dev] Naming and Directories?</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00656.html">Re: [MUD-Dev] Naming and Directories?</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00652"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00652"><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>
<ul compact>
<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>
<LI><strong><A NAME="00644" HREF="msg00644.html">Re: [MUD-Dev] Naming and Directories?</A></strong>,
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Thu 18 Mar 1999, 07:44 GMT
<UL>
<LI><strong><A NAME="00653" HREF="msg00653.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
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</ul>
</ul>
</ul>
</ul>
</ul>
</LI>
</UL></BLOCKQUOTE>
</ul>
<hr>
<center>
[ <a href="../">Other Periods</a>
| <a href="../../">Other mailing lists</a>
| <a href="/search.php3">Search</a>
]
</center>
<hr>
</body>
</html>