-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunitheap.cuh
68 lines (53 loc) · 1.81 KB
/
unitheap.cuh
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
// MIT License Copyright (c) 2016, Hao Wei.
#ifndef _UNITHEAP_H
#define _UNITHEAP_H
#include "tools.cuh"
#include <climits>
#include <cstdlib>
class ListElement {
public:
int key;
ul prev;
ul next;
};
class HeadEnd {
public:
ul first;
ul second;
};
class UnitHeap {
public:
std::vector<int> update;
std::vector<ListElement> LinkedList; // key=degree, prev=id of previous node
// in degree DESC ordering, next=...
std::vector<HeadEnd> Header; // first=id of first node with this degree,
// second=id of last node...
size_t heapsize = 0; // updated at each instant
ul top; // id of node with highest degree
ul huge; // ignore huge nodes (deg > sqrt of graph size)
ul none; // integer that cannot be a node index
const int infty = INT_MAX/2;
// reserve memory
UnitHeap(ul size);
// prepare insertion of node by compensating the key with a negative update
void InsertElement(const ul index, const int key);
// oncle all elements are inserted, create headers and linked list
void ReConstruct();
// update headers when element is removed
void erase_key_element(const ul index, const ul next, const ul prev);
// find best element and output it
ul ExtractMax();
// update top and decrease it if necessary
void DecreaseTop();
// delete a node from linked list, update headers
void DeleteElement(const ul index);
// change element key: increase update if possible otherwise call IncrementKey
void lazyIncrement(const ul index, const int up);
// increment key, move element in linked list, update headers
void IncrementKey(const ul index);
// debug
void print_status();
void safety_check();
// void DecrementKey(const ul index);
};
#endif