Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost][heap] Which heap to use.
From: degski (degski_at_[hidden])
Date: 2016-09-27 10:20:33


On 25 September 2016 at 17:07, degski <degski_at_[hidden]> wrote:

> What criteria should I use to choose a specific Boost.Heap implementation
> (skew, fibonacci etc), from the ones provided by the Boost.Heap library?
>

 Well, as no answer, wrote my own:

#define BV_NOEXCEPT noexcept
#define BV_CONST_NOEXCEPT const noexcept

template < typename T >
class priority_queue {

private:

    typedef std::vector < T > Data;

public:

    typedef typename Data::iterator iterator;
    typedef typename Data::const_iterator const_iterator;

private:

    Data m_data;

public:

    priority_queue ( ) BV_NOEXCEPT {

        m_data.reserve ( 16 );
    }

    iterator begin ( ) BV_NOEXCEPT {

        return m_data.begin ( );
    }

    const_iterator begin ( ) BV_CONST_NOEXCEPT {

        return m_data.begin ( );
    }

    iterator end ( ) BV_NOEXCEPT {

        return m_data.end ( );
    }

    const_iterator end ( ) BV_CONST_NOEXCEPT {

        return m_data.end ( );
    }

    void push ( const T & t_ ) BV_NOEXCEPT {

        const const_iterator i = std::lower_bound ( m_data.begin ( ),
m_data.end ( ), t_, std::greater < T > ( ) );

        if ( i == m_data.end ( ) or std::greater < T > ( ) ( t_, * i ) ) {

            m_data.insert ( i, t_ );
        }
    }

    inline void pop ( ) BV_NOEXCEPT {

        if ( m_data.size ( ) ) {

            m_data.pop_back ( );
        }
    }

    inline T top ( ) BV_CONST_NOEXCEPT {

        return m_data.back ( );
    }

    inline size_t size ( ) BV_CONST_NOEXCEPT {

        return m_data.size ( );
    }

    inline bool empty ( ) BV_CONST_NOEXCEPT {

        return m_data.empty ( );
    }
};

Have a good day,

degski



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net