Skip to content

Commit

Permalink
Merge int vectors in temporary chain index
Browse files Browse the repository at this point in the history
  • Loading branch information
xchang1 committed Dec 6, 2024
1 parent 6cff676 commit 84a80f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
15 changes: 9 additions & 6 deletions bdsg/include/bdsg/snarl_distance_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,13 +1527,16 @@ class SnarlDistanceIndex : public SnarlDecomposition, public TriviallySerializab
bool loopable = true; //If this is a looping snarl, this is false if the last snarl is not start-end connected

vector<pair<temp_record_t, size_t>> children; //All children, both nodes and snarls, in order

//Distances for the chain, one entry per node
//TODO This would probably be more efficient as a vector of a struct of five ints
vector<size_t> prefix_sum;
vector<size_t> max_prefix_sum;
vector<size_t> forward_loops;
vector<size_t> backward_loops;
vector<size_t> chain_components;//Which component does each node belong to, usually all 0s
struct chain_distances_t {
size_t prefix_sum;
size_t max_prefix_sum;
size_t forward_loop;
size_t backward_loop;
size_t chain_component;//Which component does each node belong to, usually all 0s
};
vector<chain_distances_t> per_node_distances;

size_t get_max_record_length(bool include_distances) const;
};
Expand Down
14 changes: 7 additions & 7 deletions bdsg/src/snarl_distance_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6164,14 +6164,14 @@ void SnarlDistanceIndex::get_snarl_tree_records(const vector<const TemporaryDist

ChainRecordWriter chain_record_constructor;

if (temp_chain_record.chain_components.back() == 0 || ignore_distances) {
if (temp_chain_record.per_node_distances.back().chain_component == 0 || ignore_distances) {
record_t record_type = ignore_distances ? CHAIN : DISTANCED_CHAIN;
chain_record_constructor = ChainRecordWriter(snarl_tree_records->size(), record_type,
temp_chain_record.prefix_sum.size(), &snarl_tree_records);
temp_chain_record.per_node_distances.size(), &snarl_tree_records);
chain_record_constructor.set_start_end_connected();
} else {
chain_record_constructor = ChainRecordWriter(snarl_tree_records->size(), MULTICOMPONENT_CHAIN,
temp_chain_record.prefix_sum.size(), &snarl_tree_records);
temp_chain_record.per_node_distances.size(), &snarl_tree_records);
}
chain_record_constructor.set_parent_record_offset(
record_to_offset[make_pair(temp_index_i, temp_chain_record.parent)]);
Expand Down Expand Up @@ -6231,15 +6231,15 @@ void SnarlDistanceIndex::get_snarl_tree_records(const vector<const TemporaryDist
//Make a new node record
size_t new_offset = chain_record_constructor.add_node(
temp_node_record.node_id, temp_node_record.node_length, temp_node_record.reversed_in_parent,
temp_chain_record.prefix_sum[chain_node_i], temp_chain_record.forward_loops[chain_node_i],
temp_chain_record.backward_loops[chain_node_i], temp_chain_record.chain_components[chain_node_i],
temp_chain_record.max_prefix_sum[chain_node_i],
temp_chain_record.per_node_distances[chain_node_i].prefix_sum, temp_chain_record.per_node_distances[chain_node_i].forward_loop,
temp_chain_record.per_node_distances[chain_node_i].backward_loop, temp_chain_record.per_node_distances[chain_node_i].chain_component,
temp_chain_record.per_node_distances[chain_node_i].max_prefix_sum,
last_child_offset.first, last_child_was_nontrivial_snarl,
!ignore_distances);

//Remember this node as the last thing in the chain
last_child_offset = make_pair(new_offset, false);
if (temp_chain_record.forward_loops[chain_node_i] == 0) {
if (temp_chain_record.per_node_distances[chain_node_i].forward_loop == 0) {
last_child_was_nontrivial_snarl = true;
} else {
last_child_was_nontrivial_snarl = false;
Expand Down

0 comments on commit 84a80f4

Please sign in to comment.