-
Notifications
You must be signed in to change notification settings - Fork 10
/
minheap.h
46 lines (35 loc) · 1018 Bytes
/
minheap.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
#pragma once
#ifndef MINHEAP_H
#define MINHEAP_H
#include <memory>
#include <sys/time.h>
class Channel;
class MinHeap
{
public:
typedef std::shared_ptr<Channel> ChannelPtr;
MinHeap();
~MinHeap();
void Push(ChannelPtr ptChannel, const struct timeval & stActiveTime);
void Pop();
ChannelPtr Top();
void Change(ChannelPtr ptChannel, const struct timeval & stActiveTime);
void Delete(ChannelPtr ptChannel);
bool Empty();
void LevelPrint();
private:
static bool Greater(const ChannelPtr & lth, const ChannelPtr & rth);
void ShiftUp(ChannelPtr ptChannel);
void ShiftDown(ChannelPtr ptChannel);
private:
static const int kMinHeapInitSize;
// index of data start from 1
ChannelPtr * m_data;
int m_size;
int m_capacity;
};
static bool TimevalGreater(const struct timeval & lth, const struct timeval & rth)
{
return lth.tv_sec > rth.tv_sec ? true : lth.tv_sec < rth.tv_sec ? false : lth.tv_usec > rth.tv_usec ? true : false;
}
#endif