[PATCH] Implement std::experimental::sample

Evgeniy Stepanov eugenis at google.com
Fri Apr 24 10:58:07 PDT 2015


Switched to reserved identifiers.


================
Comment at: include/experimental/algorithm:53
@@ +52,3 @@
+  for (; __first != __last; ++__first, (void)++__k) {
+    _Distance __r = _VSTD::uniform_int_distribution<>(0, __k)(__g);
+    if (__r < __sz)
----------------
This thing is costing us lots of performance - it's just way too fancy.
It makes this code is about 2x slower than std::random_sample in existing implementations, but I guess it makes the sample more uniform, as well.

Do you thing smth like (__g() - __g::min()) % ( __k + 1) would be acceptable?

================
Comment at: include/experimental/algorithm:49
@@ +48,3 @@
+  Distance k = 0;
+  for (; first != last && k < n; ++first, ++k)
+    out[k] = *first;
----------------
EricWF wrote:
> We need a void cast like `++first, (void) ++k` to prevent calling a comma operator overload.
done

http://reviews.llvm.org/D9044

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list