-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashFuncsAnalyze.cpp
More file actions
67 lines (50 loc) · 2.06 KB
/
HashFuncsAnalyze.cpp
File metadata and controls
67 lines (50 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Programm for testing different hash-functions
#include "./Config.h"
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <time.h>
#include "./Libs/List/Include/List.h"
#include "./Include/HashFunctions.h"
#include "./Include/HashTable.h"
static void PrepareData();
static void ShowGraphs( );
#define FILLING_WORDS_FILENAME "./Data/filling_words.txt"
#define GRAPHS_DATA_FILENAME "./Graphs/data.csv"
int main()
{
// PrepareData();
FILE* input_file = fopen(FILLING_WORDS_FILENAME, "r");
assert(input_file);
FILE* output_file = fopen(GRAPHS_DATA_FILENAME, "w");
assert(output_file);
HashTable hash_table = {};
HashFunc hash_functions_set[N_HASH_FUNCTIONS] = {ConstHash, LenHash, FirstSymbHash, SumHash,
RolHash , RorHash, GnuHash };
// const char hash_functions_names[N_HASH_FUNCTIONS][10] = {"const", "length", "ascii", "sum", "rol", "ror", "myhash"};
for (int hash_func_i = 0; hash_func_i < N_HASH_FUNCTIONS; hash_func_i++)
{
fseek(input_file, 0, SEEK_SET);
int n_words = 0;
fscanf(input_file, "%d", &n_words);
assert(n_words <= HASH_TABLE_MAX_CAPACITY);
// int hash_table_size = n_words / HASH_TABLE_LIST_SIZE; // good
int hash_table_size = 1000; //cringe size
fgetc(input_file);
HashTableCtor(&hash_table, hash_table_size, hash_functions_set[hash_func_i]);
FillHashTable(&hash_table, input_file, n_words);
// HashTableDump(hash_table);
// fprintf(output_file, "%7s, ", hash_functions_names[hash_func_i]);
for (int list_i = 0; list_i < hash_table.size; list_i++)
fprintf(output_file, "%ld, ", hash_table.lists[list_i].size);
fseek(output_file, -2, SEEK_CUR);
fprintf(output_file, "\n");
HashTableDtor(&hash_table);
}
fclose(output_file);
fclose(input_file);
ShowGraphs();
return 1;
}
static void PrepareData() {system("cd ./Data ; make; cd ../");}
static void ShowGraphs( ) {system("cd ./Graphs; make; cd ../");}