QGIS API Documentation  2.99.0-Master (ba079d8)
priorityqueue.h
Go to the documentation of this file.
1 /*
2  * libpal - Automated Placement of Labels Library
3  *
4  * Copyright (C) 2008 Maxence Laurent, MIS-TIC, HEIG-VD
5  * University of Applied Sciences, Western Switzerland
6  * http://www.hes-so.ch
7  *
8  * Contact:
9  * maxence.laurent <at> heig-vd <dot> ch
10  * or
11  * eric.taillard <at> heig-vd <dot> ch
12  *
13  * This file is part of libpal.
14  *
15  * libpal is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation, either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * libpal is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with libpal. If not, see <http://www.gnu.org/licenses/>.
27  *
28  */
29 
30 #ifndef PAL_PRIORITYQUEUE_H
31 #define PAL_PRIORITYQUEUE_H
32 
33 #include <iostream>
34 
35 #define LEFT(x) (2*x+1)
36 #define RIGHT(x) (2*x+2)
37 #define PARENT(x) ((x-1)/2)
38 
39 
40 namespace pal
41 {
42 
49  {
50 
51  public:
52 
58  PriorityQueue( int n, int maxId, bool min );
60 
62  PriorityQueue( const PriorityQueue & ) = delete;
64  PriorityQueue &operator=( const PriorityQueue & ) = delete;
65 
66  void print();
67 
68  int getSize();
69  int getSizeByPos();
70 
71  bool isIn( int key );
72 
73  int getBest(); // O(log n)
74 
75  void remove( int key );
76  void insert( int key, double p );
77 
78  void sort(); // O(n log n)
79 
80  void downheap( int id );
81  void upheap( int key );
82 
83  void decreaseKey( int key );
84  void setPriority( int key, double new_p );
85 
86 
87  int getId( int key );
88  private:
89 
90  int size;
91  int maxsize;
92  int maxId;
93  int *heap = nullptr;
94  double *p = nullptr;
95  int *pos = nullptr;
96 
97  bool ( *greater )( double l, double r );
98  };
99 
100 } // namespace
101 
102 #endif
bool isIn(int key)
PriorityQueue & operator=(const PriorityQueue &)=delete
PriorityQueue cannot be copied.
void upheap(int key)
void downheap(int id)
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:452
void insert(int key, double p)
void setPriority(int key, double new_p)
PriorityQueue(int n, int maxId, bool min)
Create a priority queue of max size n \param n max size of the queuet \param p external vector repres...
void decreaseKey(int key)