zipf/pareto/gauss: hash cleanup
authorJens Axboe <axboe@fb.com>
Tue, 17 May 2016 01:18:09 +0000 (19:18 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 17 May 2016 01:18:09 +0000 (19:18 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
lib/gauss.c
lib/zipf.c

index 48e2fbf..f974490 100644 (file)
@@ -39,7 +39,7 @@ unsigned long long gauss_next(struct gauss_state *gs)
        }
 
        if (!gs->disable_hash)
-               return __hash_u64(sum) % gs->nranges;
+               sum = __hash_u64(sum);
 
        return sum % gs->nranges;
 }
index 8b581fa..681df70 100644 (file)
@@ -69,10 +69,12 @@ unsigned long long zipf_next(struct zipf_state *zs)
        else
                val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha));
 
+       val--;
+
        if (!zs->disable_hash)
-               return (__hash_u64(val - 1) + zs->rand_off) % zs->nranges;
+               val = __hash_u64(val);
 
-       return (val - 1 + zs->rand_off) % zs->nranges;
+       return (val + zs->rand_off) % zs->nranges;
 }
 
 void pareto_init(struct zipf_state *zs, unsigned long nranges, double h,
@@ -85,12 +87,14 @@ void pareto_init(struct zipf_state *zs, unsigned long nranges, double h,
 unsigned long long pareto_next(struct zipf_state *zs)
 {
        double rand = (double) __rand(&zs->rand) / (double) FRAND32_MAX;
-       unsigned long long n = zs->nranges - 1;
+       unsigned long long n;
+
+       n = (zs->nranges - 1) * pow(rand, zs->pareto_pow);
 
        if (!zs->disable_hash)
-               return (__hash_u64(n * pow(rand, zs->pareto_pow)) + zs->rand_off) % zs->nranges;
+               n = __hash_u64(n);
 
-       return (unsigned long long) (n * pow(rand, zs->pareto_pow) + zs->rand_off) % zs->nranges;
+       return (n + zs->rand_off)  % zs->nranges;
 }
 
 void zipf_disable_hash(struct zipf_state *zs)