queso-0.53.0
Classes | Public Member Functions | Private Attributes | List of all members
ANNpr_queue Class Reference

#include <pr_queue.h>

Collaboration diagram for ANNpr_queue:
Collaboration graph
[legend]

Classes

struct  pq_node
 

Public Member Functions

 ANNpr_queue (int max)
 
 ~ANNpr_queue ()
 
ANNbool empty ()
 
ANNbool non_empty ()
 
void reset ()
 
void insert (PQkey kv, PQinfo inf)
 
void extr_min (PQkey &kv, PQinfo &inf)
 

Private Attributes

int n
 
int max_size
 
pq_nodepq
 

Detailed Description

Definition at line 54 of file pr_queue.h.

Constructor & Destructor Documentation

ANNpr_queue::ANNpr_queue ( int  max)
inline

Definition at line 65 of file pr_queue.h.

References max_size, n, and pq.

66  {
67  n = 0; // initially empty
68  max_size = max; // maximum number of items
69  pq = new pq_node[max+1]; // queue is array [1..max] of nodes
70  }
pq_node * pq
Definition: pr_queue.h:62
int max_size
Definition: pr_queue.h:61
ANNpr_queue::~ANNpr_queue ( )
inline

Definition at line 72 of file pr_queue.h.

References pq.

73  { delete [] pq; }
pq_node * pq
Definition: pr_queue.h:62

Member Function Documentation

ANNbool ANNpr_queue::empty ( )
inline

Definition at line 75 of file pr_queue.h.

References ANNfalse, ANNtrue, and n.

76  { if (n==0) return ANNtrue; else return ANNfalse; }
Definition: ANN.h:132
Definition: ANN.h:132
void ANNpr_queue::extr_min ( PQkey kv,
PQinfo inf 
)
inline

Definition at line 102 of file pr_queue.h.

References ANN_FLOP, ANNpr_queue::pq_node::info, ANNpr_queue::pq_node::key, n, and pq.

Referenced by ANNkd_tree::annkPriSearch().

105  {
106  kv = pq[1].key; // key of min item
107  inf = pq[1].info; // information of min item
108  register PQkey kn = pq[n--].key;// last item in queue
109  register int p = 1; // p points to item out of position
110  register int r = p<<1; // left child of p
111  while (r <= n) { // while r is still within the heap
112  ANN_FLOP(2) // increment floating ops
113  // set r to smaller child of p
114  if (r < n && pq[r].key > pq[r+1].key) r++;
115  if (kn <= pq[r].key) // in proper order
116  break;
117  pq[p] = pq[r]; // else swap with child
118  p = r; // advance pointers
119  r = p<<1;
120  }
121  pq[p] = pq[n+1]; // insert last item in proper place
122  }
pq_node * pq
Definition: pr_queue.h:62
ANNdist PQkey
Definition: pr_queue.h:36
#define ANN_FLOP(n)
Definition: ANNperf.h:131
void ANNpr_queue::insert ( PQkey  kv,
PQinfo  inf 
)
inline

Definition at line 84 of file pr_queue.h.

References ANN_FLOP, ANNabort, annError(), ANNpr_queue::pq_node::info, ANNpr_queue::pq_node::key, max_size, n, and pq.

Referenced by ANNbd_shrink::ann_pri_search(), ANNkd_split::ann_pri_search(), and ANNkd_tree::annkPriSearch().

87  {
88  if (++n > max_size) annError("Priority queue overflow.", ANNabort);
89  register int r = n;
90  while (r > 1) { // sift up new item
91  register int p = r/2;
92  ANN_FLOP(1) // increment floating ops
93  if (pq[p].key <= kv) // in proper order
94  break;
95  pq[r] = pq[p]; // else swap with parent
96  r = p;
97  }
98  pq[r].key = kv; // insert new item at final location
99  pq[r].info = inf;
100  }
pq_node * pq
Definition: pr_queue.h:62
Definition: ANNx.h:48
void annError(const char *msg, ANNerr level)
Definition: ANN.cpp:169
#define ANN_FLOP(n)
Definition: ANNperf.h:131
int max_size
Definition: pr_queue.h:61
ANNbool ANNpr_queue::non_empty ( )
inline

Definition at line 78 of file pr_queue.h.

References ANNfalse, ANNtrue, and n.

Referenced by ANNkd_tree::annkPriSearch().

79  { if (n==0) return ANNfalse; else return ANNtrue; }
Definition: ANN.h:132
Definition: ANN.h:132
void ANNpr_queue::reset ( )
inline

Definition at line 81 of file pr_queue.h.

References n.

82  { n = 0; }

Member Data Documentation

int ANNpr_queue::max_size
private

Definition at line 61 of file pr_queue.h.

Referenced by ANNpr_queue(), and insert().

int ANNpr_queue::n
private

Definition at line 60 of file pr_queue.h.

Referenced by ANNpr_queue(), empty(), extr_min(), insert(), non_empty(), and reset().

pq_node* ANNpr_queue::pq
private

Definition at line 62 of file pr_queue.h.

Referenced by ANNpr_queue(), extr_min(), insert(), and ~ANNpr_queue().


The documentation for this class was generated from the following file:

Generated on Thu Jun 11 2015 13:52:33 for queso-0.53.0 by  doxygen 1.8.5