4bd8d0793488ed896bf604d1ce7252fd601df161 kent Sat Dec 19 11:25:30 2020 -0800 Making hashIncInt return the value (after increment, rather than be void. diff --git src/lib/hash.c src/lib/hash.c index 989beb3..783df7e 100644 --- src/lib/hash.c +++ src/lib/hash.c @@ -302,43 +302,45 @@ { struct hashEl *hel = hashLookup(hash, name); if (hel == NULL) errAbort("hashMustFindName: '%s' not found", name); return hel->name; } struct hashEl *hashAddInt(struct hash *hash, char *name, int val) /* Store integer value in hash */ { char *pt = NULL; return hashAdd(hash, name, pt + val); } -void hashIncInt(struct hash *hash, char *name) -/* Increment integer value in hash */ +int hashIncInt(struct hash *hash, char *name) +/* Increment integer value in hash. Return value after increment. */ { struct hashEl *hel = hashLookup(hash, name); if (hel == NULL) { hashAddInt(hash, name, 1); + return 1; } else { - hel->val = ((char *)hel->val)+1; - /* The much simpler ++hel->val works for gnu C, but really adding one to a void pointer - * I think is not well defined. */ + char *ptVal = hel->val; + ptVal += 1; + hel->val = ptVal; + return ptToInt(ptVal); } } long long hashIntSum(struct hash *hash) /* Return sum of all the ints in a hash of ints. */ { long long sum = 0; int i; struct hashEl *hel; for (i=0; i<hash->size; ++i) { for (hel = hash->table[i]; hel != NULL; hel = hel->next) { int num = ptToInt(hel->val); sum += (long long)num;