Skip to content

Commit

Permalink
Estimate size of index better
Browse files Browse the repository at this point in the history
  • Loading branch information
xchang1 committed Dec 3, 2024
1 parent f626d12 commit 982848f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions bdsg/include/bdsg/snarl_distance_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ class SnarlDistanceIndex : public SnarlDecomposition, public TriviallySerializab
SimpleSnarlRecord (net_handle_t net, const bdsg::yomo::UniqueMappedPointer<bdsg::MappedIntVector>* tree_records);

//How big is the entire snarl record?
const static size_t record_size(size_t node_count) {return SIMPLE_SNARL_RECORD_SIZE + (node_count*2);}
const static size_t record_size(size_t node_count, bool include_distances) {return SIMPLE_SNARL_RECORD_SIZE + (node_count*2);}
size_t record_size() ;

//Get and set the distances between two node sides in the graph
Expand Down Expand Up @@ -1529,7 +1529,7 @@ class SnarlDistanceIndex : public SnarlDecomposition, public TriviallySerializab
//What is the index of this record in root_snarl_components
size_t root_snarl_index = std::numeric_limits<size_t>::max();
bool loopable = true; //If this is a looping snarl, this is false if the last snarl is not start-end connected
size_t get_max_record_length() const;
size_t get_max_record_length(bool include_distances) const;
};
struct TemporarySnarlRecord : TemporaryRecord{
handlegraph::nid_t start_node_id;
Expand Down Expand Up @@ -1557,6 +1557,7 @@ class SnarlDistanceIndex : public SnarlDecomposition, public TriviallySerializab
bool is_simple;
bool is_tip = false;
bool is_root_snarl = false;
bool include_distances = true;

size_t get_max_record_length() const ;
};
Expand Down
12 changes: 7 additions & 5 deletions bdsg/src/snarl_distance_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ string SnarlDistanceIndex::TemporaryDistanceIndex::structure_start_end_as_string
}
}
//The max record length of this chain
size_t SnarlDistanceIndex::TemporaryDistanceIndex::TemporaryChainRecord::get_max_record_length() const {
size_t SnarlDistanceIndex::TemporaryDistanceIndex::TemporaryChainRecord::get_max_record_length(bool include_distances) const {
if (is_trivial) {
return NODE_RECORD_SIZE;
} else {
Expand Down Expand Up @@ -82,7 +82,9 @@ size_t SnarlDistanceIndex::TemporaryDistanceIndex::TemporaryChainRecord::get_max
//The size of the chain record + the size of all the trivial snarls in the chain
// + the size of the nodes in the trivial snarls + the sizes of all
// the snarls in the chain
return CHAIN_RECORD_SIZE + (DISTANCED_TRIVIAL_SNARL_RECORD_SIZE*trivial_snarl_count) + (total_node_count * 2) + ((trivial_snarl_count + nontrivial_snarl_count) * 2) - 1;
return CHAIN_RECORD_SIZE + ((include_distances ? DISTANCED_TRIVIAL_SNARL_RECORD_SIZE : DISTANCELESS_TRIVIAL_SNARL_RECORD_SIZE) *trivial_snarl_count)
+ (total_node_count * (include_distances ? 2 : 1))
+ ((trivial_snarl_count + nontrivial_snarl_count) * 2) - 1;
}
}
//The max record length of the root
Expand All @@ -95,12 +97,12 @@ size_t SnarlDistanceIndex::TemporaryDistanceIndex::TemporarySnarlRecord::get_max
if (is_trivial) {
return 0;
} else if (is_simple) {
return SimpleSnarlRecord::record_size(node_count);
return SimpleSnarlRecord::record_size(node_count, include_distances);
} else {
if (parent.first == TEMP_ROOT) {
return SnarlRecord::record_size(DISTANCED_ROOT_SNARL, node_count) + node_count;
return SnarlRecord::record_size(include_distances ? DISTANCED_ROOT_SNARL : ROOT_SNARL, node_count) + node_count;
} else {
return SnarlRecord::record_size(DISTANCED_SNARL, node_count) + node_count;
return SnarlRecord::record_size(include_distances ? DISTANCED_SNARL : SNARL, node_count) + node_count;
}
}
}
Expand Down

0 comments on commit 982848f

Please sign in to comment.