zipf/pareto/gauss: add option to disable hashing
authorJens Axboe <axboe@fb.com>
Tue, 17 May 2016 00:09:43 +0000 (18:09 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 17 May 2016 00:09:43 +0000 (18:09 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
lib/gauss.c
lib/gauss.h
lib/zipf.c
lib/zipf.h

index afd0490d54786130acf04e0bb3c64bd8a4473bbd..48e2fbfef776ecd298a65e6771d3b4e797534693 100644 (file)
@@ -38,7 +38,10 @@ unsigned long long gauss_next(struct gauss_state *gs)
                sum += dev;
        }
 
                sum += dev;
        }
 
-       return __hash_u64(sum) % gs->nranges;
+       if (!gs->disable_hash)
+               return __hash_u64(sum) % gs->nranges;
+
+       return sum % gs->nranges;
 }
 
 void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
 }
 
 void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
@@ -54,3 +57,8 @@ void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
                        gs->stddev = nranges / 2;
        }
 }
                        gs->stddev = nranges / 2;
        }
 }
+
+void gauss_disable_hash(struct gauss_state *gs)
+{
+       gs->disable_hash = true;
+}
index a76df3f27206a46dfe2e3ff5741bfdce37c518a5..478aa146896b5ea2ad41da7b0f5914ed00c2a745 100644 (file)
@@ -8,10 +8,12 @@ struct gauss_state {
        struct frand_state r;
        uint64_t nranges;
        unsigned int stddev;
        struct frand_state r;
        uint64_t nranges;
        unsigned int stddev;
+       bool disable_hash;
 };
 
 void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
                unsigned int seed);
 unsigned long long gauss_next(struct gauss_state *gs);
 };
 
 void gauss_init(struct gauss_state *gs, unsigned long nranges, double dev,
                unsigned int seed);
 unsigned long long gauss_next(struct gauss_state *gs);
+void gauss_disable_hash(struct gauss_state *gs);
 
 #endif
 
 #endif
index d8e72b15c6a1e04601e9febdd84eb862f715ae4d..8b581fafff6e9e0dd8b1423d7e7d0b9e5e2d94de 100644 (file)
@@ -69,7 +69,10 @@ unsigned long long zipf_next(struct zipf_state *zs)
        else
                val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha));
 
        else
                val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha));
 
-       return (__hash_u64(val - 1) + zs->rand_off) % zs->nranges;
+       if (!zs->disable_hash)
+               return (__hash_u64(val - 1) + zs->rand_off) % zs->nranges;
+
+       return (val - 1 + zs->rand_off) % zs->nranges;
 }
 
 void pareto_init(struct zipf_state *zs, unsigned long nranges, double h,
 }
 
 void pareto_init(struct zipf_state *zs, unsigned long nranges, double h,
@@ -84,5 +87,13 @@ 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;
 
        double rand = (double) __rand(&zs->rand) / (double) FRAND32_MAX;
        unsigned long long n = zs->nranges - 1;
 
-       return (__hash_u64(n * pow(rand, zs->pareto_pow)) + zs->rand_off) % zs->nranges;
+       if (!zs->disable_hash)
+               return (__hash_u64(n * pow(rand, zs->pareto_pow)) + zs->rand_off) % zs->nranges;
+
+       return (unsigned long long) (n * pow(rand, zs->pareto_pow) + zs->rand_off) % zs->nranges;
+}
+
+void zipf_disable_hash(struct zipf_state *zs)
+{
+       zs->disable_hash = true;
 }
 }
index f98ad8182883142e5232000388126534ef3fefe6..af2d0e645c1e462df12190d9669bf5ebf18593d9 100644 (file)
@@ -12,6 +12,7 @@ struct zipf_state {
        double pareto_pow;
        struct frand_state rand;
        uint64_t rand_off;
        double pareto_pow;
        struct frand_state rand;
        uint64_t rand_off;
+       bool disable_hash;
 };
 
 void zipf_init(struct zipf_state *zs, unsigned long nranges, double theta, unsigned int seed);
 };
 
 void zipf_init(struct zipf_state *zs, unsigned long nranges, double theta, unsigned int seed);
@@ -19,5 +20,6 @@ unsigned long long zipf_next(struct zipf_state *zs);
 
 void pareto_init(struct zipf_state *zs, unsigned long nranges, double h, unsigned int seed);
 unsigned long long pareto_next(struct zipf_state *zs);
 
 void pareto_init(struct zipf_state *zs, unsigned long nranges, double h, unsigned int seed);
 unsigned long long pareto_next(struct zipf_state *zs);
+void zipf_disable_hash(struct zipf_state *zs);
 
 #endif
 
 #endif