-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbinheap.hpp
54 lines (41 loc) · 979 Bytes
/
binheap.hpp
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
//
// Copyright (c) 2015 – Thomson Licensing, SAS
//
// The source code form of this open source project is subject to the terms of the
// Clear BSD license.
//
// You can redistribute it and/or modify it under the terms of the Clear BSD
// License (See LICENSE file).
//
#ifndef BINHEAP_HPP_
#define BINHEAP_HPP_
#include <memory>
#include <utility>
#include <algorithm>
class binheap {
private:
typedef std::pair<int, float> TupleType;
std::unique_ptr<TupleType[]> data_;
int capacity_;
int size_;
static bool comparator(const TupleType a, const TupleType& b) {
return a.second < b.second;
}
public:
binheap(int capacity) :
capacity_(capacity), size_(0) {
data_.reset(new std::pair<int, float>[capacity_+1]);
}
int capacity() const {
return capacity_;
}
int size() const {
return size_;
}
float max() const {
return data_[0].second;
}
void push(int id, float value);
void sort(int ids[], float values[]);
};
#endif /* BINHEAP_HPP_ */