Skip to content
Snippets Groups Projects
Commit 0a7afb0b authored by Recolic Keghart's avatar Recolic Keghart
Browse files

updated

parent e0ac51b3
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
std::pair<bool, value_type> operator[](const key_type &k) const { std::pair<bool, value_type> operator[](const key_type &k) const {
auto target_rank = find_rank_for_hash(find_hash_for_ele(k)); auto target_rank = find_rank_for_hash(find_hash_for_ele(k));
if(my_rank == target_rank) { if(my_rank == target_rank) {
return std::make_pair(true, do_find(k)); return std::make_pair(true, *do_find(k));
} }
else { else {
auto res = upcxx::rpc(target_rank, std::bind(&this_type::do_rpc_find, this, k)).wait(); auto res = upcxx::rpc(target_rank, std::bind(&this_type::do_rpc_find, this, k)).wait();
...@@ -65,6 +65,21 @@ public: ...@@ -65,6 +65,21 @@ public:
} }
} }
bool push_if_is_mine(const key_type &k, const value_type &v) {
auto target_rank = find_rank_for_hash(find_hash_for_ele(k));
if(my_rank == target_rank) {
do_insert(k, v);
}
return my_rank == target_rank;
}
std::pair<bool, value_type> find_if_is_mine(const key_type &k) {
auto target_rank = find_rank_for_hash(find_hash_for_ele(k));
if(my_rank == target_rank)
return std::make_pair(true, *do_find(k));
else
return std::make_pair(false, value_type{});
}
private: private:
bool do_rpc_insert(key_type k, value_type v) { bool do_rpc_insert(key_type k, value_type v) {
...@@ -79,10 +94,11 @@ private: ...@@ -79,10 +94,11 @@ private:
} }
auto do_rpc_find(key_type k) const { auto do_rpc_find(key_type k) const {
try { try {
return rpc_find_result{true, true, do_find(k)}; const auto *res = do_find(k, true);
} if(res)
catch(std::out_of_range &o) { return rpc_find_result{true, true, *res};
return rpc_find_result{false, true, value_type{}}; else
return rpc_find_result{false, true, value_type{}};
} }
catch(std::exception &e) { catch(std::exception &e) {
rlib::println(std::cerr, "Error: exception while executing rpc find: ", e.what()); rlib::println(std::cerr, "Error: exception while executing rpc find: ", e.what());
...@@ -111,25 +127,29 @@ private: ...@@ -111,25 +127,29 @@ private:
} }
} }
const value_type &do_find(const key_type &k) const { const value_type *do_find(const key_type &k, bool no_throw = false) const {
const auto &target_ls = find_slot(k); const auto &target_ls = find_slot(k);
{ {
for(const auto &ele : target_ls) { for(const auto &ele : target_ls) {
if(equal_engine_type{}(ele.first, k)) if(equal_engine_type{}(ele.first, k))
return ele.second; return &ele.second;
} }
} }
throw std::out_of_range("Element not found."); if(not no_throw)
throw std::out_of_range("Element not found.");
return nullptr;
} }
value_type &do_find(const key_type &k) { value_type *do_find(const key_type &k, bool no_throw = false) {
auto &target_ls = find_slot(k); auto &target_ls = find_slot(k);
{ {
for(auto &ele : target_ls) { for(auto &ele : target_ls) {
if(equal_engine_type{}(ele.first, k)) if(equal_engine_type{}(ele.first, k))
return ele.second; return &ele.second;
} }
} }
throw std::out_of_range("Element not found."); if(not no_throw)
throw std::out_of_range("Element not found.");
return nullptr;
} }
const auto &find_slot(const key_type &k) const { const auto &find_slot(const key_type &k) const {
......
...@@ -23,8 +23,7 @@ struct HashMap { ...@@ -23,8 +23,7 @@ struct HashMap {
} }
bool insert(const kmer_pair &kmer) { bool insert(const kmer_pair &kmer) {
real_db.push(kmer.kmer, kmer); return real_db.push_if_is_mine(kmer.kmer, kmer);
return true;
} }
bool find(const pkmer_t &key_kmer, kmer_pair &val_kmer) { bool find(const pkmer_t &key_kmer, kmer_pair &val_kmer) {
auto res = real_db[key_kmer]; auto res = real_db[key_kmer];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment