Created
February 15, 2018 06:02
-
-
Save swilly22/64e8ee3e38165063ec39a18e74ba5265 to your computer and use it in GitHub Desktop.
redis dict init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint64_t dictStringHash(const void *key) { | |
return dictGenHashFunction(key, strlen(key)); | |
} | |
void *dictStringDup(void *privdata, const void *key) { | |
DICT_NOTUSED(privdata); | |
size_t key_len = strlen(key); | |
char *copy = malloc((key_len + 1) * sizeof(char)); | |
strcpy(copy, key); | |
copy[key_len] = 0; | |
return copy; | |
} | |
int dictStringKeyCompare(void *privdata, const void *key1, const void *key2) { | |
DICT_NOTUSED(privdata); | |
return strcmp(key1, key2) == 0; | |
} | |
void dictStringDestructor(void *privdata, void *key) { | |
DICT_NOTUSED(privdata); | |
free(key); | |
} | |
void dictMatrixDestructor(void *privdata, void *value) { | |
DICT_NOTUSED(privdata); | |
GrB_Matrix_free((GrB_Matrix*)&value); | |
} | |
void dictVectorDestructor(void *privdata, void *value) { | |
DICT_NOTUSED(privdata); | |
GrB_Vector_free((GrB_Vector*)&value); | |
} | |
/* Maps relation to matrix. */ | |
dictType dictTypeRelations = { | |
dictStringHash, /* hash function */ | |
dictStringDup, /* key dup */ | |
NULL, /* val dup */ | |
dictStringKeyCompare, /* key compare */ | |
dictStringDestructor, /* key destructor */ | |
dictMatrixDestructor /* val destructor */ | |
}; | |
dictCreate(&dictTypeRelations, NULL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment