xaizek / hstr (License: Apachev2) (since 2018-12-07)
Bash and Zsh shell history suggest box - easily view, navigate, search and manage your command history.
Commit 2b205e1be909718dc26fd48f99aaa16d179101d5

Syncing hashset listkeys partial implementation (yet broken).
Author: Martin Dvorak
Author date (UTC): 2014-05-07 20:35
Committer name: Martin Dvorak
Committer date (UTC): 2014-05-07 20:35
Parent(s): cde0b2cd98f4d668ef19c9f3ae6f1edbae18e3a3
Signing key:
Tree: cd590dd649393f2d9f2dc2fafbcbde7affceab8f
File Lines added Lines deleted
src/hashset.c 20 12
src/hstr.c 30 9
tests/src/test_hashset.c 8 3
tests/test_hashset.sh 2 1
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
File tests/test_hashset.sh changed (mode: 100755) (index d403ad4..8758166)
1 1 #!/bin/bash #!/bin/bash
2 2
3 gcc ./src/test_hashset.c ../src/hashset.c -o _hashset
3 clear
4 gcc ./src/test_hashset.c ../src/hashset.c ../src/hstr_utils.c -o _hashset
4 5
5 6 # eof # eof
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/hstr

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/hstr

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master