Example #1
0
File: nile.c Project: Gottox/nile
int
nileDiff(FILE *oldfile, FILE *newfile, FILE *output, enum Options options) {
	int rv = 1;
	off_t oldoff = 0, newoff = 0, lastSkip = 0;
	size_t oldsize, newsize;
	char *olddata = NULL, *newdata = NULL, md5sum[MD5_DIGEST_LENGTH] = { 0 }, header[8];

	if((oldsize = mapfile(oldfile, &olddata)) == -1)
		rv = 1;
	else if((newsize = mapfile(newfile, &newdata)) == -1)
		rv = 1;

	fputs(MAGIC, output);

	// newfile: uncompress and build md5sum
	if((newfile = uncompress(newfile, output, options)) == NULL)
		goto diff_cleanup;
	buildhash(md5sum, newfile);
	fwrite(md5sum, sizeof(md5sum), 1, output);

	// oldfile: uncompress and build md5sum
	if((oldfile = uncompress(oldfile, NULL, options)) == NULL)
		goto diff_cleanup;
	buildhash(md5sum, oldfile);
	fwrite(md5sum, sizeof(md5sum), 1, output);

	// Building Diff
	for(oldoff = newoff = 0; oldoff < oldsize && newoff < newsize;) {
		if(lcs(olddata, &oldoff, oldsize, newdata, &newoff, newsize, &lastSkip, output)) break;
	}
	// write trailing diff
	offtout(lastSkip, header);
	fwrite(header, sizeof(header), 1, output);
	offtout(oldsize - oldoff, header);
	fwrite(header, sizeof(header), 1, output);
	offtout(newsize - newoff, header);
	fwrite(header, sizeof(header), 1, output);
	fwrite(&newdata[newoff], newsize - newoff, 1, output);

diff_cleanup:
	if(oldsize >= 0)
		munmap(olddata, oldsize);
	if(newsize >= 0)
		munmap(newdata, newsize);
	return rv;
}
Example #2
0
int main(int argc, char **argv)
{
	printf("begining...\n");
	clock_t t1, t2, begin, end;

	begin = clock();
	int pkeylen = datalen[0];
	int *pkeydata = (int*)malloc(sizeof(int) * pkeylen);
	assert(pkeydata);

	int fkeylen = datalen[1];
	int *fkeydata = (int*)malloc(sizeof(int) * fkeylen);
	assert(pkeydata);

	loaddata(filenames, 0, pkeylen, pkeydata);
	loaddata(filenames, 1, fkeylen, fkeydata);

	int *hashtable = (int*)malloc(sizeof(int) * TABLESIZE);
	memset(hashtable, 0, sizeof(int) * TABLESIZE);
	assert(hashtable);

	printf("building hashtable...\n");
	t1 = clock();
	buildhash(pkeydata, hashtable, pkeylen);
	t2 = clock();
	printf("build hashtable time = %f\n", (double)(t2 - t1) / CLOCKS_PER_SEC);

	printf("probing...\n");
	t1 = clock();
	probe(hashtable, fkeydata, fkeylen);
	t2 = clock();
	printf("probing time = %f\n", (double)(t2 - t1) / CLOCKS_PER_SEC);

	end = clock();
	printf("total time = %f\n", (double)(end - begin) / CLOCKS_PER_SEC);

	free(hashtable);
	free(fkeydata);
	free(pkeydata);
}