From b954f5b493c0ced69a18d75c6df4a3d84ccbef9f Mon Sep 17 00:00:00 2001 From: "ulrich.bauer@gmail.com" Date: Tue, 3 Jun 2014 13:30:25 +0000 Subject: faster column addition for vector_vector git-svn-id: https://phat.googlecode.com/svn/trunk@180 8e3bb3c2-eed4-f18f-5264-0b6c94e6926d --- include/phat/representations/vector_vector.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/phat/representations/vector_vector.h b/include/phat/representations/vector_vector.h index da8ec5a..4aee533 100644 --- a/include/phat/representations/vector_vector.h +++ b/include/phat/representations/vector_vector.h @@ -83,11 +83,18 @@ namespace phat { column& source_col = matrix[ source ]; column& target_col = matrix[ target ]; column& temp_col = temp_column_buffer(); - temp_col.clear(); - std::set_symmetric_difference( target_col.begin(), target_col.end(), + + + size_t new_size = source_col.size() + target_col.size(); + + if (new_size > temp_col.size()) temp_col.resize(new_size); + + std::vector::iterator col_end = std::set_symmetric_difference( target_col.begin(), target_col.end(), source_col.begin(), source_col.end(), - std::back_inserter( temp_col ) ); - //target_col.swap( temp_col ); + temp_col.begin() ); + temp_col.erase(col_end, temp_col.end()); + + target_col = temp_col; temp_col.clear(); } -- cgit v1.2.3