-
Notifications
You must be signed in to change notification settings - Fork 0
/
fibheap.h
79 lines (63 loc) · 1.99 KB
/
fibheap.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
// ---------------------------------------------------------------------
// MIT License
// Copyright (c) 2018 Henrik Peters
// See LICENSE file in the project root for full license information.
// ---------------------------------------------------------------------
#include <iostream>
#include <cmath>
#include <cstdlib>
#ifdef DEBUG
#include <assert.h>
#include <fstream>
#include <utility>
#include <list>
#include <map>
#endif
using namespace std;
#ifndef FIBHEAP_H
#define FIBHEAP_H
template <typename K, typename V>
class FibonacciHeap final {
private:
struct Node {
Node *prev, *next, *child, *parent;
K key;
V value;
bool marked;
unsigned int degree;
} *rootlist, *min;
unsigned int nodeCount;
inline void makeHeap();
void insertList(Node* node);
void freeList(Node* node);
void meldNode(Node* node);
void consolidate();
Node* link(Node* a, Node* b);
inline void appendNode(Node* node);
Node* find(Node* list, V value) const;
void cut(Node* node);
public:
FibonacciHeap();
FibonacciHeap(const FibonacciHeap<K,V>& orig);
FibonacciHeap<K,V>& operator=(const FibonacciHeap<K,V>& rhs);
~FibonacciHeap();
bool isEmpty() const;
void insert(K key, V value);
void meld(FibonacciHeap<K,V>* other);
V getMin() const;
V extractMin();
bool decreaseKey(V value, K newKey);
bool remove(V value);
#ifdef DEBUG
bool invariant();
bool invariantList(Node* node);
bool invariantNode(Node* node);
bool invariantDegree(Node* node);
bool invariantHeapOrder(Node* node, K key);
unsigned int invariantNodeCount(Node* node);
bool normalized(Node* node);
void dump(string dumpName = "dump");
void dumpNode(list<pair<Node*,int>>* nodeList, Node* node, int depth);
#endif
};
#endif /* FIBHEAP_H */