forked from 1flei/lccs-lsh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pri_queue.h
102 lines (78 loc) · 3.59 KB
/
pri_queue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef __PRI_QUEUE_H
#define __PRI_QUEUE_H
#include "def.h"
#include "result.h"
#include <cstdlib>
// -----------------------------------------------------------------------------
// MinK_List: a structure which maintains the smallest k values (of type Scalar)
// and associated object id (of type int).
//
// This structure is used for ANN search
// -----------------------------------------------------------------------------
class MinK_List {
public:
MinK_List(int max); // constructor (given max size)
~MinK_List(); // destructor
// -------------------------------------------------------------------------
void reset() { num_ = 0; }
// -------------------------------------------------------------------------
Scalar min_key() { return (num_ > 0 ? list_[0].key_ : MAXREAL); }
// -------------------------------------------------------------------------
Scalar max_key() { return (num_ >= k_ ? list_[k_ - 1].key_ : MAXREAL); }
// -------------------------------------------------------------------------
Scalar ith_key(int i) { return (i < num_ ? list_[i].key_ : MAXREAL); }
// -------------------------------------------------------------------------
int ith_id(int i) { return (i < num_ ? list_[i].id_ : MININT); }
// -------------------------------------------------------------------------
int size() { return num_; }
int getk() {
return k_;
}
// -------------------------------------------------------------------------
bool isFull(); // is full?
// -------------------------------------------------------------------------
Scalar insert( // insert item
Scalar key, // key of item
int id); // id of item
protected:
int k_; // max numner of keys
int num_; // number of key current active
Result *list_; // the list itself
};
// -----------------------------------------------------------------------------
// MaxK_List: An MaxK_List structure is one which maintains the largest k
// values (of type Scalar) and associated object id (of type int).
//
// This structure is used for MIP search
// -----------------------------------------------------------------------------
class MaxK_List {
public:
MaxK_List(int max); // constructor (given max size)
~MaxK_List(); // destructor
// -------------------------------------------------------------------------
void reset() { num_ = 0; }
// -------------------------------------------------------------------------
Scalar max_key() { return num_ > 0 ? list_[0].key_ : MINREAL; }
// -------------------------------------------------------------------------
Scalar min_key() { return num_ == k_ ? list_[k_-1].key_ : MINREAL; }
// -------------------------------------------------------------------------
Scalar ith_key(int i) { return i < num_ ? list_[i].key_ : MINREAL; }
// -------------------------------------------------------------------------
int ith_id(int i) { return i < num_ ? list_[i].id_ : MININT; }
// -------------------------------------------------------------------------
int size() { return num_; }
int getk() {
return k_;
}
// -------------------------------------------------------------------------
bool isFull(); // is full?
// -------------------------------------------------------------------------
Scalar insert( // insert item
Scalar key, // key of item
int id); // id of item
private:
int k_; // max numner of keys
int num_; // number of key current active
Result *list_; // the list itself
};
#endif // __PRI_QUEUE_H