Exemplo n.º 1
0
static void len_resize(void*arg,void*old_array,int old_size,void*new_array,int new_size){
    DEBUG("extend during len resize from %d to %d",old_size,new_size);
    (void)old_array;
    (void)new_array;
    string_index_t si=(string_index_t)arg;
    expand_free_list(si,old_size,new_size);
	if ((si->mask*FILL_OUTOF)<(si->count*FILL_MAX)){
		int i,current,next,N;
	    uint32_t hash;
    	uint32_t len;
	    int bucket;

		N=si->mask+1;
		DEBUG("resizing table from %d to %d",N,N+N);
		si->mask=(si->mask<<1)+1;
		si->table=(int*)RTrealloc(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=si->len[current];
				hash=SuperFastHash(si->data[current],len,0);
				bucket=hash&si->mask;
				HREassert(bucket==i||bucket==N+i,"error");
				si->next[current]=si->table[bucket];
				si->table[bucket]=current;
				DEBUG("moving %s from %d to %d",si->data[current],i,bucket);
				current=next;
			}
		}
	}   
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
void SIreset(string_index_t si){
	int i,N;
	N=array_size(si->man);
	for(i=0;i<N;i++) {
		if (USED(si,i)) RTfree(si->data[i]);
	}
	si->count=0;
	si->free_list=END_OF_LIST;
	expand_free_list(si,0,N);
	N=si->mask+1;
	for(i=0;i<N;i++) si->table[i]=END_OF_LIST;
}
Exemplo n.º 4
0
void* RBPoolAllctor::alloc(void** header,size_t single_size)
{
	if(NULL==NEXT_NODE(*header))
	{
		expand_free_list(single_size,&NEXT_NODE(*header));
#ifdef _DEBUG
		printf("NOTE:Memory pool expanded at %p\n",NEXT_NODE(*header));
#endif
	}
	void *r_header = *header;
	*header = NEXT_NODE(*header);
	return r_header;
}
Exemplo n.º 5
0
void RBPoolAllctor::new_pool(void** header,size_t single_size)
{
	expand_free_list(single_size,header);
}