Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/gsomix/shogun
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Aug 1, 2011
2 parents a514bca + 44708d4 commit 60efbcd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
34 changes: 13 additions & 21 deletions src/shogun/lib/FibonacciHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,7 @@ int32_t CFibonacciHeap::extract_min(float64_t &ret_key)
child->left->right = child->right;
child->right->left = child->left;

// and insert in root list
child->right = min_node->right;
child->left = min_node;

child->left->right = child;
child->right->left = child;

// parent of all root's nodes is NULL
child->parent = NULL;

num_trees++;
add_to_roots(child);

// next iteration
child = next_child;
Expand All @@ -115,6 +105,8 @@ int32_t CFibonacciHeap::extract_min(float64_t &ret_key)
min_node->left->right = min_node->right;
min_node->right->left = min_node->left;

num_trees--;

if(min_node == min_node->right)
{
min_root = NULL; // remove last element
Expand All @@ -130,7 +122,6 @@ int32_t CFibonacciHeap::extract_min(float64_t &ret_key)
clear_node(result);

num_nodes--;
num_trees--;

return result;
}
Expand Down Expand Up @@ -173,9 +164,11 @@ void CFibonacciHeap::decrease_key(int32_t index, float64_t key)
if(key > nodes[index]->key)
return;


nodes[index]->key = key;

parent = nodes[index]->parent;

if(parent != NULL && nodes[index]->key < parent->key)
{
cut(nodes[index], parent);
Expand Down Expand Up @@ -213,6 +206,7 @@ void CFibonacciHeap::add_to_roots(FibonacciHeapNode *up_node)
}
}

up_node->parent = NULL;
num_trees++;
}

Expand All @@ -223,7 +217,7 @@ void CFibonacciHeap::consolidate()

int32_t Dn, d;

Dn = 1 + (int32_t)(8*sizeof(long));
Dn = 1 + (int32_t)(CMath::log2(max_num_nodes));

A = SG_MALLOC(FibonacciHeapNode* , Dn);
for(int32_t i = 0; i < Dn; i++)
Expand All @@ -244,17 +238,14 @@ void CFibonacciHeap::consolidate()
while(A[d] != NULL)
{
y = A[d];

if(y->key < x->key)
{
float64_t temp;
temp = y->key;
y->key = x->key;
x->key = temp;
}
FibonacciHeapNode *temp;

if(w == y)
{
w = y->right;
temp = y;
y = x;
x = temp;
}

link_nodes(y, x);
Expand Down Expand Up @@ -339,6 +330,7 @@ void CFibonacciHeap::cut(FibonacciHeapNode *child, FibonacciHeapNode *parent)
child->right->left = child->left;

add_to_roots(child);
child->marked = false;
}

void CFibonacciHeap::cascading_cut(FibonacciHeapNode *tree)
Expand Down
5 changes: 3 additions & 2 deletions src/shogun/lib/FibonacciHeap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#ifndef FIBONACCI_H_
#define FIBONACCI_H_

#include "base/SGObject.h"
#include "lib/common.h"
#include <shogun/base/SGObject.h>
#include <shogun/lib/common.h>
#include <shogun/mathematics/Math.h>

namespace shogun
{
Expand Down

0 comments on commit 60efbcd

Please sign in to comment.