replaced STL
This commit is contained in:
@ -18,7 +18,7 @@ class TicketSystemEngine {
|
|||||||
#endif
|
#endif
|
||||||
bool its_time_to_exit = false;
|
bool its_time_to_exit = false;
|
||||||
std::string data_directory;
|
std::string data_directory;
|
||||||
std::map<hash_t, uint8_t> online_users;
|
sjtu::map<hash_t, uint8_t> online_users;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief user data system
|
* @brief user data system
|
||||||
|
@ -100,7 +100,7 @@ class StopRegister : public DataDriverBase {
|
|||||||
*reinterpret_cast<default_numeric_index_t *>(&record_leave));
|
*reinterpret_cast<default_numeric_index_t *>(&record_leave));
|
||||||
}
|
}
|
||||||
inline void QueryDirectTrains(uint32_t date, hash_t from_station_ID, hash_t to_station_ID,
|
inline void QueryDirectTrains(uint32_t date, hash_t from_station_ID, hash_t to_station_ID,
|
||||||
std::vector<StopRegister::DirectTrainInfo> &res) {
|
sjtu::vector<StopRegister::DirectTrainInfo> &res) {
|
||||||
const static int June_1st_2024 = 152;
|
const static int June_1st_2024 = 152;
|
||||||
auto it_from = bpt_indexer->lower_bound_const({from_station_ID, 0});
|
auto it_from = bpt_indexer->lower_bound_const({from_station_ID, 0});
|
||||||
auto it_to = bpt_indexer->lower_bound_const({to_station_ID, 0});
|
auto it_to = bpt_indexer->lower_bound_const({to_station_ID, 0});
|
||||||
@ -202,7 +202,7 @@ class StopRegister : public DataDriverBase {
|
|||||||
entry.to_stop_id = key_to.stop_id;
|
entry.to_stop_id = key_to.stop_id;
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
inline void FetchTrainLeavingFrom(uint32_t date, hash_t from_station_ID, std::vector<hash_t> &res) {
|
inline void FetchTrainLeavingFrom(uint32_t date, hash_t from_station_ID, sjtu::vector<hash_t> &res) {
|
||||||
const static int June_1st_2024 = 152;
|
const static int June_1st_2024 = 152;
|
||||||
res.clear();
|
res.clear();
|
||||||
auto it_from = bpt_indexer->lower_bound_const({from_station_ID, 0});
|
auto it_from = bpt_indexer->lower_bound_const({from_station_ID, 0});
|
||||||
@ -232,7 +232,7 @@ class StopRegister : public DataDriverBase {
|
|||||||
++it_from;
|
++it_from;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inline void FetchTrainArriavingAt(uint32_t date, hash_t to_station_ID, std::vector<hash_t> &res) {
|
inline void FetchTrainArriavingAt(uint32_t date, hash_t to_station_ID, sjtu::vector<hash_t> &res) {
|
||||||
res.clear();
|
res.clear();
|
||||||
auto it_to = bpt_indexer->lower_bound_const({to_station_ID, 0});
|
auto it_to = bpt_indexer->lower_bound_const({to_station_ID, 0});
|
||||||
while (it_to != bpt_indexer->end_const()) {
|
while (it_to != bpt_indexer->end_const()) {
|
||||||
|
@ -203,7 +203,7 @@ class TransactionManager : public DataDriverBase {
|
|||||||
order_history_indexer->Put(order_history_index, data_id);
|
order_history_indexer->Put(order_history_index, data_id);
|
||||||
}
|
}
|
||||||
inline void FetchQueue(hash_t train_ID_hash, uint8_t running_date_offset,
|
inline void FetchQueue(hash_t train_ID_hash, uint8_t running_date_offset,
|
||||||
std::vector<std::pair<b_plus_tree_value_index_t, uint32_t>> &res) {
|
sjtu::vector<std::pair<b_plus_tree_value_index_t, uint32_t>> &res) {
|
||||||
// warning: the validity of train_ID_hash is not checked
|
// warning: the validity of train_ID_hash is not checked
|
||||||
queue_index_t queue_index_for_query;
|
queue_index_t queue_index_for_query;
|
||||||
queue_index_for_query.train_ID_hash = train_ID_hash;
|
queue_index_for_query.train_ID_hash = train_ID_hash;
|
||||||
@ -228,7 +228,7 @@ class TransactionManager : public DataDriverBase {
|
|||||||
queue_index_for_query.id = id;
|
queue_index_for_query.id = id;
|
||||||
queue_indexer->Remove(queue_index_for_query);
|
queue_indexer->Remove(queue_index_for_query);
|
||||||
}
|
}
|
||||||
inline void FetchFullUserOrderHistory(hash_t user_ID_hash, std::vector<b_plus_tree_value_index_t> &res) {
|
inline void FetchFullUserOrderHistory(hash_t user_ID_hash, sjtu::vector<b_plus_tree_value_index_t> &res) {
|
||||||
// warning: the validity of user_ID_hash is not checked
|
// warning: the validity of user_ID_hash is not checked
|
||||||
order_history_index_t order_history_index_for_query;
|
order_history_index_t order_history_index_for_query;
|
||||||
order_history_index_for_query.user_ID_hash = user_ID_hash;
|
order_history_index_for_query.user_ID_hash = user_ID_hash;
|
||||||
|
@ -50,10 +50,10 @@ std::string TicketSystemEngine::QueryTicket(const std::string &command) {
|
|||||||
LOG->debug("date {}={}-{}, from {}, to {}, order by {}", date, RetrieveReadableDate(date).first,
|
LOG->debug("date {}={}-{}, from {}, to {}, order by {}", date, RetrieveReadableDate(date).first,
|
||||||
RetrieveReadableDate(date).second, from, to, order_by);
|
RetrieveReadableDate(date).second, from, to, order_by);
|
||||||
hash_t from_hash = SplitMix64Hash(from), to_hash = SplitMix64Hash(to);
|
hash_t from_hash = SplitMix64Hash(from), to_hash = SplitMix64Hash(to);
|
||||||
std::vector<StopRegister::DirectTrainInfo> valid_trains;
|
sjtu::vector<StopRegister::DirectTrainInfo> valid_trains;
|
||||||
stop_register.QueryDirectTrains(date, from_hash, to_hash, valid_trains);
|
stop_register.QueryDirectTrains(date, from_hash, to_hash, valid_trains);
|
||||||
size_t len = valid_trains.size();
|
size_t len = valid_trains.size();
|
||||||
std::vector<std::pair<StopRegister::DirectTrainInfo, AdditionalTrainInfo>> valid_trains_full(len);
|
sjtu::vector<std::pair<StopRegister::DirectTrainInfo, AdditionalTrainInfo>> valid_trains_full(len);
|
||||||
LOG->debug("retrieving full data");
|
LOG->debug("retrieving full data");
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
valid_trains_full[i].first = valid_trains[i];
|
valid_trains_full[i].first = valid_trains[i];
|
||||||
@ -78,7 +78,7 @@ std::string TicketSystemEngine::QueryTicket(const std::string &command) {
|
|||||||
valid_trains_full[i].second.seats = seats;
|
valid_trains_full[i].second.seats = seats;
|
||||||
}
|
}
|
||||||
LOG->debug("successfully retrieved full data");
|
LOG->debug("successfully retrieved full data");
|
||||||
std::vector<int> valid_trains_full_index(len);
|
sjtu::vector<int> valid_trains_full_index(len);
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
valid_trains_full_index[i] = i;
|
valid_trains_full_index[i] = i;
|
||||||
}
|
}
|
||||||
@ -163,8 +163,8 @@ std::string TicketSystemEngine::QueryTransfer(const std::string &command) {
|
|||||||
LOG->debug("date {}={}-{}, from {}, to {}, order by {}", date, RetrieveReadableDate(date).first,
|
LOG->debug("date {}={}-{}, from {}, to {}, order by {}", date, RetrieveReadableDate(date).first,
|
||||||
RetrieveReadableDate(date).second, from, to, order_by);
|
RetrieveReadableDate(date).second, from, to, order_by);
|
||||||
bool has_solution = false;
|
bool has_solution = false;
|
||||||
std::vector<hash_t> trains_leaving_from_from;
|
sjtu::vector<hash_t> trains_leaving_from_from;
|
||||||
std::vector<hash_t> trains_arriving_at_dest;
|
sjtu::vector<hash_t> trains_arriving_at_dest;
|
||||||
hash_t from_station_hash = SplitMix64Hash(from), to_station_hash = SplitMix64Hash(to);
|
hash_t from_station_hash = SplitMix64Hash(from), to_station_hash = SplitMix64Hash(to);
|
||||||
stop_register.FetchTrainLeavingFrom(date, from_station_hash, trains_leaving_from_from);
|
stop_register.FetchTrainLeavingFrom(date, from_station_hash, trains_leaving_from_from);
|
||||||
stop_register.FetchTrainArriavingAt(date, to_station_hash, trains_arriving_at_dest);
|
stop_register.FetchTrainArriavingAt(date, to_station_hash, trains_arriving_at_dest);
|
||||||
@ -212,7 +212,7 @@ void TicketSystemEngine::CheckTransfer(hash_t train1_ID_hash, hash_t train2_ID_h
|
|||||||
int &res_train2_seat, std::string &res_transfer_station_name,
|
int &res_train2_seat, std::string &res_transfer_station_name,
|
||||||
bool sort_by_time) {
|
bool sort_by_time) {
|
||||||
if (train1_ID_hash == train2_ID_hash) return;
|
if (train1_ID_hash == train2_ID_hash) return;
|
||||||
std::map<hash_t, int> transfer_mp;
|
sjtu::map<hash_t, int> transfer_mp;
|
||||||
hash_t from_station_hash = SplitMix64Hash(from_station), to_station_hash = SplitMix64Hash(to_station);
|
hash_t from_station_hash = SplitMix64Hash(from_station), to_station_hash = SplitMix64Hash(to_station);
|
||||||
CoreTrainData train1_core_data, train2_core_data;
|
CoreTrainData train1_core_data, train2_core_data;
|
||||||
core_train_data_storage.Get(train1_ID_hash, train1_core_data);
|
core_train_data_storage.Get(train1_ID_hash, train1_core_data);
|
||||||
@ -513,7 +513,7 @@ std::string TicketSystemEngine::QueryOrder(const std::string &command) {
|
|||||||
response_stream << "[" << command_id << "] -1";
|
response_stream << "[" << command_id << "] -1";
|
||||||
return response_stream.str();
|
return response_stream.str();
|
||||||
}
|
}
|
||||||
std::vector<b_plus_tree_value_index_t> his_idxs;
|
sjtu::vector<b_plus_tree_value_index_t> his_idxs;
|
||||||
transaction_manager.FetchFullUserOrderHistory(user_ID_hash, his_idxs);
|
transaction_manager.FetchFullUserOrderHistory(user_ID_hash, his_idxs);
|
||||||
size_t len = his_idxs.size();
|
size_t len = his_idxs.size();
|
||||||
TransactionData txn_data;
|
TransactionData txn_data;
|
||||||
@ -602,7 +602,7 @@ std::string TicketSystemEngine::RefundTicket(const std::string &command) {
|
|||||||
seats_data.seat[i] += txn_data.num;
|
seats_data.seat[i] += txn_data.num;
|
||||||
}
|
}
|
||||||
seats_data_storage.Put({train_ID_hash, txn_data.running_date_offset}, seats_data);
|
seats_data_storage.Put({train_ID_hash, txn_data.running_date_offset}, seats_data);
|
||||||
std::vector<std::pair<b_plus_tree_value_index_t, uint32_t>> queue_idxs;
|
sjtu::vector<std::pair<b_plus_tree_value_index_t, uint32_t>> queue_idxs;
|
||||||
transaction_manager.FetchQueue(train_ID_hash, txn_data.running_date_offset, queue_idxs);
|
transaction_manager.FetchQueue(train_ID_hash, txn_data.running_date_offset, queue_idxs);
|
||||||
size_t len = queue_idxs.size();
|
size_t len = queue_idxs.size();
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
|
@ -126,6 +126,7 @@ class vector {
|
|||||||
*/
|
*/
|
||||||
bool operator!=(const iterator &rhs) const { return raw_pointer != rhs.raw_pointer; }
|
bool operator!=(const iterator &rhs) const { return raw_pointer != rhs.raw_pointer; }
|
||||||
bool operator!=(const const_iterator &rhs) const { return raw_pointer != rhs.raw_pointer; }
|
bool operator!=(const const_iterator &rhs) const { return raw_pointer != rhs.raw_pointer; }
|
||||||
|
bool operator<(const iterator &rhs) const { return raw_pointer < rhs.raw_pointer; }
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
@ -231,6 +232,15 @@ class vector {
|
|||||||
allocated_length = 1;
|
allocated_length = 1;
|
||||||
current_length = 0;
|
current_length = 0;
|
||||||
}
|
}
|
||||||
|
vector(size_t len) {
|
||||||
|
raw_beg = alloc.allocate(len * 2);
|
||||||
|
raw_end = raw_beg + len;
|
||||||
|
allocated_length = len * 2;
|
||||||
|
current_length = len;
|
||||||
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
std::allocator_traits<decltype(alloc)>::construct(alloc, raw_beg + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
vector(const vector &other) {
|
vector(const vector &other) {
|
||||||
raw_beg = alloc.allocate(other.allocated_length);
|
raw_beg = alloc.allocate(other.allocated_length);
|
||||||
raw_end = raw_beg + other.current_length;
|
raw_end = raw_beg + other.current_length;
|
||||||
@ -536,6 +546,34 @@ class vector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
T *data() { return raw_beg; }
|
T *data() { return raw_beg; }
|
||||||
|
|
||||||
|
void resize(size_t len) {
|
||||||
|
if (len < current_length) {
|
||||||
|
for (size_t i = len; i < current_length; ++i) {
|
||||||
|
std::allocator_traits<decltype(alloc)>::destroy(alloc, raw_beg + i);
|
||||||
|
}
|
||||||
|
raw_end = raw_beg + len;
|
||||||
|
current_length = len;
|
||||||
|
} else if (len > current_length) {
|
||||||
|
if (len > allocated_length) {
|
||||||
|
size_t new_allocated_length = len * 2;
|
||||||
|
T *new_raw_beg = alloc.allocate(new_allocated_length);
|
||||||
|
for (size_t i = 0; i < current_length; ++i) {
|
||||||
|
std::allocator_traits<decltype(alloc)>::construct(alloc, new_raw_beg + i, std::move(raw_beg[i]));
|
||||||
|
std::allocator_traits<decltype(alloc)>::destroy(alloc, raw_beg + i);
|
||||||
|
}
|
||||||
|
alloc.deallocate(raw_beg, allocated_length);
|
||||||
|
raw_beg = new_raw_beg;
|
||||||
|
raw_end = raw_beg + current_length;
|
||||||
|
allocated_length = new_allocated_length;
|
||||||
|
}
|
||||||
|
for (size_t i = current_length; i < len; ++i) {
|
||||||
|
std::allocator_traits<decltype(alloc)>::construct(alloc, raw_beg + i);
|
||||||
|
}
|
||||||
|
raw_end = raw_beg + len;
|
||||||
|
current_length = len;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::allocator<T> vector<T>::alloc;
|
std::allocator<T> vector<T>::alloc;
|
||||||
|
Reference in New Issue
Block a user