-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
66 lines (64 loc) · 2.13 KB
/
main.c
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
#include "pair_char_int.h"
#include "pair.c"
#include "vector.c"
void *elem_cpy (const void *elem)
{
int *a = malloc (sizeof (int));
*a = *((int *) elem);
return a;
}
int elem_cmp (const void *elem_1, const void *elem_2)
{
return *((const int *) elem_1) == *((const int *) elem_2);
}
void elem_free (void **elem)
{
free (*elem);
}
/////
int main ()
{
// Insert elements to vec.
vector *vec = vector_alloc (elem_cpy, elem_cmp, elem_free);
for (int i = 0; i < 8; ++i)
{
vector_push_back (vec, &i);
}
vector_free (&vec);
// Create Pairs.
// pair *pairs[8];
// for (int j = 0; j < 8; ++j)
// {
// char key = (char) (j + 48);
// //even keys are capital letters, odd keys are digits
// if (key % 2)
// {
// key += 17;
// }
// int value = j;
// pairs[j] = pair_alloc (&key, &value, char_key_cpy, int_value_cpy, char_key_cmp,
// int_value_cmp, char_key_free, int_value_free);
// }
// // Create hash-map and inserts elements into it, using pair_char_int.h
// hashmap *map = hashmap_alloc (hash_char);
// for (int k = 0; k < 8; ++k)
// {
// hashmap_insert (map, pairs[k]);
// }
// //apply double_value on values where key is a digit
// char key_dig = '2', key_letter = 'D';
// printf ("map['2'] before apply if: %d, map['D'] before apply if: %d\n",
// *(int *) hashmap_at (map, &key_dig), *(int *) hashmap_at (map, &key_letter));
// int apply_if_res = hashmap_apply_if (map, is_digit, double_value);
// printf ("Number of changed values: %d\n", apply_if_res);
// printf ("map['2'] after apply if: %d, map['D'] after apply if: %d\n",
// *(int *) hashmap_at (map, &key_dig), *(int *) hashmap_at (map, &key_letter));
// // Free the pairs.
// for (int k_i = 0; k_i < 8; ++k_i)
// {
// pair_free ((void **) &pairs[k_i]);
// }
// // Free the hash-map.
// hashmap_free (&map);
return 0;
}