| 3243 | |
| 3244 | template <typename ArrowType> |
| 3245 | ModeResult<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 | |
| 3274 | template <typename ArrowType, typename CTYPE = typename ArrowType::c_type> |
| 3275 | void VerifyMode(const std::shared_ptr<Array>& array) { |
nothing calls this directly
no test coverage detected