static int PutEntry(string_index_t si,const char*str,int index) { int i,current,next,N; ub4 hash; ub4 len; int bucket; if(index>=si->size) { int extra1,extra2,old_size,new_size; old_size=si->size; extra1=1+(index-si->size)/DATA_BLOCK_SIZE; extra2=old_size/DATA_BLOCK_SIZE/4; new_size=old_size+DATA_BLOCK_SIZE*((extra1>=extra2)?extra1:extra2); // fprintf(stderr,"resizing data from %d to %d\n",old_size,new_size); si->data=(char**)realloc(si->data,new_size*sizeof(char*)); si->next=(int*)realloc(si->next,new_size*sizeof(int)); expand_free_list(si,old_size,new_size); si->size=new_size; if ((si->mask*FILL_OUTOF)<(si->count*FILL_MAX)) { N=si->mask+1; // fprintf(stderr,"resizing table from %d to %d",N,N+N); si->mask=(si->mask<<1)+1; si->table=(int*)realloc(si->table,(si->mask+1)*sizeof(int)); for(i=0; i<N; i++) { current=si->table[i]; si->table[i]=END_OF_LIST; si->table[N+i]=END_OF_LIST; while(current!=END_OF_LIST) { next=si->next[current]; len=strlen(si->data[current]); hash=hash_4_1((unsigned char*) si->data[current],len,0); bucket=hash&si->mask; assert(bucket==i||bucket==N+i); si->next[current]=si->table[bucket]; si->table[bucket]=current; //fprintf(stderr,"moving %s from %d to %d",si->data[current],i,bucket); current=next; } } } } if (si->next[index]>=0) { //fprintf(stderr,"Cannot put %s at %d: position occupied by %s\n",str,index,si->data[index]); return 1; } cut_from_free_list(si,index); si->data[index]=strdup(str); if (si->data[index]==NULL) { return 1; } len=strlen(str); hash=hash_4_1((unsigned char*) str,len,0); bucket=hash&si->mask; si->next[index]=si->table[bucket]; si->table[bucket]=index; si->count++; return 0; }
static void PutEntry(string_index_t si,const char*str,int s_len,int index){ uint32_t hash; int bucket; ensure_access(si->man,index); HREassert (si->next[index] < 0, "Cannot put %s at %d: position occupied by %s", str,index,si->data[index]); cut_from_free_list(si,index); si->len[index]=s_len; si->data[index]=RTmalloc(s_len+1); memcpy(si->data[index],str,s_len); (si->data[index])[s_len]=0; hash=SuperFastHash(str,s_len,0); bucket=hash&si->mask; si->next[index]=si->table[bucket]; si->table[bucket]=index; si->count++; }