#include #include #include "meaputils.h" namespace MeapUtils { IntMeap::index_type get_parent_index( IntMeap::index_type index ) { return ( ( ( index + 1 ) / 2 ) - 1 ); } IntMeap::index_type get_left_child_index( IntMeap::index_type index ) { return ( ( 2 * ( index + 1 ) ) - 1 ); } IntMeap::index_type get_right_sibling_index( IntMeap::index_type left_child_index ) { return ( left_child_index + 1 ); } IntMeap::const_iterator index_to_it( const IntMeap& meap, IntMeap::index_type index ) { if( index >= meap.size() ) { return meap.end(); } IntMeap::const_iterator ret = meap.begin(); std::advance( ret, index ); return ret; } IntMeap::index_type it_to_index( const IntMeap& meap, IntMeap::const_iterator it ) { return std::distance( meap.begin(), it ); } void swap_values( IntMeap::container_type& values, IntMeap::index_type i1, IntMeap::index_type i2 ) { std::swap( *( values.begin() + i1 ), *( values.begin() + i2 ) ); } void print_meap( const IntMeap& meap, std::ostream& out ) { for( IntMeap::const_iterator it = meap.begin(); it != meap.end(); ++it ) { out << *it << std::endl; } out << std::endl; } }