SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FibonacciHeap.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2011 Evgeniy Andreev (gsomix)
8  *
9  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
10  */
11 
12 #ifndef FIBONACCI_H_
13 #define FIBONACCI_H_
14 
15 #include <shogun/base/SGObject.h>
16 #include <shogun/lib/common.h>
18 
19 namespace shogun
20 {
21 
22 #ifndef DOXYGEN_SHOULD_SKIP_THIS
23 struct FibonacciHeapNode
24 {
26  FibonacciHeapNode* parent;
27 
29  FibonacciHeapNode* child;
30 
32  FibonacciHeapNode* left;
33 
35  FibonacciHeapNode* right;
36 
38  int32_t rank;
39 
41  bool marked;
42 
44  int32_t index;
45 
47  float64_t key;
48 };
49 
56 class CFibonacciHeap: public CSGObject
57 {
58 public:
59 
60  CFibonacciHeap();
61 
63  CFibonacciHeap(int32_t capacity);
64 
65  virtual inline const char* get_name() const
66  {
67  return "FibonacciHeap";
68  }
69 
70  virtual ~CFibonacciHeap();
71 
72 
73  int32_t get_num_nodes() const
74  {
75  return num_nodes;
76  }
77 
78  int32_t get_num_trees()
79  {
80  return num_trees;
81  }
82 
83  int32_t get_capacity()
84  {
85  return max_num_nodes;
86  }
87 
91  void insert(int32_t index, float64_t key);
92 
97  int32_t extract_min(float64_t &ret_key);
98 
100  void clear();
101 
105  int32_t get_key(int32_t index, float64_t &ret_key);
106 
110  void decrease_key(int32_t index, float64_t key);
111 
112  void debug_print();
113 
114 private:
116  void add_to_roots(FibonacciHeapNode *up_node);
117 
119  void consolidate();
120 
122  void link_nodes(FibonacciHeapNode *right, FibonacciHeapNode *left);
123 
125  void clear_node(int32_t index);
126 
128  void cut(FibonacciHeapNode *child, FibonacciHeapNode *parent);
129 
130  void cascading_cut(FibonacciHeapNode* tree);
131 
132 protected:
134  FibonacciHeapNode* min_root;
135 
137  FibonacciHeapNode** nodes;
138 
140  int32_t num_nodes;
141 
143  int32_t num_trees;
144 
146  int32_t max_num_nodes;
147 
149  FibonacciHeapNode **A;
150 
152  int32_t Dn;
153 };
154 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
155 
156 }
157 #endif /* FIBONACCI_H_ */

SHOGUN Machine Learning Toolbox - Documentation