fix fatal bugs

This commit is contained in:
2024-05-25 06:54:56 +00:00
parent 87d50bc193
commit 55c503a0d0
2 changed files with 33 additions and 3 deletions

View File

@ -16,8 +16,15 @@ inline hash_t SplitMix64Hash(const std::string &str) noexcept {
hash_t ret = 0; hash_t ret = 0;
int i = 0; int i = 0;
size_t len = str.length(); size_t len = str.length();
hash_t *buf = new hash_t;
char *buf_ptr = reinterpret_cast<char *>(buf);
for (; i + 8 <= len; i += 8) { for (; i + 8 <= len; i += 8) {
ret ^= *reinterpret_cast<const hash_t *>(str.c_str() + i); // ret ^= *reinterpret_cast<const hash_t *>(str.c_str() + i);
// ret ^= *reinterpret_cast<const hash_t *>(inner_salt + (i & 15));
for (int j = 0; j < 8; ++j) {
buf_ptr[j] = str[i + j];
}
ret ^= *buf;
ret ^= *reinterpret_cast<const hash_t *>(inner_salt + (i & 15)); ret ^= *reinterpret_cast<const hash_t *>(inner_salt + (i & 15));
ret += 0x9e3779b97f4a7c15; ret += 0x9e3779b97f4a7c15;
ret = (ret ^ (ret >> 30)) * 0xbf58476d1ce4e5b9; ret = (ret ^ (ret >> 30)) * 0xbf58476d1ce4e5b9;
@ -32,6 +39,7 @@ inline hash_t SplitMix64Hash(const std::string &str) noexcept {
ret = (ret ^ (ret >> 27)) * 0x94d049bb133111eb; ret = (ret ^ (ret >> 27)) * 0x94d049bb133111eb;
ret ^= ret >> 31; ret ^= ret >> 31;
} }
delete buf;
return ret; return ret;
} }
inline hash_t SplitMix64Hash(const std::string_view &str) noexcept { inline hash_t SplitMix64Hash(const std::string_view &str) noexcept {
@ -43,8 +51,15 @@ inline hash_t SplitMix64Hash(const std::string_view &str) noexcept {
hash_t ret = 0; hash_t ret = 0;
int i = 0; int i = 0;
size_t len = str.length(); size_t len = str.length();
hash_t *buf = new hash_t;
char *buf_ptr = reinterpret_cast<char *>(buf);
for (; i + 8 <= len; i += 8) { for (; i + 8 <= len; i += 8) {
ret ^= *reinterpret_cast<const hash_t *>(str.data() + i); // ret ^= *reinterpret_cast<const hash_t *>(str.data() + i);
// ret ^= *reinterpret_cast<const hash_t *>(inner_salt + (i & 15));
for (int j = 0; j < 8; ++j) {
buf_ptr[j] = str[i + j];
}
ret ^= *buf;
ret ^= *reinterpret_cast<const hash_t *>(inner_salt + (i & 15)); ret ^= *reinterpret_cast<const hash_t *>(inner_salt + (i & 15));
ret += 0x9e3779b97f4a7c15; ret += 0x9e3779b97f4a7c15;
ret = (ret ^ (ret >> 30)) * 0xbf58476d1ce4e5b9; ret = (ret ^ (ret >> 30)) * 0xbf58476d1ce4e5b9;
@ -59,6 +74,7 @@ inline hash_t SplitMix64Hash(const std::string_view &str) noexcept {
ret = (ret ^ (ret >> 27)) * 0x94d049bb133111eb; ret = (ret ^ (ret >> 27)) * 0x94d049bb133111eb;
ret ^= ret >> 31; ret ^= ret >> 31;
} }
delete buf;
return ret; return ret;
} }

View File

@ -281,7 +281,7 @@ void TicketSystemEngine::CheckTransfer(hash_t train1_ID_hash, hash_t train2_ID_h
PrintFullTimeStamp(train2_earliest_leaving_time_stamp, test_buf); PrintFullTimeStamp(train2_earliest_leaving_time_stamp, test_buf);
LOG->debug("train2_earliest_leaving_time_stamp: {}", test_buf.str()); LOG->debug("train2_earliest_leaving_time_stamp: {}", test_buf.str());
int cur_train2_leaving_time_stamp = train2_earliest_leaving_time_stamp; int cur_train2_leaving_time_stamp = train2_earliest_leaving_time_stamp;
int tran2_day_delta; int tran2_day_delta = 0;
if (cur_train2_leaving_time_stamp < cur_train1_arriving_time_stamp) { if (cur_train2_leaving_time_stamp < cur_train1_arriving_time_stamp) {
tran2_day_delta = (cur_train1_arriving_time_stamp - cur_train2_leaving_time_stamp + 1440 - 1) / 1440; tran2_day_delta = (cur_train1_arriving_time_stamp - cur_train2_leaving_time_stamp + 1440 - 1) / 1440;
cur_train2_leaving_time_stamp += tran2_day_delta * 1440; cur_train2_leaving_time_stamp += tran2_day_delta * 1440;
@ -290,6 +290,7 @@ void TicketSystemEngine::CheckTransfer(hash_t train1_ID_hash, hash_t train2_ID_h
cur_train2_leaving_time_stamp + train2_arrive_time_offeset[dest_station_offset] - train2_leave_time_offset[i]; cur_train2_leaving_time_stamp + train2_arrive_time_offeset[dest_station_offset] - train2_leave_time_offset[i];
if (!has_solution) { if (!has_solution) {
// just copy the first solution // just copy the first solution
LOG->debug("generating the first solution");
has_solution = true; has_solution = true;
res_train1_id = train1_price_data.trainID; res_train1_id = train1_price_data.trainID;
res_train2_id = train2_price_data.trainID; res_train2_id = train2_price_data.trainID;
@ -300,14 +301,20 @@ void TicketSystemEngine::CheckTransfer(hash_t train1_ID_hash, hash_t train2_ID_h
res_train1_price = train1_price_sum[transfer_station_offset] - train1_price_sum[start_station_offset]; res_train1_price = train1_price_sum[transfer_station_offset] - train1_price_sum[start_station_offset];
res_train2_price = train2_price_sum[dest_station_offset] - train2_price_sum[i]; res_train2_price = train2_price_sum[dest_station_offset] - train2_price_sum[i];
StationNameData station_name_data; StationNameData station_name_data;
LOG->debug("trying to get station name data");
station_name_data_storage.Get(train1_ID_hash, station_name_data); station_name_data_storage.Get(train1_ID_hash, station_name_data);
LOG->debug("successfully got station name data");
auto &str = station_name_data.name[transfer_station_offset]; auto &str = station_name_data.name[transfer_station_offset];
res_transfer_station_name = ""; res_transfer_station_name = "";
for (int i = 0; i < 40 && str[i] != '\0'; i++) res_transfer_station_name.push_back(str[i]); for (int i = 0; i < 40 && str[i] != '\0'; i++) res_transfer_station_name.push_back(str[i]);
SeatsData train1_seats_data, train2_seats_data; SeatsData train1_seats_data, train2_seats_data;
LOG->debug("trying to get train1 seats data");
seats_data_storage.Get({train1_ID_hash, train1_actual_start_date - train1_core_data.saleDate_beg}, seats_data_storage.Get({train1_ID_hash, train1_actual_start_date - train1_core_data.saleDate_beg},
train1_seats_data); train1_seats_data);
LOG->debug("successfully got train1 seats data");
LOG->debug("trying to get train2 seats data");
seats_data_storage.Get({train2_ID_hash, tran2_day_delta}, train2_seats_data); seats_data_storage.Get({train2_ID_hash, tran2_day_delta}, train2_seats_data);
LOG->debug("successfully got train2 seats data");
res_train1_seat = train1_seats_data.seat[start_station_offset]; res_train1_seat = train1_seats_data.seat[start_station_offset];
for (int j = start_station_offset + 1; j < transfer_station_offset; j++) { for (int j = start_station_offset + 1; j < transfer_station_offset; j++) {
res_train1_seat = std::min(res_train1_seat, (int)train1_seats_data.seat[j]); res_train1_seat = std::min(res_train1_seat, (int)train1_seats_data.seat[j]);
@ -317,6 +324,7 @@ void TicketSystemEngine::CheckTransfer(hash_t train1_ID_hash, hash_t train2_ID_h
res_train2_seat = std::min(res_train2_seat, (int)train2_seats_data.seat[j]); res_train2_seat = std::min(res_train2_seat, (int)train2_seats_data.seat[j]);
} }
} else { } else {
LOG->debug("trying to generate a new solution");
int cur_total_time = cur_train2_arriving_time_stamp - cur_train1_leaving_time_stamp; int cur_total_time = cur_train2_arriving_time_stamp - cur_train1_leaving_time_stamp;
int existsing_total_time = res_train2_arriving_time_stamp - res_train1_leaving_time_stamp; int existsing_total_time = res_train2_arriving_time_stamp - res_train1_leaving_time_stamp;
int cur_total_price = train1_price_sum[transfer_station_offset] - train1_price_sum[start_station_offset] + int cur_total_price = train1_price_sum[transfer_station_offset] - train1_price_sum[start_station_offset] +
@ -350,14 +358,20 @@ void TicketSystemEngine::CheckTransfer(hash_t train1_ID_hash, hash_t train2_ID_h
res_train1_price = train1_price_sum[transfer_station_offset] - train1_price_sum[start_station_offset]; res_train1_price = train1_price_sum[transfer_station_offset] - train1_price_sum[start_station_offset];
res_train2_price = train2_price_sum[dest_station_offset] - train2_price_sum[i]; res_train2_price = train2_price_sum[dest_station_offset] - train2_price_sum[i];
StationNameData station_name_data; StationNameData station_name_data;
LOG->debug("trying to get station name data");
station_name_data_storage.Get(train1_ID_hash, station_name_data); station_name_data_storage.Get(train1_ID_hash, station_name_data);
LOG->debug("successfully got station name data");
auto &str = station_name_data.name[transfer_station_offset]; auto &str = station_name_data.name[transfer_station_offset];
res_transfer_station_name = ""; res_transfer_station_name = "";
for (int i = 0; i < 40 && str[i] != '\0'; i++) res_transfer_station_name.push_back(str[i]); for (int i = 0; i < 40 && str[i] != '\0'; i++) res_transfer_station_name.push_back(str[i]);
SeatsData train1_seats_data, train2_seats_data; SeatsData train1_seats_data, train2_seats_data;
LOG->debug("trying to get train1 seats data");
seats_data_storage.Get({train1_ID_hash, train1_actual_start_date - train1_core_data.saleDate_beg}, seats_data_storage.Get({train1_ID_hash, train1_actual_start_date - train1_core_data.saleDate_beg},
train1_seats_data); train1_seats_data);
LOG->debug("successfully got train1 seats data");
LOG->debug("trying to get train2 seats data");
seats_data_storage.Get({train2_ID_hash, tran2_day_delta}, train2_seats_data); seats_data_storage.Get({train2_ID_hash, tran2_day_delta}, train2_seats_data);
LOG->debug("successfully got train2 seats data");
res_train1_seat = train1_seats_data.seat[start_station_offset]; res_train1_seat = train1_seats_data.seat[start_station_offset];
for (int j = start_station_offset + 1; j < transfer_station_offset; j++) { for (int j = start_station_offset + 1; j < transfer_station_offset; j++) {
res_train1_seat = std::min(res_train1_seat, (int)train1_seats_data.seat[j]); res_train1_seat = std::min(res_train1_seat, (int)train1_seats_data.seat[j]);