Joel F Real men use unique_ptr | Ah mon brave musaran je te le fait pas dire que c stupide ...
Si j'y pouvais qqchose ...
Enfin, pour les courageux :
Code :
- bool TBLFile::save( const char* filename )
- {
- bool result;
- unsigned long numberofmisses;
- unsigned long hashvalue;
- unsigned short hashoffset;
- unsigned short* hashIndices;
- TBLPAIRHEADER* nodes;
- unsigned char* define;
- FILE* file;
- if( header )
- {
- AnsiString allstring;
- unsigned short size = values.size();
- unsigned long stringoffset = 21 + 19*size;
- unsigned long highestnbrofmisses = 0;
- unsigned long strsize = 0;
- hashIndices = new unsigned short[size];
- nodes = new TBLPAIRHEADER[size];
- define = new unsigned char[size];
- memset( define, 0, size );
- for( int j = 0; j < size; j++ )
- {
- strsize += values[j]->key.length();
- strsize += values[j]->value.length();
- }
- strsize += 2*size;
- allstring.SetLength( strsize );
- allstring = "";
- for( int i = 0; i < size; i++ )
- {
- numberofmisses = 0;
-
- // No time influence.
- //
- hashvalue = hash( values[i]->key.c_str(), size );
- hashoffset = hashvalue;
- // No time influence.
- //
- while( define[hashoffset] != 0 )
- {
- numberofmisses++;
- hashoffset++;
- hashoffset %= size;
- }
- highestnbrofmisses = ( numberofmisses > highestnbrofmisses ? numberofmisses : highestnbrofmisses );
- hashIndices[i] = hashoffset;
- define[hashoffset] = 1;
- nodes[hashoffset].used = 1;
- nodes[hashoffset].dummy = i;
- nodes[hashoffset].hashNbr = hashvalue;
- nodes[hashoffset].keyOffset = stringoffset + allstring.Length();
- allstring += values[i]->key.c_str();
- allstring += '\0';
- nodes[hashoffset].stringOffset = stringoffset + allstring.Length();;
- nodes[hashoffset].strlength = values[i]->value.length()+1;
- allstring += values[i]->value.c_str();
- allstring += '\0';
- }
- file = fopen( filename, "wb" );
- header->CRC = CRC( allstring );
- header->numElts = (unsigned short)size;
- header->hashSize = size;
- header->unknown = 1;
- header->indexStart = stringoffset;
- header->missNbr = highestnbrofmisses + 1;
- header->indexEnd = stringoffset + allstring.Length();
- if( file )
- {
- fwrite( header, 1, 21, file );
- fwrite( hashIndices, 1, 2*size, file);
- fwrite( nodes, 1, 17*size, file );
- fwrite( allstring.c_str(), 1, allstring.Length(), file );
- fclose( file );
- result = true;
- }
- else
- {
- result = false;
- }
- delete[] nodes;
- delete[] define;
- delete[] hashIndices;
- }
- else
- {
- result = false;
- }
- return result;
- }
|
je vous fait grace des acrobaties arithmetiques des fonctions hash et CRC.
Les commentaires // No time influence montre les endroits ou je suis sur que c pas ca qui rame.
V essayer s'titoire de buffer.
PS : le truc du char* deja essayer ... donne pas mieux |