MCPcopy Create free account
hub / github.com/apache/arrow / ShuffleListViewDataInPlace

Function ShuffleListViewDataInPlace

cpp/src/arrow/testing/random.cc:744–772  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

742/// \param[in,out] data The array to shuffle
743template <typename ListViewType>
744void ShuffleListViewDataInPlace(SeedType seed, ArrayData* data) {
745 DCHECK_EQ(data->type->id(), ListViewType::type_id);
746 using offset_type = typename ListViewType::offset_type;
747
748 auto* validity = data->GetMutableValues<uint8_t>(0, 0);
749 auto* offsets = data->GetMutableValues<offset_type>(1);
750 auto* sizes = data->GetMutableValues<offset_type>(2);
751
752 pcg32 rng(seed);
753 using UniformDist = std::uniform_int_distribution<int64_t>;
754 UniformDist dist;
755 for (int64_t i = data->length - 1; i > 0; --i) {
756 const auto j = dist(rng, UniformDist::param_type(0, i));
757 if (ARROW_PREDICT_TRUE(i != j)) {
758 // Swap validity bits
759 if (validity) {
760 const bool valid_i = bit_util::GetBit(validity, data->offset + i);
761 const bool valid_j = bit_util::GetBit(validity, data->offset + i);
762 if (valid_i != valid_j) {
763 bit_util::SetBitTo(validity, data->offset + i, valid_j);
764 bit_util::SetBitTo(validity, data->offset + j, valid_i);
765 }
766 }
767 // Swap offsets and sizes
768 std::swap(offsets[i], offsets[j]);
769 std::swap(sizes[i], sizes[j]);
770 }
771 }
772}
773
774/// \brief Generate the list-view offsets based on a random buffer of sizes.
775///

Callers

nothing calls this directly

Calls 4

swapFunction · 0.85
GetBitFunction · 0.50
SetBitToFunction · 0.50
idMethod · 0.45

Tested by

no test coverage detected