コード例 #1
0
ファイル: main.c プロジェクト: Enari/DVA104
int main()
{
	Tree* tree;
	
	printf("välkommen till skagettikåd\n\n");


	printf("No.items, Sekvential, BinaryST, HashTable\n");

	//loop
	for (int numberOfitems = 50000; numberOfitems <= 5000000; numberOfitems = numberOfitems * 10)
	{
		int* arr = (int*)calloc(numberOfitems, sizeof(int));
		FILE* fp;

		fp = fopen("5 000 000 unika slumpade tal.txt", "r");
		for (int i = 0; i < numberOfitems; i++)
		{
			fscanf(fp, "%d", &arr[i]);
		}
		fclose(fp);

		//stuff
		makeHashTable(arr, numberOfitems);
		tree = makeBST(arr, numberOfitems);
		
		//time variables
		double timeSekventiall = 0;
		double timeBST = 0;
		double timeHash = 0;

		//Genomför sköningen 100 gånger
		for (int i = 0; i < 100; i++)
		{
			int searchfor = 1;
			timeSekventiall += sekventiell(arr, searchfor, numberOfitems);
			timeBST += searchBST(tree, searchfor, numberOfitems);
			timeHash += searchHashTable(arr, searchfor, numberOfitems);
		}

		//dela på 100 för att få genomsnitt
		timeSekventiall = timeSekventiall / 100;
		timeBST = timeBST / 100;
		timeHash = timeHash / 100;
		
		//Print it!
		printf("%8d%10Lf%12Lf%10Lf\n", numberOfitems, timeSekventiall, timeBST, timeHash);

		//free
		free(arr);
		emptyTree(tree, tree->root);
	}





	system("pause");
	return 0;
}
コード例 #2
0
static int
doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
{
    char *dirname, *fontscale_name, *filename, *encdir;
    FILE *fontscale, *encfile;
    DIR *dirp;
    struct dirent *entry;
    FT_Error ftrc;
    FT_Face face;
    ListPtr encoding, xlfd, lp;
    HashTablePtr entries;
    HashBucketPtr *array;
    int i, n, found, rc;
    int isBitmap=0,xl=0;

    if (exclusionSuffix)
        xl = strlen (exclusionSuffix);

    i = strlen(dirname_given);
    if(i == 0)
        dirname = dsprintf("./");
    else if(dirname_given[i - 1] != '/')
        dirname = dsprintf("%s/", dirname_given);
    else
        dirname = dsprintf("%s", dirname_given);

    if(dirname == NULL) {
        perror("dirname");
        exit(1);
    }

    if (onlyEncodings)
	goto encodings;

    entries = makeHashTable();
    if(doBitmaps && !doScalable) {
        readFontScale(entries, dirname);
    }

    if(strcmp(outfilename, "-") == 0)
        fontscale_name = NULL;
    else {
        if(outfilename[0] == '/')
            fontscale_name = dsprintf("%s", outfilename);
        else
            fontscale_name = dsprintf("%s%s", dirname, outfilename);
        if(fontscale_name == NULL) {
            perror("fontscale_name");
            exit(1);
        }
    }

    dirp = opendir(dirname);
    if(dirp == NULL) {
        fprintf(stderr, "%s: ", dirname);
        perror("opendir");
        return 0;
    }

    if(fontscale_name == NULL)
        fontscale = stdout;
    else
        fontscale = fopen(fontscale_name, "wb");

    if(fontscale == NULL) {
        fprintf(stderr, "%s: ", fontscale_name);
        perror("fopen(w)");
        return 0;
    }

    while((entry = readdir(dirp)) != NULL) {
        int have_face = 0;
        char *xlfd_name = NULL;
	struct stat f_stat;
	int tprio = 1;

        xlfd = NULL;

	if (xl) {
	    int dl = strlen (entry->d_name);
	    if (strcmp (entry->d_name + dl - xl, exclusionSuffix) == 0)
		continue;
	}

        filename = dsprintf("%s%s", dirname, entry->d_name);

#define PRIO(x) ((x << 1) + tprio)
#ifdef DT_LNK
	if (entry->d_type != DT_UNKNOWN) {
	    if (entry->d_type == DT_LNK)
		tprio = 0;
	} else
#endif
#ifdef S_ISLNK
	{
#ifndef WIN32
	    if (lstat(filename, &f_stat))
		goto done;
	    if (S_ISLNK(f_stat.st_mode))
		tprio = 0;
#endif
	}
#else
	;
#endif
        if(doBitmaps)
            rc = bitmapIdentify(filename, &xlfd_name);
        else
            rc = 0;

        if(rc < 0)
            goto done;

        if(rc == 0) {
            ftrc = FT_New_Face(ft_library, filename, 0, &face);
            if(ftrc)
                goto done;
            have_face = 1;

            isBitmap = ((face->face_flags & FT_FACE_FLAG_SCALABLE) == 0);

            if(!isBitmap) {
                /* Workaround for bitmap-only SFNT fonts */
                if(FT_IS_SFNT(face) && face->num_fixed_sizes > 0 &&
                   strcmp(FT_Get_X11_Font_Format(face), "TrueType") == 0) {
                    TT_MaxProfile *maxp;
                    maxp = FT_Get_Sfnt_Table(face, ft_sfnt_maxp);
                    if(maxp != NULL && maxp->maxContours == 0)
                        isBitmap = 1;
                }
            }

            if(isBitmap) {
                if(!doBitmaps)
                    goto done;
            } else {
                if(!doScalable)
                    goto done;
            }

            if(isBitmap) {
                BDF_PropertyRec prop;
                rc = FT_Get_BDF_Property(face, "FONT", &prop);
                if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) {
                    xlfd_name = strdup(prop.u.atom);
                    if(xlfd_name == NULL)
                        goto done;
                }
            }
        }

        if(xlfd_name) {
            /* We know it's a bitmap font, and we know its XLFD */
            int n = strlen(xlfd_name);
            if(reencodeLegacy &&
               n >= 12 && strcasecmp(xlfd_name + n - 11, "-iso10646-1") == 0) {
                char *s;

                s = malloc(n - 10);
                memcpy(s, xlfd_name, n - 11);
                s[n - 11] = '\0';
                xlfd = listCons(s, xlfd);
            } else {
                /* Not a reencodable font -- skip all the rest of the loop body */
                putHash(entries, xlfd_name, entry->d_name, PRIO(filePrio(entry->d_name)));
                goto done;
            }
        }

        if(!have_face) {
            ftrc = FT_New_Face(ft_library, filename, 0, &face);
            if(ftrc)
                goto done;
            have_face = 1;
            isBitmap = ((face->face_flags & FT_FACE_FLAG_SCALABLE) == 0);

            if(!isBitmap) {
                if(face->num_fixed_sizes > 0) {
                    TT_MaxProfile *maxp;
                    maxp = FT_Get_Sfnt_Table(face, ft_sfnt_maxp);
                    if(maxp != NULL && maxp->maxContours == 0)
                        isBitmap = 1;
                }
            }
        }

        if(xlfd == NULL)
            xlfd = makeXLFD(entry->d_name, face, isBitmap);

        found = 0;

        for(lp = xlfd; lp; lp = lp->next) {
            char buf[MAXFONTNAMELEN];
            for(encoding = encodings; encoding; encoding = encoding->next) {
                if(checkEncoding(face, encoding->value)) {
                    found = 1;
                    snprintf(buf, MAXFONTNAMELEN, "%s-%s",
                            lp->value, encoding->value);
                    putHash(entries, buf, entry->d_name, PRIO(filePrio(entry->d_name)));
                }
            }
            for(encoding = extra_encodings; encoding;
                encoding = encoding->next) {
                if(checkExtraEncoding(face, encoding->value, found)) {
                    /* Do not set found! */
                    snprintf(buf, MAXFONTNAMELEN, "%s-%s",
                            lp->value, encoding->value);
                    putHash(entries, buf, entry->d_name, PRIO(filePrio(entry->d_name)));
                }
            }
        }
    done:
        if(have_face)
            FT_Done_Face(face);
        deepDestroyList(xlfd);
        xlfd = NULL;
        free(filename);
#undef PRIO
    }

    closedir(dirp);
    n = hashElements(entries);
    fprintf(fontscale, "%d\n", n);
    array = hashArray(entries, 1);
    for(i = 0; i < n; i++)
        fprintf(fontscale, "%s %s\n", array[i]->value, array[i]->key);
    destroyHashArray(array);
    entries = NULL;
    if(fontscale_name) {
        fclose(fontscale);
        free(fontscale_name);
    }

 encodings:
    encdir = dsprintf("%s%s", dirname, "encodings.dir");

    if(encdir == NULL) {
	perror("encodings");
	exit(1);
    }
    unlink(encdir);

    if (numEncodings) {
	encfile = fopen(encdir, "w");
	if(encfile == NULL) {
	    perror("open(encodings.dir)");
	    exit(1);
	}
        fprintf(encfile, "%d\n", numEncodings);
        encodingsToDo = sortList(encodingsToDo);
        for(lp = encodingsToDo; lp; lp = lp->next) {
            fprintf(encfile, "%s\n", lp->value);
        }
	fclose (encfile);
    }

    free(dirname);
    return 1;
}