[complement-svn] SF.net SVN: complement: [1579] trunk/complement/explore/test/virtual_time
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-06-01 16:58:48
|
Revision: 1579 http://svn.sourceforge.net/complement/?rev=1579&view=rev Author: complement Date: 2007-06-01 09:58:36 -0700 (Fri, 01 Jun 2007) Log Message: ----------- dev Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-31 18:37:14 UTC (rev 1578) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-06-01 16:58:36 UTC (rev 1579) @@ -207,143 +207,44 @@ vtime_type operator +( const vtime_type& l, const vtime_type& r ) { - if ( r.empty() ) { - return l; - } + vtime_type tmp( l.begin(), l.end() ); - if ( l.empty() ) { - return r; + for ( i = r.begin(); i != r.end(); ++i ) { + tmp[i->first] += i->second; } - vtime_type vt; - vtime_type::const_iterator i = l.begin(); - vtime_type::const_iterator j = r.begin(); - - while ( i != l.end() && j != r.end() ) { - while ( i != l.end() && i->first < j->first ) { - vt.push_back( make_pair( i->first, i->second ) ); - ++i; - } - - while ( i != l.end() && j != r.end() && i->first == j->first ) { - vt.push_back( make_pair( i->first, i->second + j->second ) ); - ++i; - ++j; - } - if ( i != l.end() ) { - while ( j != r.end() && j->first < i->first ) { - vt.push_back( make_pair( j->first, j->second ) ); - ++j; - } - } - } - - while ( i != l.end() ) { - vt.push_back( make_pair( i->first, i->second ) ); - ++i; - } - while ( j != r.end() ) { - vt.push_back( make_pair( j->first, j->second ) ); - ++j; - } - - return vt; + return tmp; } vtime_type& operator +=( vtime_type& l, const vtime_type& r ) { - if ( r.empty() ) { - return l; + for ( i = r.begin(); i != r.end(); ++i ) { + l[i->first] += i->second; } - if ( l.empty() ) { - l = r; - return l; - } - - vtime_type::iterator i = l.begin(); - vtime_type::const_iterator j = r.begin(); - - while ( i != l.end() && j != r.end() ) { - while ( i != l.end() && i->first < j->first ) { - ++i; - } - - while ( i != l.end() && j != r.end() && i->first == j->first ) { - i->second += j->second; - ++i; - ++j; - } - - while ( i != l.end() && j != r.end() && j->first < i->first ) { - l.insert( i, make_pair( j->first, j->second ) ); - ++i; - ++j; - } - } - - while ( j != r.end() ) { - l.push_back( make_pair( j->first, j->second ) ); - ++j; - } - return l; } // template <> vtime_type max( const vtime_type& l, const vtime_type& r ) { - if ( l.empty() ) { - return r; - } + vtime_type tmp( l.begin(), l.end() ); - if ( r.empty() ) { - return l; - } - - // here l and r non-empty - - vtime_type vt; - vtime_type::const_iterator i = l.begin(); - vtime_type::const_iterator j = r.begin(); - - while ( i != l.end() && j != r.end() ) { - while ( i != l.end() && i->first < j->first ) { - vt.push_back( make_pair( i->first, i->second ) ); - ++i; + for ( i = r.begin(); i != r.end(); ++i ) { + pair<vtime_type::iterator,bool> p = tmp.insert(i->first); + if ( p->second == false ) { + *p->first = i->second; + } else { + *p->first = max( *p->first->second, i->second ); } - - while ( i != l.end() && j != r.end() && i->first == j->first ) { - vt.push_back( make_pair( i->first, std::max( i->second, j->second ) ) ); - ++i; - ++j; - } } - while ( i != l.end() ) { - vt.push_back( make_pair( i->first, i->second ) ); - ++i; - } - while ( j != r.end() ) { - vt.push_back( make_pair( j->first, j->second ) ); - ++j; - } - - return vt; + return tmp; } vtime& vtime::operator +=( const vtime_proc_type& t ) { - vtime_type::iterator i = vt.begin(); + vt[t.first] += t.second; - for ( ; i != vt.end(); ++i ) { - if ( i->first > t.first ) { - break; - } else if ( i->first == t.first ) { - i->second += t.second; - return *this; - } - } - vt.insert( i, t ); return *this; } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-31 18:37:14 UTC (rev 1578) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-06-01 16:58:36 UTC (rev 1579) @@ -23,45 +23,6 @@ typedef uint32_t group_type; typedef std::hash_map<oid_type, vtime_unit_type> vtime_type; -template <class _InputIter1, class _InputIter2, class _OutputIter, - class _Compare> -_OutputIter vt_union(_InputIter1 __first1, _InputIter1 __last1, - _InputIter2 __first2, _InputIter2 __last2, - _OutputIter __result, _Equal __equal, _Aggregate __aggr ) -{ - - while ( __first1 != __last1 ) { - _InputIter1 __cur1 = __first1; - for ( ; __cur1 != __last1, ++__cur1 ) { - if ( __equal(*__cur1, *__first2) ) { - __aggr( __cur1, __first2, __result ); - ++__first2; - break; - } - ++__result; - } - if ( __cur1 == __last1 ) { - - } - } - - while (__first1 != __last1 && __first2 != __last2) { - if (__comp(*__first1, *__first2)) { - *__result = *__first1; - ++__first1; - } else if (__comp(*__first2, *__first1)) { - *__result = *__first2; - ++__first2; - } else { - *__result = *__first1; - ++__first1; - ++__first2; - } - ++__result; - } - return copy(__first2, __last2, copy(__first1, __last1, __result)); -} - // typedef std::pair<oid_type, vtime_unit_type> vtime_proc_type; // typedef std::list<vtime_proc_type> vtime_type; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |