Wednesday, December 12, 2018

Text8 in operation at the symbol table

Below is a symbol search using text8 longs.  text8 are eight byte string packed into a 64 bit word. Not, thus, this symbol look p can use arithmetic greater or lesser for fast switching down the symbol tree.  The tree will automatically cluster accoring to scope if the naming convention is set.  Search time is log N for most typical word look up, but each compare is a single instruction in 64 bit.I keep this as a keeper, nothing can improve on it, it is optimal.  This is default for the linux bus generic symbol access, it will be a loadable. Remember, we can always design the two step tables and expand he word length as we wish.

Code below the fold.  This super fast symbol system will be integrated into Shunt to make Hardly an easy thing. But I can integrate Default variables into Shunt, a great match that is Hardly Default.



Sym * GetText8Sym(Text8 t,PSym * prev) {
Text8 s;
PSym  sm= syms; // enterat syms[0];
while(sm) {
if(*prev) *prev=sm;
s=sm->val;
if(s.l == t.l) return(sm);
if(t.l < s.l ) {
if(!sm->p1 )  {
sm->p1 = (void *) calloc(1,sizeof(Sym));
((PSym) sm->p1)->val= t;
return(sm->p1);
} else
sm = sm->p1;
}
else {
if(!sm->p2) {
sm->p2=( void *) calloc(1,sizeof(Sym));
((PSym) sm->p2)->val = t;
return(sm->p2);
} else
   sm =  sm->p2;
  }

}

return(sm);
}

No comments: