| Home | Libraries | People | FAQ | More

## Class template d_ary_heap

boost::heap::d_ary_heap — d-ary heap class

## Synopsis

    // In header: <boost/heap/d_ary_heap.hpp>

    template<typename T, class... Options>
    class d_ary_heap {
    public:
      // types
      typedef T                                        value_type;
      typedef implementation_defined::size_type        size_type;
      typedef implementation_defined::difference_type  difference_type;
      typedef implementation_defined::value_compare    value_compare;
      typedef implementation_defined::allocator_type   allocator_type;
      typedef implementation_defined::reference        reference;
      typedef implementation_defined::const_reference  const_reference;
      typedef implementation_defined::pointer          pointer;
      typedef implementation_defined::const_pointer    const_pointer;
      typedef implementation_defined::iterator         iterator;
      typedef implementation_defined::const_iterator   const_iterator;
      typedef implementation_defined::ordered_iterator ordered_iterator;
      typedef implementation_defined::handle_type      handle_type;

      // public member functions
      explicit d_ary_heap(value_compare const & = value_compare());
      d_ary_heap(d_ary_heap const &) = default;
      d_ary_heap(d_ary_heap &&) = default;
      d_ary_heap & operator=(d_ary_heap &&) = default;
      d_ary_heap & operator=(d_ary_heap const &);
      bool empty(void) const;
      size_type size(void) const;
      size_type max_size(void) const;
      void clear(void);
      allocator_type get_allocator(void) const;
      value_type const & top(void) const;
      std::conditional< is_mutable, handle_type, void >::type
      push(value_type const &);
      template<class... Args>
        std::conditional< is_mutable, handle_type, void >::type
        emplace(Args &&...);
      template<typename HeapType> bool operator<(HeapType const &) const;
      template<typename HeapType> bool operator>(HeapType const &) const;
      template<typename HeapType> bool operator>=(HeapType const &) const;
      template<typename HeapType> bool operator<=(HeapType const &) const;
      template<typename HeapType> bool operator==(HeapType const &) const;
      template<typename HeapType> bool operator!=(HeapType const &) const;
      void update(handle_type, const_reference);
      void update(handle_type);
      void increase(handle_type, const_reference);
      void increase(handle_type);
      void decrease(handle_type, const_reference);
      void decrease(handle_type);
      void erase(handle_type);
      void pop(void);
      void swap(d_ary_heap &);
      const_iterator begin(void) const;
      iterator begin(void);
      iterator end(void);
      const_iterator end(void) const;
      ordered_iterator ordered_begin(void) const;
      ordered_iterator ordered_end(void) const;
      void reserve(size_type);
      value_compare const & value_comp(void) const;

      // public static functions
      static handle_type s_handle_from_iterator(iterator const &);

      // private member functions
      void do_swap(d_ary_heap &);

      // public data members
      static const bool constant_time_size;
      static const bool has_ordered_iterators;
      static const bool is_mergable;
      static const bool has_reserve;
      static const bool is_stable;
    };

## Description

This class implements an immutable priority queue. Internally, the d-ary heap is represented as dynamically sized array (std::vector), that directly stores the values.

The template parameter T is the type to be managed by the container. The user can specify additional options and if no options are provided default options are used.

The container supports the following options:

- `boost::heap::arity<>`, required

- `boost::heap::compare<>`, defaults to `compare<std::less<T>` >

- `boost::heap::stable<>`, defaults to `stable<false>`

- `boost::heap::stability_counter_type<>`, defaults to `stability_counter_type<boost::uintmax_t>`

- `boost::heap::allocator<>`, defaults to `allocator<std::allocator<T>` >

- `boost::heap::mutable_<>`, defaults to `mutable_<false>`

### `d_ary_heap` public types

1. typedef implementation_defined::iterator iterator;

   Note: The iterator does not traverse the priority queue in order of the priorities.

### `d_ary_heap` public member functions

1.     explicit d_ary_heap(value_compare const & cmp = value_compare());

   Effects: constructs an empty priority queue.

   Complexity: Constant.

2.     d_ary_heap(d_ary_heap const & rhs) = default;

   Effects: copy-constructs priority queue from rhs.

   Complexity: Linear.

3.     d_ary_heap(d_ary_heap && rhs) = default;

   Effects: C++11-style move constructor.

   Complexity: Constant.

4.     d_ary_heap & operator=(d_ary_heap && rhs) = default;

   Effects: C++11-style move assignment.

   Complexity: Constant.

5.     d_ary_heap & operator=(d_ary_heap const & rhs);

   Effects: Assigns priority queue from rhs.

   Complexity: Linear.

6.     bool empty(void) const;

   Effects: Returns true, if the priority queue contains no elements.

   Complexity: Constant.

7.     size_type size(void) const;

   Effects: Returns the number of elements contained in the priority queue.

   Complexity: Constant.

8.     size_type max_size(void) const;

   Effects: Returns the maximum number of elements the priority queue can contain.

   Complexity: Constant.

9.     void clear(void);

   Effects: Removes all elements from the priority queue.

   Complexity: Linear.

10.     allocator_type get_allocator(void) const;

    Effects: Returns allocator.

    Complexity: Constant.

11.     value_type const & top(void) const;

    Effects: Returns a const_reference to the maximum element.

    Complexity: Constant.

