MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / ShuffleRange

Function ShuffleRange

test/common/gtest/gtest.cpp:718–735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

716// shuffle to the end of the vector.
717template <typename E>
718void ShuffleRange(internal::Random* random, int begin, int end,
719 std::vector<E>* v) {
720 const int size = static_cast<int>(v->size());
721 GTEST_CHECK_(0 <= begin && begin <= size)
722 << "Invalid shuffle range start " << begin << ": must be in range [0, "
723 << size << "].";
724 GTEST_CHECK_(begin <= end && end <= size)
725 << "Invalid shuffle range finish " << end << ": must be in range ["
726 << begin << ", " << size << "].";
727
728 // Fisher-Yates shuffle, from
729 // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
730 for (int range_width = end - begin; range_width >= 2; range_width--) {
731 const int last_in_range = begin + range_width - 1;
732 const int selected = begin + random->Generate(range_width);
733 std::swap((*v)[selected], (*v)[last_in_range]);
734 }
735}
736
737// Performs an in-place shuffle of the vector's elements.
738template <typename E>

Callers 2

ShuffleFunction · 0.85
ShuffleTestsMethod · 0.85

Calls 2

GenerateMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected