Fix deallocation problem and add documentation
This commit is contained in:
parent
e6fe405838
commit
896ff0644a
@ -241,3 +241,10 @@ sampleInfo* getSampleInfo(const char** fileNamesTable, unsigned nbFiles, size_t
|
|||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void freeSampleInfo(sampleInfo *info) {
|
||||||
|
if (info->samplesSizes) free((void*)(info->samplesSizes));
|
||||||
|
if (info->srcBuffer) free((void*)(info->srcBuffer));
|
||||||
|
free(info);
|
||||||
|
}
|
||||||
|
@ -26,8 +26,25 @@ typedef struct {
|
|||||||
}sampleInfo;
|
}sampleInfo;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*! getSampleInfo():
|
||||||
|
* Load from input files and add samples to buffer
|
||||||
|
* @return: a sampleInfo struct containing infomation about buffer where samples are stored,
|
||||||
|
* size of each sample, and total number of samples
|
||||||
|
*/
|
||||||
sampleInfo* getSampleInfo(const char** fileNamesTable, unsigned nbFiles, size_t chunkSize,
|
sampleInfo* getSampleInfo(const char** fileNamesTable, unsigned nbFiles, size_t chunkSize,
|
||||||
unsigned maxDictSize, const unsigned displayLevel);
|
unsigned maxDictSize, const unsigned displayLevel);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*! freeSampleInfo():
|
||||||
|
* Free memory allocated for info
|
||||||
|
*/
|
||||||
|
void freeSampleInfo(sampleInfo *info);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*! saveDict():
|
||||||
|
* Save data stored on buff to dictFileName
|
||||||
|
*/
|
||||||
void saveDict(const char* dictFileName, const void* buff, size_t buffSize);
|
void saveDict(const char* dictFileName, const void* buff, size_t buffSize);
|
||||||
|
@ -46,7 +46,6 @@ static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER;
|
|||||||
***************************************/
|
***************************************/
|
||||||
static const unsigned g_defaultMaxDictSize = 110 KB;
|
static const unsigned g_defaultMaxDictSize = 110 KB;
|
||||||
#define DEFAULT_CLEVEL 3
|
#define DEFAULT_CLEVEL 3
|
||||||
#define DEFAULT_INPUTFILE ""
|
|
||||||
#define DEFAULT_k 200
|
#define DEFAULT_k 200
|
||||||
#define DEFAULT_OUTPUTFILE "defaultDict"
|
#define DEFAULT_OUTPUTFILE "defaultDict"
|
||||||
#define DEFAULT_DICTID 0
|
#define DEFAULT_DICTID 0
|
||||||
@ -135,30 +134,29 @@ int main(int argCount, const char* argv[])
|
|||||||
const char* programName = argv[0];
|
const char* programName = argv[0];
|
||||||
int operationResult = 0;
|
int operationResult = 0;
|
||||||
|
|
||||||
char* inputFile = DEFAULT_INPUTFILE;
|
/* Initialize arguments to default values */
|
||||||
unsigned k = DEFAULT_k;
|
unsigned k = DEFAULT_k;
|
||||||
char* outputFile = DEFAULT_OUTPUTFILE;
|
const char* outputFile = DEFAULT_OUTPUTFILE;
|
||||||
unsigned dictID = DEFAULT_DICTID;
|
unsigned dictID = DEFAULT_DICTID;
|
||||||
unsigned maxDictSize = g_defaultMaxDictSize;
|
unsigned maxDictSize = g_defaultMaxDictSize;
|
||||||
|
|
||||||
|
/* Initialize table to store input files */
|
||||||
const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*));
|
const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*));
|
||||||
unsigned filenameIdx = 0;
|
unsigned filenameIdx = 0;
|
||||||
|
|
||||||
|
/* Parse arguments */
|
||||||
for (int i = 1; i < argCount; i++) {
|
for (int i = 1; i < argCount; i++) {
|
||||||
const char* argument = argv[i];
|
const char* argument = argv[i];
|
||||||
if (longCommandWArg(&argument, "k=")) { k = readU32FromChar(&argument); continue; }
|
if (longCommandWArg(&argument, "k=")) { k = readU32FromChar(&argument); continue; }
|
||||||
if (longCommandWArg(&argument, "dictID=")) { dictID = readU32FromChar(&argument); continue; }
|
if (longCommandWArg(&argument, "dictID=")) { dictID = readU32FromChar(&argument); continue; }
|
||||||
if (longCommandWArg(&argument, "maxdict=")) { maxDictSize = readU32FromChar(&argument); continue; }
|
if (longCommandWArg(&argument, "maxdict=")) { maxDictSize = readU32FromChar(&argument); continue; }
|
||||||
if (longCommandWArg(&argument, "in=")) {
|
if (longCommandWArg(&argument, "in=")) {
|
||||||
inputFile = malloc(strlen(argument) + 1);
|
filenameTable[filenameIdx] = argument;
|
||||||
strcpy(inputFile, argument);
|
|
||||||
filenameTable[filenameIdx] = inputFile;
|
|
||||||
filenameIdx++;
|
filenameIdx++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (longCommandWArg(&argument, "out=")) {
|
if (longCommandWArg(&argument, "out=")) {
|
||||||
outputFile = malloc(strlen(argument) + 1);
|
outputFile = argument;
|
||||||
strcpy(outputFile, argument);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
DISPLAYLEVEL(1, "Incorrect parameters\n");
|
DISPLAYLEVEL(1, "Incorrect parameters\n");
|
||||||
@ -168,7 +166,7 @@ int main(int argCount, const char* argv[])
|
|||||||
|
|
||||||
char* fileNamesBuf = NULL;
|
char* fileNamesBuf = NULL;
|
||||||
unsigned fileNamesNb = filenameIdx;
|
unsigned fileNamesNb = filenameIdx;
|
||||||
int followLinks = 0;
|
int followLinks = 0; /* follow directory recursively */
|
||||||
const char** extendedFileList = NULL;
|
const char** extendedFileList = NULL;
|
||||||
extendedFileList = UTIL_createFileList(filenameTable, filenameIdx, &fileNamesBuf,
|
extendedFileList = UTIL_createFileList(filenameTable, filenameIdx, &fileNamesBuf,
|
||||||
&fileNamesNb, followLinks);
|
&fileNamesNb, followLinks);
|
||||||
@ -194,5 +192,9 @@ int main(int argCount, const char* argv[])
|
|||||||
filenameIdx, blockSize, maxDictSize, zParams.notificationLevel);
|
filenameIdx, blockSize, maxDictSize, zParams.notificationLevel);
|
||||||
operationResult = RANDOM_trainFromFiles(outputFile, info, maxDictSize, ¶ms);
|
operationResult = RANDOM_trainFromFiles(outputFile, info, maxDictSize, ¶ms);
|
||||||
|
|
||||||
|
/* Free allocated memory */
|
||||||
|
UTIL_freeFileList(extendedFileList, fileNamesBuf);
|
||||||
|
freeSampleInfo(info);
|
||||||
|
|
||||||
return operationResult;
|
return operationResult;
|
||||||
}
|
}
|
||||||
|
@ -113,15 +113,8 @@ static size_t RANDOM_buildDictionary(const size_t totalSamplesSize, const BYTE *
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ZDICT_trainFromBuffer_random():
|
|
||||||
* Train a dictionary from an array of samples using the RANDOM algorithm.
|
|
||||||
* Samples must be stored concatenated in a single flat buffer `samplesBuffer`,
|
|
||||||
* supplied with an array of sizes `samplesSizes`, providing the size of each
|
|
||||||
* sample, in order.
|
|
||||||
* The resulting dictionary will be saved into `dictBuffer`.
|
|
||||||
* @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)
|
|
||||||
* or an error code, which can be tested with ZDICT_isError().
|
|
||||||
*/
|
|
||||||
ZDICTLIB_API size_t ZDICT_trainFromBuffer_random(
|
ZDICTLIB_API size_t ZDICT_trainFromBuffer_random(
|
||||||
void *dictBuffer, size_t dictBufferCapacity,
|
void *dictBuffer, size_t dictBufferCapacity,
|
||||||
const void *samplesBuffer, const size_t *samplesSizes, unsigned nbSamples,
|
const void *samplesBuffer, const size_t *samplesSizes, unsigned nbSamples,
|
||||||
|
@ -23,7 +23,14 @@ typedef struct {
|
|||||||
} ZDICT_random_params_t;
|
} ZDICT_random_params_t;
|
||||||
|
|
||||||
|
|
||||||
|
/*! ZDICT_trainFromBuffer_random():
|
||||||
|
* Train a dictionary from an array of samples.
|
||||||
|
* Samples must be stored concatenated in a single flat buffer `samplesBuffer`,
|
||||||
|
* supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order.
|
||||||
|
* The resulting dictionary will be saved into `dictBuffer`.
|
||||||
|
* @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)
|
||||||
|
* or an error code, which can be tested with ZDICT_isError().
|
||||||
|
*/
|
||||||
ZDICTLIB_API size_t ZDICT_trainFromBuffer_random( void *dictBuffer, size_t dictBufferCapacity,
|
ZDICTLIB_API size_t ZDICT_trainFromBuffer_random( void *dictBuffer, size_t dictBufferCapacity,
|
||||||
const void *samplesBuffer, const size_t *samplesSizes, unsigned nbSamples,
|
const void *samplesBuffer, const size_t *samplesSizes, unsigned nbSamples,
|
||||||
ZDICT_random_params_t parameters);
|
ZDICT_random_params_t parameters);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user