dcapwell commented on code in PR #3835:
URL: https://github.com/apache/cassandra/pull/3835#discussion_r1932657750
##########
test/unit/accord/utils/Gens.java:
##########
@@ -336,24 +507,70 @@ public static <T> Gen<Gen<T>> mixedDistribution(T... list)
public static <T> Gen<Gen<T>> mixedDistribution(List<T> list)
{
return rs -> {
- switch (rs.nextInt(0, 2))
+ switch (rs.nextInt(0, 4))
{
case 0: // uniform
return r -> list.get(rs.nextInt(0, list.size()));
- case 1: // zipf
+ case 1: // median biased
+ int median = rs.nextInt(0, list.size());
+ return r -> list.get(r.nextBiasedInt(0, median,
list.size()));
+ case 2: // zipf
List<T> array = list;
if (rs.nextBoolean())
{
array = new ArrayList<>(list);
Collections.reverse(array);
}
return pickZipf(array);
+ case 3: // random weight
+ return randomWeights(list).next(rs);
default:
throw new AssertionError();
}
};
}
+ public static <T> Gen<Gen.IntGen> mixedDistribution(int[] list)
+ {
+ return rs -> {
+ switch (rs.nextInt(0, 4))
+ {
+ case 0: // uniform
+ return r -> list[rs.nextInt(0, list.length)];
+ case 1: // median biased
+ int median = rs.nextInt(0, list.length);
+ return r -> list[r.nextBiasedInt(0, median, list.length)];
+ case 2: // zipf
+ int[] array = list;
+ if (rs.nextBoolean())
+ {
+ array = Arrays.copyOf(array, array.length);
+ reverse(array);
+ }
+ return pickZipf(array);
+ case 3: // random weight
+ return randomWeights(list).next(rs);
+ default:
+ throw new AssertionError();
+ }
+ };
+ }
Review Comment:
we have a pattern of generic and primitive versions, this helps avoid extra
allocations. Given that this change would force boxing I would prefer not to
unify.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]