| 8 | } |
| 9 | |
| 10 | bool InfoParser::add(const Example& ex) { |
| 11 | for (int i = 0; i < ex.slot_size(); ++i) { |
| 12 | const auto& slot = ex.slot(i); |
| 13 | if (slot.id() >= kSlotIDmax) return false; |
| 14 | auto& sinfo = slot_info_[slot.id()]; |
| 15 | for (int j = 0; j < slot.key_size(); ++j) { |
| 16 | uint64 key = slot.key(j); |
| 17 | sinfo.set_min_key(std::min((uint64)sinfo.min_key(), key)); |
| 18 | sinfo.set_max_key(std::max((uint64)sinfo.max_key(), key + 1)); |
| 19 | } |
| 20 | if (slot.key_size() > 0) { |
| 21 | if (slot.val_size() == slot.key_size()) { |
| 22 | sinfo.set_format(SlotInfo::SPARSE); |
| 23 | } else { |
| 24 | sinfo.set_format(SlotInfo::SPARSE_BINARY); |
| 25 | } |
| 26 | } else if (slot.val_size() > 0) { |
| 27 | sinfo.set_format(SlotInfo::DENSE); |
| 28 | } |
| 29 | sinfo.set_nnz_ex(sinfo.nnz_ex() + 1); |
| 30 | sinfo.set_nnz_ele(sinfo.nnz_ele() + std::max(slot.key_size(), slot.val_size())); |
| 31 | } |
| 32 | ++ num_ex_; |
| 33 | return true; |
| 34 | } |
| 35 | |
| 36 | ExampleInfo InfoParser::info() { |
| 37 | info_.set_num_ex(num_ex_); |
no test coverage detected