Z S newSymbol(const C *str,S prevsym) { int mw; SBS cur,prev; S res; mw=((12+strlen(str))>>2)&~0x01; for(cur=&SymBlockListHead,prev=cur;cur=cur->next;prev=cur) { if (cur->size-cur->idx>=mw) break; } if(!cur) { allocNewBlock(mw); prev=&SymBlockListHead; cur=prev->next; } res=(S)(cur->buf+cur->idx); res->s=prevsym->s,prevsym->s=res,strcpy(res->n,str); /* See if we need to move block to Full list. */ cur->idx += mw; ++cur->count; if(cur->size-cur->idx<SBS_BLOCKTHRESHOLD) { prev->next=cur->next; cur->next=FullSymBlockList; FullSymBlockList=cur; } /* See if we need to grow hash table. */ if(SymHashTable->nb*SBS_TRIGGERRATIO<++SymHashTable->ni)growSymHashTable(); R res; }
int dbfile::findEnoughSpace(int offset, int size) { unsigned int block_count = m_file.GetLength() / 4096; int array[2]; if(offset == 0) offset = 1; for(int i = offset; i < block_count; i++) { m_file.Seek(i*4096,CFile::begin); m_file.Read((void *)array,8); if(array[1] + 1 - 2*4 - array[0]*8 >= size + 8) return i; } return allocNewBlock(); }