pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:16:      #include <errno.h>   #include <float.h>   #include <ctype.h>   #include <math.h>      #ifndef HUGE   #define HUGE HUGE_VAL   #endif /*!HUGE*/    - RCSID("$Id: stralloc.c,v 1.61 1999/08/14 15:09:27 per Exp $"); + RCSID("$Id: stralloc.c,v 1.62 1999/09/02 04:40:49 hubbe Exp $");      #define BEGIN_HASH_SIZE 997   #define MAX_AVG_LINK_LENGTH 3 - #define HASH_PREFIX 64 +     -  + /* Experimental dynamic hash length */ + #ifndef HASH_PREFIX + static unsigned int HASH_PREFIX=32; + static int need_more_hash_prefix=0; + #endif +    unsigned INT32 htable_size=0;   static unsigned int hashprimes_entry=0;   static struct pike_string **base_table=0;   static unsigned INT32 full_hash_value;   unsigned INT32 num_strings=0;      /*** Main string hash function ***/         #define StrHash(s,len) low_do_hash(s,len,0)
pike.git/src/stralloc.c:275:      /*\ find a string in the shared string table.   ||| This assumes that the string is minimized!!!!   \*/   static struct pike_string *internal_findstring(const char *s,    int len,    int size_shift,    int h)   {    struct pike_string *curr,**prev, **base; + #ifndef HASH_PREFIX +  unsigned int depth=0; + #endif       for(base = prev = base_table + h;( curr=*prev ); prev=&curr->next)    {   #ifdef PIKE_DEBUG    if(curr->refs<1)    {    debug_dump_pike_string(curr, 70);    locate_problem(has_zero_refs);    fatal("String with no references.\n");    }
pike.git/src/stralloc.c:297:    if (full_hash_value == curr->hval &&    len==curr->len &&    size_shift==curr->size_shift &&    !MEMCMP(curr->str, s,len<<size_shift)) /* found it */    {    *prev = curr->next;    curr->next = *base;    *base = curr;    return curr; /* pointer to string */    } + #ifndef HASH_PREFIX +  depth++; + #endif    } -  + #ifndef HASH_PREFIX +  /* These heuruistics might require tuning! /Hubbe */ +  if(depth > HASH_PREFIX && HASH_PREFIX<len) +  { +  need_more_hash_prefix++; + /* fprintf(stderr,"depth=%d num_strings=%d need_more_hash_prefix=%d HASH_PREFIX=%d\n",depth,num_strings,need_more_hash_prefix,HASH_PREFIX); */ +  }else{ +  if(need_more_hash_prefix) +  need_more_hash_prefix--; +  } + #endif    return 0; /* not found */   }      struct pike_string *binary_findstring(const char *foo, INT32 l)   {    return internal_findstring(foo, l, 0, StrHash(foo,l));   }      struct pike_string *findstring(const char *foo)   {
pike.git/src/stralloc.c:365:    int h,old;    struct pike_string **old_base;       old=htable_size;    old_base=base_table;       htable_size=hashprimes[++hashprimes_entry];    base_table=(struct pike_string **)xalloc(sizeof(struct pike_string *)*htable_size);    MEMSET((char *)base_table,0,sizeof(struct pike_string *)*htable_size);    -  for(h=0;h<old;h++) rehash_string_backwards(old_base[h]); +  for(h=0;h<old;h++) +  rehash_string_backwards(old_base[h]);       if(old_base)    free((char *)old_base);   }         /*** Make new strings ***/      /* note that begin_shared_string expects the _exact_ size of the string,    * not the maximum size
pike.git/src/stralloc.c:401:      static void link_pike_string(struct pike_string *s, int h)   {    s->refs = 0;    s->next = base_table[h];    base_table[h] = s;    s->hval=full_hash_value;    num_strings++;    if(num_strings > MAX_AVG_LINK_LENGTH * htable_size)    rehash(); +  + #ifndef HASH_PREFIX +  /* These heuruistics might require tuning! /Hubbe */ +  if(need_more_hash_prefix > ( htable_size >> 4)) +  { +  /* This could in theory have a pretty ugly complexity */ +  /* /Hubbe +  */ +  unsigned INT32 save_full_hash_value=full_hash_value; +  +  need_more_hash_prefix=0; +  HASH_PREFIX=HASH_PREFIX*2; + /* fprintf(stderr,"Doubling HASH_PREFIX to %d and rehashing\n",HASH_PREFIX); */ +  +  for(h=0;h<htable_size;h++) +  { +  struct pike_string *tmp=base_table[h]; +  base_table[h]=0; +  while(tmp) +  { +  int h2; +  struct pike_string *tmp2=tmp; /* First unlink */ +  tmp=tmp2->next; +  +  h2=do_hash(tmp2); /* compute new hash value */ +  tmp2->hval=full_hash_value; +  +  tmp2->next=base_table[h2]; /* and re-hash */ +  base_table[h2]=tmp2;    } -  +  } +  full_hash_value=save_full_hash_value; +  } + #endif + }      struct pike_string *debug_begin_wide_shared_string(int len, int shift)   {    struct pike_string *t;   #ifdef PIKE_DEBUG    extern int d_flag;    if(d_flag>10)    verify_shared_strings_tables();   #endif    t=(struct pike_string *)xalloc((len<<shift) + sizeof(struct pike_string));