File src/hashset.c changed (mode: 100644) (index aec790a..b3f837b) |
... |
... |
void hashset_init(HashSet * hs) |
26 |
26 |
{ |
{ |
27 |
27 |
int i; |
int i; |
28 |
28 |
hs->currentSize = 0; |
hs->currentSize = 0; |
29 |
|
for( i = 0; i < HASH_MAP_SIZE; i++ ) { |
|
30 |
|
hs->lists[ i ] = NULL; |
|
|
29 |
|
for(i = 0; i<HASH_MAP_SIZE; i++) { |
|
30 |
|
hs->lists[i] = NULL; |
31 |
31 |
} |
} |
32 |
32 |
} |
} |
33 |
33 |
|
|
|
... |
... |
int hashset_contains(const HashSet * hs, const char *key) |
49 |
49 |
|
|
50 |
50 |
int hashset_put(HashSet *hs, const char *key, void *value) |
int hashset_put(HashSet *hs, const char *key, void *value) |
51 |
51 |
{ |
{ |
52 |
|
struct HashSetNode *newNode; |
|
53 |
|
int listNum; |
|
54 |
|
|
|
55 |
|
if( hashset_get( hs, key ) ) |
|
|
52 |
|
if(hashset_get(hs, key)) { |
56 |
53 |
return 0; |
return 0; |
|
54 |
|
} |
57 |
55 |
|
|
58 |
|
listNum = hashmap_hash( key ); |
|
59 |
|
|
|
60 |
|
|
|
61 |
|
newNode=(struct HashSetNode *)malloc(sizeof(struct HashSetNode)); |
|
62 |
|
if( newNode == NULL ) { |
|
63 |
|
fprintf( stderr,"Error allocating node"); |
|
|
56 |
|
int listNum = hashmap_hash( key ); |
|
57 |
|
struct HashSetNode *newNode=(struct HashSetNode *)malloc(sizeof(struct HashSetNode)); |
|
58 |
|
if(newNode == NULL) { |
|
59 |
|
fprintf(stderr,"Unable to allocate hashset entry!"); |
64 |
60 |
return 0; |
return 0; |
65 |
61 |
} |
} |
66 |
62 |
|
|
|
... |
... |
void hashset_stat(const HashSet *hs) |
97 |
93 |
char** hashset_keys(const HashSet *hs) |
char** hashset_keys(const HashSet *hs) |
98 |
94 |
{ |
{ |
99 |
95 |
// TODO to be implemented |
// TODO to be implemented |
|
96 |
|
|
|
97 |
|
char **result=malloc(sizeof(char*) * hs->currentSize); |
|
98 |
|
int i=0, j=0; |
|
99 |
|
for(i=0; i<HASH_MAP_SIZE; i++) { |
|
100 |
|
if(hs->lists[i]) { |
|
101 |
|
while(hs->lists[i]->next) { |
|
102 |
|
printf(">>> %s",hs->lists[i]->key); |
|
103 |
|
result[j++]=hs->lists[i]->key; |
|
104 |
|
} |
|
105 |
|
result[j++]=hs->lists[i]->key; |
|
106 |
|
} |
|
107 |
|
} |
100 |
108 |
return NULL; |
return NULL; |
101 |
109 |
} |
} |
102 |
110 |
|
|
File src/hstr.c changed (mode: 100644) (index 51f2505..0edd472) |
... |
... |
void hstr_getopt(int argc, char **argv, Hstr *hstr) |
1007 |
1007 |
|
|
1008 |
1008 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
1009 |
1009 |
{ |
{ |
1010 |
|
hstr=malloc(sizeof(Hstr)); |
|
|
1010 |
|
const char* commandBlacklist[] = { }; |
|
1011 |
|
HashSet blacklist; |
|
1012 |
|
int i; |
|
1013 |
|
hashset_init(&blacklist); |
|
1014 |
|
for (i = 0; i < 5; i++) { |
|
1015 |
|
hashset_add(&blacklist, commandBlacklist[i]); |
|
1016 |
|
} |
|
1017 |
|
for (i = 0; i < 5; i++) { |
|
1018 |
|
printf("match %d\n", hashset_contains(&blacklist, hstr_strdup(commandBlacklist[i]))); |
|
1019 |
|
} |
|
1020 |
|
|
|
1021 |
|
char **keys=hashset_keys(&blacklist); |
|
1022 |
|
if(keys) { |
|
1023 |
|
for(i=0; i<hashset_size(&blacklist); i++) { |
|
1024 |
|
printf("\nKey: %s", keys[i]); |
|
1025 |
|
} |
|
1026 |
|
} |
|
1027 |
|
|
1011 |
1028 |
|
|
1012 |
|
hstr_init(hstr); |
|
1013 |
|
hstr_get_env_configuration(hstr); |
|
1014 |
|
hstr_getopt(argc, argv, hstr); |
|
1015 |
|
hstr_init_favorites(hstr); |
|
1016 |
|
hstr_main(hstr); |
|
1017 |
1029 |
|
|
1018 |
|
favorites_destroy(hstr->favorites); |
|
1019 |
|
free(hstr); |
|
1020 |
1030 |
|
|
1021 |
|
return EXIT_SUCCESS; |
|
|
1031 |
|
// hstr=malloc(sizeof(Hstr)); |
|
1032 |
|
// |
|
1033 |
|
// hstr_init(hstr); |
|
1034 |
|
// hstr_get_env_configuration(hstr); |
|
1035 |
|
// hstr_getopt(argc, argv, hstr); |
|
1036 |
|
// hstr_init_favorites(hstr); |
|
1037 |
|
// hstr_main(hstr); |
|
1038 |
|
// |
|
1039 |
|
// favorites_destroy(hstr->favorites); |
|
1040 |
|
// free(hstr); |
|
1041 |
|
// |
|
1042 |
|
// return EXIT_SUCCESS; |
1022 |
1043 |
} |
} |
File tests/src/test_hashset.c changed (mode: 100644) (index c0ae7e3..6c14162) |
... |
... |
void testBlacklist() { |
19 |
19 |
hashset_add(&blacklist, commandBlacklist[i]); |
hashset_add(&blacklist, commandBlacklist[i]); |
20 |
20 |
} |
} |
21 |
21 |
for (i = 0; i < 5; i++) { |
for (i = 0; i < 5; i++) { |
22 |
|
printf("match %d\n", |
|
23 |
|
hashset_contains(&blacklist, hstr_strdup(commandBlacklist[i]))); |
|
|
22 |
|
printf("match %d\n", hashset_contains(&blacklist, hstr_strdup(commandBlacklist[i]))); |
|
23 |
|
} |
|
24 |
|
|
|
25 |
|
char **keys=hashset_keys(&blacklist); |
|
26 |
|
if(keys) { |
|
27 |
|
for(i=0; i<hashset_size(&blacklist); i++) { |
|
28 |
|
printf("\nKey: %s", keys[i]); |
|
29 |
|
} |
24 |
30 |
} |
} |
25 |
31 |
} |
} |
26 |
32 |
|
|
|
... |
... |
int main(int argc, char *argv[]) |
28 |
34 |
{ |
{ |
29 |
35 |
testBlacklist(); |
testBlacklist(); |
30 |
36 |
} |
} |
31 |
|
|
|