MCPcopy Create free account
hub / github.com/3proxy/3proxy / inithashtable

Function inithashtable

src/auth.c:909–961  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

907
908#define hvalue(I) ((struct hashentry *)((char *)ht->hashvalues + (I)*(sizeof(struct hashentry) + ht->recsize - 4)))
909int inithashtable(struct hashtable *ht, unsigned nhashsize){
910 unsigned i;
911 clock_t c;
912
913
914#ifdef _WIN32
915 struct timeb tb;
916
917 ftime(&tb);
918
919#else
920 struct timeval tb;
921 struct timezone tz;
922 gettimeofday(&tb, &tz);
923#endif
924 c = clock();
925
926 if(nhashsize<4) return 1;
927 pthread_mutex_lock(&hash_mutex);
928 if(ht->hashtable){
929 myfree(ht->hashtable);
930 ht->hashtable = NULL;
931 }
932 if(ht->hashvalues){
933 myfree(ht->hashvalues);
934 ht->hashvalues = NULL;
935 }
936 ht->hashsize = 0;
937 if(!(ht->hashtable = myalloc((nhashsize>>2) * sizeof(struct hashentry *)))){
938 pthread_mutex_unlock(&hash_mutex);
939 return 2;
940 }
941 if(!(ht->hashvalues = myalloc(nhashsize * (sizeof(struct hashentry) + (ht->recsize-4))))){
942 myfree(ht->hashtable);
943 ht->hashtable = NULL;
944 pthread_mutex_unlock(&hash_mutex);
945 return 3;
946 }
947 ht->hashsize = nhashsize;
948 ht->rnd[0] = myrand(&tb, sizeof(tb));
949 ht->rnd[1] = myrand(ht->hashtable, sizeof(ht->hashtable));
950 ht->rnd[2] = myrand(&c, sizeof(c));
951 ht->rnd[3] = myrand(ht->hashvalues,sizeof(ht->hashvalues));
952 memset(ht->hashtable, 0, (ht->hashsize>>2) * sizeof(struct hashentry *));
953 memset(ht->hashvalues, 0, ht->hashsize * (sizeof(struct hashentry) + ht->recsize -4));
954
955 for(i = 0; i< (ht->hashsize - 1); i++) {
956 hvalue(i)->next = hvalue(i+1);
957 }
958 ht->hashempty = ht->hashvalues;
959 pthread_mutex_unlock(&hash_mutex);
960 return 0;
961}
962
963void hashadd(struct hashtable *ht, const unsigned char* name, unsigned char* value, time_t expires){
964 struct hashentry * hen, *he;

Callers 2

h_nscacheFunction · 0.85
h_nscache6Function · 0.85

Calls 3

myfreeFunction · 0.85
myallocFunction · 0.85
myrandFunction · 0.85

Tested by

no test coverage detected