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

Function ShuffleListViewDataInPlace

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

Source from the content-addressed store, hash-verified

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

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