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

Function NaiveMode

cpp/src/arrow/compute/kernels/aggregate_test.cc:3245–3272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3243
3244template <typename ArrowType>
3245ModeResult<ArrowType> NaiveMode(const Array& array) {
3246 using ArrayType = typename TypeTraits<ArrowType>::ArrayType;
3247 using CTYPE = typename ArrowType::c_type;
3248
3249 std::unordered_map<CTYPE, int64_t> value_counts;
3250
3251 const auto& array_numeric = reinterpret_cast<const ArrayType&>(array);
3252 const auto values = array_numeric.raw_values();
3253 BitmapReader reader(array.null_bitmap_data(), array.offset(), array.length());
3254 for (int64_t i = 0; i < array.length(); ++i) {
3255 if (reader.IsSet()) {
3256 ++value_counts[values[i]];
3257 }
3258 reader.Next();
3259 }
3260
3261 ModeResult<ArrowType> result;
3262 for (const auto& value_count : value_counts) {
3263 auto value = value_count.first;
3264 auto count = value_count.second;
3265 if (count > result.count || (count == result.count && value < result.mode)) {
3266 result.count = count;
3267 result.mode = value;
3268 }
3269 }
3270
3271 return result;
3272}
3273
3274template <typename ArrowType, typename CTYPE = typename ArrowType::c_type>
3275void VerifyMode(const std::shared_ptr<Array>& array) {

Callers

nothing calls this directly

Calls 5

raw_valuesMethod · 0.45
offsetMethod · 0.45
lengthMethod · 0.45
IsSetMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected