Esempio n. 1
0
static s32 binaryFind(LTable* lt, const char* hash)
{
        u32 start = 0;
        u32 end   = lt->n_rows-1;
        while (start != end)
        {
                u32 middle = (start + end) / 2;
                if (bstrncmp(hash, CHASH(middle), lt->l_hash) <= 0)
                        end = middle;
                else
                        start = middle + 1;
        }
        if (bstrncmp(CHASH(start), hash, lt->l_hash) == 0)
                return start;
        else
                return -1;
}
Esempio n. 2
0
static void quicksort(LTable* lt, u32 left, u32 right)
{
	if (left >= right)
		return;

	swap(lt, (left+right)/2, right);
	char* pivotValue = CHASH(right);
	u32 storeIndex = left;
	for (u32 i = left; i < right; i++)
		if (bstrncmp(CHASH(i), pivotValue, lt->l_hash) < 0)
			swap(lt, i, storeIndex++);

	swap(lt, storeIndex, right);

	if (storeIndex)
		quicksort(lt, left, storeIndex-1);
	quicksort(lt, storeIndex+1, right);
}
Esempio n. 3
0
void LTable_Print(LTable* lt)
{
	for (u32 i = 0; i < lt->n_rows; i++)
	{
		printHash(CHASH(i), lt->l_hash);
		printf(" ");
		printString(CSTR(i), lt->l_string);
		printf("\n");
	}
}
Esempio n. 4
0
void ADDHASH(long a,long b, long c)
{
  long *INHASH,*BEFINHASH;
  INHASH=&HASH_TABLE[CHASH(a,b,15)];
  BEFINHASH=INHASH-1;
  *(INHASH--)=*(BEFINHASH--); *(INHASH--)=*(BEFINHASH--); *(INHASH--)=*(BEFINHASH--);
  *(INHASH--)=*(BEFINHASH--); *(INHASH--)=*(BEFINHASH--); *(INHASH--)=*(BEFINHASH--);
  *(INHASH--)=*(BEFINHASH--); *(INHASH--)=*(BEFINHASH--); *(INHASH--)=*(BEFINHASH--);
  *(INHASH--)=*(BEFINHASH--); *(INHASH--)=*(BEFINHASH--); *(INHASH--)=*(BEFINHASH--);
  *(INHASH--)=*(BEFINHASH--); *(INHASH--)=*(BEFINHASH--); *(INHASH)=*(BEFINHASH);
  *BEFINHASH=c;  
}
Esempio n. 5
0
char LTable_Next(LTable* lt)
{
	// compute and store the hash of the current string
	memcpy(CSTR(lt->curidx), lt->curstr, lt->l_string);
	MD5((u8*) CHASH(lt->curidx), (u8*) lt->curstr, lt->l_string);

	// compute next string
	char* c = lt->curstr;
	while (*c)
	{
		char* n = strchr(lt->charset, *c);
		if ((*c = n[1]))
			break;
		*c = lt->charset[0];
		c++;
	}
	if (!*c)
		return 0;

	lt->curidx++;
	return 1;
}
Esempio n. 6
0
static token_t *
ttree_line_parse(ttree_t *t, char **cpp, char **epp, char **hpp, uint32_t *hash)
{
	char	ca, cb;			/* current line <=> parse node */

	char	*cp = *cpp;
	char	*ep = *epp;

	char	*tp = t->tok->text;	/* current parse text */
	char	*sp = cp;		/* saved *cp */

	int	parse;			/* parse state */

	uint32_t hv;			/* hash value */

	if (hash != NULL)
		hv = *hash;

	/* Special case, check for EOH (i.e. empty line) */
	if (cp < ep) {
		ca = *cp;
		if (ca == '\n') {
			/* End of header */
			*cpp = ++cp;
			*hpp = NULL;
			return (NULL);
		} else if (ca == '\r') {
			cp++;
			if (cp < ep) {
				ca = *cp;
				if (ca == '\n') {
					/* End of header */
					*cpp = ++cp;
					*hpp = NULL;
					return (NULL);
				}
			}
			cp = *cpp;
		}
	}
	while (cp < ep) {
		/* Get next parse text char */
		cb = *tp;
		if (cb != 0) {
			/* Get next current line char */
			ca = *cp++;
			/* Case insensitive */
			cb = tolower(cb);
			ca = tolower(ca);
			if (ca == cb) {
				/*
				 * Char match, next char.
				 *
				 * Note, parse text can contain EOL chars.
				 */
				tp++;
				continue;
			}
			if (ca == '\r' || ca == '\n') {
				/* EOL, always go less than */
				t = t->lt;
			} else if (ca < cb) {
				/* Go less than */
				t = t->lt;
			} else {
				/* Go greater than */
				t = t->gt;
			}
			while (t != NULL && t->tok == NULL) {
				/* Null node, so descend to < node */
				t = t->lt;
			}
			if (t != NULL) {
				/* Initialize for next node compare */
				tp = t->tok->text;
				cp = sp;
				continue;
			}
			/*
			 * End of tree walk, no match, return pointer
			 * to the start of line then below find EOL.
			 */
			*hpp = *cpp;
		} else {
			/*
			 * End of token text, match, return pointer to
			 * the rest of header text then below find EOL.
			 */
			*hpp = cp;
		}
		/*
		 * Find end of line. Note, the HTTP line syntax supports
		 * implicit multi-line if the next line starts with a <SP>
		 * or <HT>.
		 */
		parse = 0;
		while (cp < ep) {
			ca = *cp;
			if (parse == 0 && ca == '\r') {
				*epp = cp;
				parse = 1;
			} else if (parse == 0 && ca == '\n') {
				*epp = cp;
				parse = 2;
			} else if (parse == 1 && ca == '\n') {
				parse = 2;
			} else if (parse >= 2 && (ca == ' ' || ca == '\t')) {
				parse++;
			} else if (parse > 2) {
				parse = 0;
			} else if (parse == 2) {
				break;
			} else if (t != NULL && (t->tok->act & HASH) &&
			    hash != NULL) {
				CHASH(hv, ca);
			}
			cp++;
		}
		if (parse < 2) {
			/* No EOL, not enough data */
			*epp = NULL;
			return (t != NULL ? t->tok : NULL);
		}
		/*
		 * Return updated hash value (if any), update parse current
		 * pointer for next call (i.e. begin of next line), and last
		 * return pointer to the matching token_t.
		 */
		if (t != NULL && (t->tok->act & HASH) && hash != NULL)
			*hash = hv;
		*cpp = cp;
		return (t != NULL ? t->tok : NULL);
	}
	/*
	 * End of parse text, ...
	 */
	*epp = NULL;
	return (NULL);
}
Esempio n. 7
0
void PackSLZ(unsigned char *inbuffer, register FILE *outfile)
{
  long int loop1,loop2, startvalue, endvalue, wherefound;
  unsigned char outchars[MAX_COMP_LEN*10];
  unsigned char *a_buffer, *b_buffer;
  short lenoutchars;
  short myTAG, iter;
  short done,found,temp;

#ifdef hashing_on
  long *INHASH;
  short HASHCHECK;

  for(loop1=0;loop1!=65536;loop1++)
    {
      HASH_TABLE[loop1]=-1;
    }
  HASH_TABLE[CHASH(inbuffer[0],inbuffer[1],0)]=0;
#endif

  loop1=1; loop2=length-1; iter=1;  // Always do a literal first byte
  outchars[1]=inbuffer[0]; lenoutchars=2;
  done=FALSE;

  while(! done)
    {
      myTAG=0;
      while((iter<8)&&(! done))
        {

/***--- This is the slowest part.  I should rewrite it in ASM ---***/

          startvalue=loop1-MASK_history;
          if (startvalue<0) startvalue=0;
          found=0;

#ifdef hashing_on
          INHASH=&HASH_TABLE[CHASH(inbuffer[loop1],inbuffer[loop1+1],0)];
          HASHCHECK=16; // Scan for matches in HASH TABLE
          while((HASHCHECK)&&((endvalue=*INHASH++)>=startvalue))
            {
              temp=0;
              a_buffer=&inbuffer[loop1];
              b_buffer=&inbuffer[endvalue];
              while((*(a_buffer++) == *(b_buffer++))&&(temp<MAX_COMP_LEN))
                    {
		      temp++;
		    }
	      if(found<temp)
		{
		  if ((temp+loop1)>length)
		    {
                      temp=length-loop1;
                      if(found<temp) 
			{
			  found=temp;
			  wherefound=endvalue;
			}
		    }
		  else
		    {
		      found=temp;
		      wherefound=endvalue;
		    }
		  if (found=MAX_COMP_LEN) { goto skip1; }
		}
	      HASHCHECK--;
	    }
#else
	  endvalue=loop1-1;
#endif

	  while( endvalue>=startvalue) // Scan for matches
            {
              temp=0;
              a_buffer=&inbuffer[loop1];
              b_buffer=&inbuffer[endvalue];
              while((*(a_buffer++) == *(b_buffer++))&&(temp<MAX_COMP_LEN))
		{
		  temp++;
		}
	      if( found<temp)
		{
		  if ((temp+loop1)>length)
		    {
		      temp=length-loop1;
		      if( found<temp)
			{
			  found=temp;
			  wherefound=endvalue;
			}
		    }
		  else
		    {
		      found=temp;
		      wherefound=endvalue;
		    }
		  if ( found==MAX_COMP_LEN) { goto skip1; }
		}
	      endvalue--;
	    }

	skip1:
	  
	  if(found>2) // Compression will now occur
            {
              myTAG|=(128>>iter);
              endvalue=loop1-wherefound;
              startvalue=((endvalue>>LSR_upper)&MASK_upper)+(found-2);
              outchars[lenoutchars++]=startvalue;
              outchars[lenoutchars++]=(unsigned char)endvalue;
              loop2-=found;
              while(found!=0)
                {
#ifdef hashing_on
                 ADDHASH(inbuffer[loop1],inbuffer[loop1+1],loop1);
#endif
                  loop1++; found--;
                }
            }
          else // No Compression, copy literal byte
            {
#ifdef hashing_on
              ADDHASH(inbuffer[loop1],inbuffer[loop1+1],loop1);
#endif
              outchars[lenoutchars++]=inbuffer[loop1++];
              loop2--;
            }
          if(loop2<=0)
            {
              done=TRUE;
              if(loop2<0)
                {
                  printf("HMMM... ooops!!!\n");
                }
            }
          iter++;
        }