1 /***********************************************************************
2 * Software License Agreement (BSD License)
4 * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
5 * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *************************************************************************/
31 #ifndef OPENCV_FLANN_HEAP_H_
32 #define OPENCV_FLANN_HEAP_H_
41 * Priority Queue Implementation
43 * The priority queue is implemented with a heap. A heap is a complete
44 * (full) binary tree in which each parent is less than both of its
45 * children, but the order of the children is unspecified.
52 * Storage array for the heap.
53 * Type T must be comparable.
59 * Number of element in the heap
90 * Tests if the heap is empty
92 * Returns: true is heap empty, false otherwise
110 bool operator()(const T& t_1, const T& t_2) const
117 * Insert a new element in the heap.
119 * We select the next empty leaf node, and then keep moving any larger
120 * parents down until the right location is found to store this element.
123 * value = the new element to be inserted in the heap
127 /* If heap is full, then return without adding this element. */
128 if (count == length) {
132 heap.push_back(value);
133 static CompareT compareT;
134 std::push_heap(heap.begin(), heap.end(), compareT);
141 * Returns the node of minimum value from the heap (top of the heap).
144 * value = out parameter used to return the min element
145 * Returns: false if heap empty
147 bool popMin(T& value)
154 static CompareT compareT;
155 std::pop_heap(heap.begin(), heap.end(), compareT);
159 return true; /* Return old last node. */
165 #endif //OPENCV_FLANN_HEAP_H_