Skip to content

Commit

Permalink
#2342: reduce duplication and improve bool naming
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly committed Sep 6, 2024
1 parent 8138dec commit c36b530
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/vt/vrt/collection/balance/lb_data_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@
namespace vt { namespace vrt { namespace collection { namespace balance {

void get_object_from_json_field_(
const nlohmann::json& field, nlohmann::json& object, bool& bitpacked) {
const nlohmann::json& field, nlohmann::json& object, bool& is_bitpacked) {
if (field.find("id") != field.end()) {
object = field["id"];
bitpacked = true;
is_bitpacked = true;
} else {
object = field["seq_id"];
bitpacked = false;
is_bitpacked = false;
}
}

ElementIDStruct get_elm_from_object_info_(
const nlohmann::json& object, bool bitpacked, bool migratable,
const nlohmann::json& object, bool is_bitpacked, bool migratable,
const nlohmann::json& home, const nlohmann::json& node) {
using Field = uint64_t;

Field object_id;
if (bitpacked) {
if (is_bitpacked) {
object_id = BitPackerType::getField<
vt::elm::eElmIDProxyBitsNonObjGroup::ID, vt::elm::elm_id_num_bits, Field>(
static_cast<Field>(object));
Expand All @@ -81,11 +81,11 @@ ElementIDStruct get_elm_from_object_info_(
ElementIDStruct get_elm_from_comm_object_(const nlohmann::json& field, bool collection) {
// Get the object's id and determine if it is bit-encoded
nlohmann::json object;
bool bitpacked_id;
get_object_from_json_field_(field, object, bitpacked_id);
bool is_bitpacked;
get_object_from_json_field_(field, object, is_bitpacked);
vtAssertExpr(object.is_number());

// Somehow will this information
// TODO: need to get this information (if it's relevant)
int home = 0;
int node = 0;
bool migratable = false;
Expand All @@ -94,7 +94,7 @@ ElementIDStruct get_elm_from_comm_object_(const nlohmann::json& field, bool coll
ElementIDStruct elm;
if (collection) {
elm =
get_elm_from_object_info_(object, bitpacked_id, migratable, home, node);
get_elm_from_object_info_(object, is_bitpacked, migratable, home, node);
} else {
elm = ElementIDStruct{object, theContext()->getNode()};
}
Expand Down Expand Up @@ -357,13 +357,8 @@ LBDataHolder::LBDataHolder(nlohmann::json const& j)

if (etype == "object") {
nlohmann::json object;
bool bitpacked_id = false;
if (task["entity"].find("id") != task["entity"].end()) {
object = task["entity"]["id"];
bitpacked_id = true;
} else {
object = task["entity"]["seq_id"];
}
bool is_bitpacked;
get_object_from_json_field_(task["entity"], object, is_bitpacked);
vtAssertExpr(object.is_number());

ElementIDStruct elm;
Expand All @@ -372,7 +367,7 @@ LBDataHolder::LBDataHolder(nlohmann::json const& j)
task["entity"].find("collection_id") != task["entity"].end() and
task["entity"].find("index") != task["entity"].end()) {
elm = get_elm_from_object_info_(
object, bitpacked_id, migratable, home, node);
object, is_bitpacked, migratable, home, node);
auto cid = task["entity"]["collection_id"];
auto idx = task["entity"]["index"];
if (cid.is_number() && idx.is_array()) {
Expand Down

0 comments on commit c36b530

Please sign in to comment.