| 1447 | } |
| 1448 | |
| 1449 | void MultiSlotDataset::PreprocessInstance() { |
| 1450 | if (!input_channel_ || input_channel_->Size() == 0) { |
| 1451 | return; |
| 1452 | } |
| 1453 | if (!enable_pv_merge_) { // means to use Record |
| 1454 | this->LocalShuffle(); |
| 1455 | } else { // means to use Pv |
| 1456 | auto fleet_ptr = framework::FleetWrapper::GetInstance(); |
| 1457 | input_channel_->Close(); |
| 1458 | std::vector<PvInstance> pv_data; |
| 1459 | input_channel_->ReadAll(input_records_); |
| 1460 | int all_records_num = static_cast<int>(input_records_.size()); |
| 1461 | std::vector<Record*> all_records; |
| 1462 | all_records.reserve(all_records_num); |
| 1463 | for (int index = 0; index < all_records_num; ++index) { |
| 1464 | all_records.push_back(&input_records_[index]); |
| 1465 | } |
| 1466 | |
| 1467 | std::sort(all_records.data(), |
| 1468 | all_records.data() + all_records_num, |
| 1469 | [](const Record* lhs, const Record* rhs) { |
| 1470 | return lhs->search_id < rhs->search_id; |
| 1471 | }); |
| 1472 | if (merge_by_sid_) { |
| 1473 | uint64_t last_search_id = 0; |
| 1474 | for (int i = 0; i < all_records_num; ++i) { |
| 1475 | Record* ins = all_records[i]; |
| 1476 | if (i == 0 || last_search_id != ins->search_id) { |
| 1477 | PvInstance pv_instance = make_pv_instance(); |
| 1478 | pv_instance->merge_instance(ins); |
| 1479 | pv_data.push_back(pv_instance); |
| 1480 | last_search_id = ins->search_id; |
| 1481 | continue; |
| 1482 | } |
| 1483 | pv_data.back()->merge_instance(ins); |
| 1484 | } |
| 1485 | } else { |
| 1486 | for (int i = 0; i < all_records_num; ++i) { |
| 1487 | Record* ins = all_records[i]; |
| 1488 | PvInstance pv_instance = make_pv_instance(); |
| 1489 | pv_instance->merge_instance(ins); |
| 1490 | pv_data.push_back(pv_instance); |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | std::shuffle( |
| 1495 | pv_data.begin(), pv_data.end(), fleet_ptr->LocalRandomEngine()); |
| 1496 | input_pv_channel_->Open(); |
| 1497 | input_pv_channel_->Write(std::move(pv_data)); |
| 1498 | |
| 1499 | pv_data.clear(); |
| 1500 | pv_data.shrink_to_fit(); |
| 1501 | input_pv_channel_->Close(); |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | void MultiSlotDataset::GenerateLocalTablesUnlock(int table_id, |
| 1506 | int feadim, |
nothing calls this directly
no test coverage detected