12.     std::conditional< is_mutable, handle_type, void >::type
        push(value_type const & v);

    Effects: Adds a new element to the priority queue.

    Complexity: Logarithmic (amortized). Linear (worst case).

13.     template<class... Args>
          std::conditional< is_mutable, handle_type, void >::type
          emplace(Args &&... args);

    Effects: Adds a new element to the priority queue. The element is directly constructed in-place.

    Complexity: Logarithmic (amortized). Linear (worst case).

14.     template<typename HeapType> bool operator<(HeapType const & rhs) const;

    Returns: Element-wise comparison of heap data structures

    Requirement: the `value_compare` object of both heaps must match.

15.     template<typename HeapType> bool operator>(HeapType const & rhs) const;

    Returns: Element-wise comparison of heap data structures

    Requirement: the `value_compare` object of both heaps must match.

16.     template<typename HeapType> bool operator>=(HeapType const & rhs) const;

    Returns: Element-wise comparison of heap data structures

    Requirement: the `value_compare` object of both heaps must match.

17.     template<typename HeapType> bool operator<=(HeapType const & rhs) const;

    Returns: Element-wise comparison of heap data structures

    Requirement: the `value_compare` object of both heaps must match.

18.     template<typename HeapType> bool operator==(HeapType const & rhs) const;

    Equivalent comparison Returns: True, if both heap data structures are equivalent.

    Requirement: the `value_compare` object of both heaps must match.

19.     template<typename HeapType> bool operator!=(HeapType const & rhs) const;

    Equivalent comparison Returns: True, if both heap data structures are not equivalent.

    Requirement: the `value_compare` object of both heaps must match.

20.     void update(handle_type handle, const_reference v);

    Effects: Assigns `v` to the element handled by `handle` & updates the priority queue.

    Complexity: Logarithmic.

    Requirement: data structure must be configured as mutable

21.     void update(handle_type handle);

    Effects: Updates the heap after the element handled by `handle` has been changed.

    Complexity: Logarithmic.

    Note: If this is not called, after a handle has been updated, the behavior of the data structure is undefined!

    Requirement: data structure must be configured as mutable

22.     void increase(handle_type handle, const_reference v);

    Effects: Assigns `v` to the element handled by `handle` & updates the priority queue.

    Complexity: Logarithmic.

    Note: The new value is expected to be greater than the current one

    Requirement: data structure must be configured as mutable

23.     void increase(handle_type handle);

    Effects: Updates the heap after the element handled by `handle` has been changed.

    Complexity: Logarithmic.

    Note: The new value is expected to be greater than the current one. If this is not called, after a handle has been updated, the behavior of the data structure is undefined!

    Requirement: data structure must be configured as mutable

24.     void decrease(handle_type handle, const_reference v);

    Effects: Assigns `v` to the element handled by `handle` & updates the priority queue.

    Complexity: Logarithmic.

    Note: The new value is expected to be less than the current one

    Requirement: data structure must be configured as mutable

25.     void decrease(handle_type handle);

    Effects: Updates the heap after the element handled by `handle` has been changed.

    Complexity: Logarithmic.

    Note: The new value is expected to be less than the current one. If this is not called, after a handle has been updated, the behavior of the data structure is undefined!

    Requirement: data structure must be configured as mutable

26.     void erase(handle_type handle);

    Effects: Removes the element handled by `handle` from the priority_queue.

    Complexity: Logarithmic.

    Requirement: data structure must be configured as mutable

27.     void pop(void);

    Effects: Removes the top element from the priority queue.

    Complexity: Logarithmic (amortized). Linear (worst case).

28.     void swap(d_ary_heap & rhs);

    Effects: Swaps two priority queues.

    Complexity: Constant.

    <xrefsect><xreftitle>Deprecated</xreftitle><xrefdescription>

    Use `std::swap` instead.

    </xrefdescription></xrefsect>

29.     const_iterator begin(void) const;

    Effects: Returns an iterator to the first element contained in the priority queue.

    Complexity: Constant.

30.     iterator begin(void);

    Effects: Returns an iterator to the first element contained in the priority queue.

    Complexity: Constant.

31.     iterator end(void);

    Effects: Returns an iterator to the end of the priority queue.

    Complexity: Constant.

32.     const_iterator end(void) const;

    Effects: Returns an iterator to the end of the priority queue.

    Complexity: Constant.

33.     ordered_iterator ordered_begin(void) const;

    Effects: Returns an ordered iterator to the first element contained in the priority queue.

    Note: Ordered iterators traverse the priority queue in heap order.

34.     ordered_iterator ordered_end(void) const;

    Effects: Returns an ordered iterator to the end of the priority queue.

    Note: Ordered iterators traverse the priority queue in heap order.

35.     void reserve(size_type element_count);

    Effects: Reserves memory for element_count elements

    Complexity: Linear.

    Node: Invalidates iterators

36.     value_compare const & value_comp(void) const;

    Effect: Returns the value_compare object used by the priority queue

### `d_ary_heap` public static functions

1.     static handle_type s_handle_from_iterator(iterator const & it);

   Effects: Casts an iterator to a node handle.

   Complexity: Constant.

   Requirement: data structure must be configured as mutable

### `d_ary_heap` private member functions

1.     void do_swap(d_ary_heap & rhs);