salad: fix mhash 'random' method
Mhash 'random' method is supposed to return a valid node id given an arbitrary integer, likely generated randomly. But on some values it was returning 'end' marker despite emptiness of the container. This was because of confusion in usage of mh_size() and mh_end(). Mh_size() means real number of objects, stored in the cache, while mh_end() means hash capacity, or 'number of buckets' as it is named. Generally capacity is bigger than size, and sometimes it led to a situation like this: size = 1 capacity = 4 rnd = 3 [0] [1] [2] [3] - - x - When code iterates only 'size' times, looking for an element starting from 'rnd' position, it will not find anything. It should iterate 'capacity' times instead.
Showing
- src/lib/salad/mhash.h 4 additions, 7 deletionssrc/lib/salad/mhash.h
- test/unit/CMakeLists.txt 2 additions, 0 deletionstest/unit/CMakeLists.txt
- test/unit/mhash.c 63 additions, 1 deletiontest/unit/mhash.c
- test/unit/mhash.result 14 additions, 0 deletionstest/unit/mhash.result
- test/unit/mhash_bytemap.result 14 additions, 0 deletionstest/unit/mhash_bytemap.result
Loading
Please register or sign in to comment