src/lemon/fib_heap.h
author hegyi
Fri, 01 Apr 2005 08:28:51 +0000
changeset 1286 692948b894e8
parent 1204 c3e29c6ae4e4
child 1332 bf228b5f648f
permissions -rw-r--r--
Peter is able to read xy vector from file.
alpar@906
     1
/* -*- C++ -*-
alpar@921
     2
 * src/lemon/fib_heap.h - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@1164
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@906
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@906
     6
 *
alpar@906
     7
 * Permission to use, modify and distribute this software is granted
alpar@906
     8
 * provided that this copyright notice appears in all copies. For
alpar@906
     9
 * precise terms see the accompanying LICENSE file.
alpar@906
    10
 *
alpar@906
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    12
 * express or implied, and with no claim as to its suitability for any
alpar@906
    13
 * purpose.
alpar@906
    14
 *
alpar@906
    15
 */
alpar@255
    16
alpar@921
    17
#ifndef LEMON_FIB_HEAP_H
alpar@921
    18
#define LEMON_FIB_HEAP_H
alpar@255
    19
jacint@857
    20
///\file
klao@491
    21
///\ingroup auxdat
alpar@255
    22
///\brief Fibonacci Heap implementation.
alpar@255
    23
alpar@255
    24
#include <vector>
alpar@255
    25
#include <functional>
alpar@255
    26
#include <math.h>
alpar@255
    27
alpar@921
    28
namespace lemon {
alpar@255
    29
  
alpar@430
    30
  /// \addtogroup auxdat
alpar@430
    31
  /// @{
alpar@430
    32
jacint@857
    33
  /// Fibonacci Heap.
jacint@373
    34
jacint@857
    35
  ///This class implements the \e Fibonacci \e heap data structure. A \e heap
jacint@857
    36
  ///is a data structure for storing items with specified values called \e
jacint@857
    37
  ///priorities in such a way that finding the item with minimum priority is
alpar@911
    38
  ///efficient. \c Compare specifies the ordering of the priorities. In a heap
jacint@857
    39
  ///one can change the priority of an item, add or erase an item, etc.
jacint@857
    40
  ///
jacint@857
    41
  ///The methods \ref increase and \ref erase are not efficient in a Fibonacci
jacint@857
    42
  ///heap. In case of many calls to these operations, it is better to use a
jacint@857
    43
  ///\e binary \e heap.
jacint@857
    44
  ///
jacint@857
    45
  ///\param Item Type of the items to be stored.  
jacint@857
    46
  ///\param Prio Type of the priority of the items.
alpar@1204
    47
  ///\param ItemIntMap A read and writable Item int map, used internally
alpar@1204
    48
  ///to handle the cross references.
jacint@857
    49
  ///\param Compare A class for the ordering of the priorities. The
jacint@857
    50
  ///default is \c std::less<Prio>.
jacint@857
    51
  ///
alpar@967
    52
  ///\sa BinHeap
alpar@967
    53
  ///\sa Dijkstra
jacint@857
    54
  ///\author Jacint Szabo 
jacint@857
    55
 
jacint@373
    56
#ifdef DOXYGEN
jacint@373
    57
  template <typename Item, 
jacint@373
    58
	    typename Prio, 
jacint@373
    59
	    typename ItemIntMap, 
jacint@373
    60
	    typename Compare>
jacint@373
    61
#else
jacint@373
    62
  template <typename Item, 
jacint@373
    63
	    typename Prio, 
jacint@373
    64
	    typename ItemIntMap, 
alpar@255
    65
	    typename Compare = std::less<Prio> >
jacint@373
    66
#endif
alpar@255
    67
  class FibHeap {
jacint@387
    68
  public:     
alpar@255
    69
    typedef Prio PrioType;
alpar@255
    70
    
jacint@373
    71
  private:
alpar@255
    72
    class store;
alpar@255
    73
    
alpar@255
    74
    std::vector<store> container;
alpar@255
    75
    int minimum;
alpar@255
    76
    ItemIntMap &iimap;
alpar@255
    77
    Compare comp;
alpar@255
    78
    int num_items;
jacint@373
    79
    
alpar@255
    80
  public:
alpar@1127
    81
    ///Status of the nodes
alpar@255
    82
    enum state_enum {
alpar@1127
    83
      ///The node is in the heap
alpar@255
    84
      IN_HEAP = 0,
alpar@1127
    85
      ///The node has never been in the heap
alpar@255
    86
      PRE_HEAP = -1,
alpar@1127
    87
      ///The node was in the heap but it got out of it
alpar@255
    88
      POST_HEAP = -2
alpar@255
    89
    };
alpar@255
    90
    
jacint@1270
    91
    ///The constructor
jacint@1270
    92
jacint@1270
    93
    /**
jacint@1270
    94
       \c _iimap should be given to the constructor, since it is
jacint@1270
    95
       used internally to handle the cross references.
jacint@1270
    96
    */
deba@1185
    97
    explicit FibHeap(ItemIntMap &_iimap) 
deba@1185
    98
      : minimum(0), iimap(_iimap), num_items() {} 
jacint@1270
    99
 
jacint@1270
   100
    ///The constructor
jacint@1270
   101
jacint@1270
   102
    /**
jacint@1270
   103
       \c _iimap should be given to the constructor, since it is used
jacint@1270
   104
       internally to handle the cross references. \c _comp is an
jacint@1270
   105
       object for ordering of the priorities. 
jacint@1270
   106
    */
jacint@373
   107
    FibHeap(ItemIntMap &_iimap, const Compare &_comp) : minimum(0), 
jacint@1270
   108
		  iimap(_iimap), comp(_comp), num_items() {}
alpar@255
   109
    
jacint@373
   110
    ///The number of items stored in the heap.
jacint@373
   111
jacint@373
   112
    /**
jacint@387
   113
       Returns the number of items stored in the heap.
jacint@373
   114
    */
jacint@373
   115
    int size() const { return num_items; }
jacint@373
   116
jacint@373
   117
    ///Checks if the heap stores no items.
alpar@255
   118
    
jacint@373
   119
    /**
jacint@857
   120
       Returns \c true if and only if the heap stores no items.
jacint@373
   121
    */
jacint@373
   122
    bool empty() const { return num_items==0; }
jacint@373
   123
jacint@387
   124
    ///\c item gets to the heap with priority \c value independently if \c item was already there.
jacint@373
   125
jacint@373
   126
    /**
jacint@387
   127
       This method calls \ref push(\c item, \c value) if \c item is not
jacint@387
   128
       stored in the heap and it calls \ref decrease(\c item, \c value) or
jacint@387
   129
       \ref increase(\c item, \c value) otherwise.
jacint@373
   130
    */
jacint@387
   131
    void set (Item const item, PrioType const value); 
jacint@373
   132
    
jacint@373
   133
    ///Adds \c item to the heap with priority \c value. 
jacint@373
   134
    
jacint@373
   135
    /**
jacint@373
   136
       Adds \c item to the heap with priority \c value. 
jacint@373
   137
       \pre \c item must not be stored in the heap. 
jacint@373
   138
    */
jacint@387
   139
    void push (Item const item, PrioType const value);
jacint@373
   140
    
alpar@911
   141
    ///Returns the item with minimum priority relative to \c Compare.
jacint@373
   142
    
jacint@373
   143
    /**
alpar@911
   144
       This method returns the item with minimum priority relative to \c
jacint@857
   145
       Compare.  
jacint@857
   146
       \pre The heap must be nonempty.  
jacint@373
   147
    */
jacint@373
   148
    Item top() const { return container[minimum].name; }
jacint@373
   149
alpar@911
   150
    ///Returns the minimum priority relative to \c Compare.
jacint@373
   151
jacint@373
   152
    /**
alpar@911
   153
       It returns the minimum priority relative to \c Compare.
jacint@373
   154
       \pre The heap must be nonempty.
jacint@373
   155
    */
jacint@373
   156
    PrioType prio() const { return container[minimum].prio; }
jacint@373
   157
    
jacint@373
   158
    ///Returns the priority of \c item.
jacint@373
   159
jacint@373
   160
    /**
jacint@857
   161
       This function returns the priority of \c item.
jacint@373
   162
       \pre \c item must be in the heap.
jacint@373
   163
    */
jacint@387
   164
    PrioType& operator[](const Item& item) { 
jacint@387
   165
      return container[iimap[item]].prio; 
jacint@387
   166
    }
jacint@373
   167
    
jacint@373
   168
    ///Returns the priority of \c item.
jacint@373
   169
    
jacint@373
   170
    /**
jacint@373
   171
       It returns the priority of \c item.
jacint@373
   172
       \pre \c item must be in the heap.
jacint@373
   173
    */
jacint@387
   174
    const PrioType& operator[](const Item& item) const { 
jacint@387
   175
      return container[iimap[item]].prio; 
alpar@255
   176
    }
alpar@255
   177
alpar@255
   178
alpar@911
   179
    ///Deletes the item with minimum priority relative to \c Compare.
alpar@255
   180
jacint@373
   181
    /**
alpar@911
   182
    This method deletes the item with minimum priority relative to \c
jacint@857
   183
    Compare from the heap.  
jacint@857
   184
    \pre The heap must be non-empty.  
jacint@373
   185
    */
jacint@373
   186
    void pop();
jacint@373
   187
jacint@373
   188
    ///Deletes \c item from the heap.
jacint@373
   189
jacint@373
   190
    /**
jacint@373
   191
       This method deletes \c item from the heap, if \c item was already
jacint@373
   192
       stored in the heap. It is quite inefficient in Fibonacci heaps.
jacint@373
   193
    */
jacint@387
   194
    void erase (const Item& item); 
jacint@373
   195
jacint@373
   196
    ///Decreases the priority of \c item to \c value.
jacint@373
   197
jacint@373
   198
    /**
jacint@373
   199
       This method decreases the priority of \c item to \c value.
jacint@373
   200
       \pre \c item must be stored in the heap with priority at least \c
alpar@911
   201
       value relative to \c Compare.
jacint@373
   202
    */
jacint@387
   203
    void decrease (Item item, PrioType const value); 
jacint@373
   204
jacint@373
   205
    ///Increases the priority of \c item to \c value.
jacint@373
   206
jacint@373
   207
    /**
jacint@373
   208
       This method sets the priority of \c item to \c value. Though
jacint@373
   209
       there is no precondition on the priority of \c item, this
jacint@857
   210
       method should be used only if it is indeed necessary to increase
alpar@911
   211
       (relative to \c Compare) the priority of \c item, because this
jacint@373
   212
       method is inefficient.
jacint@373
   213
    */
jacint@387
   214
    void increase (Item item, PrioType const value) {
jacint@387
   215
      erase(item);
jacint@387
   216
      push(item, value);
jacint@373
   217
    }
jacint@373
   218
jacint@373
   219
jacint@857
   220
    ///Returns if \c item is in, has already been in, or has never been in the heap.
jacint@373
   221
jacint@373
   222
    /**
jacint@373
   223
       This method returns PRE_HEAP if \c item has never been in the
jacint@373
   224
       heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
jacint@373
   225
       otherwise. In the latter case it is possible that \c item will
jacint@373
   226
       get back to the heap again.
jacint@373
   227
    */
jacint@387
   228
    state_enum state(const Item &item) const {
jacint@387
   229
      int i=iimap[item];
jacint@387
   230
      if( i>=0 ) {
jacint@387
   231
	if ( container[i].in ) i=0;
jacint@387
   232
	else i=-2; 
jacint@387
   233
      }
jacint@387
   234
      return state_enum(i);
jacint@387
   235
    }    
jacint@387
   236
    
jacint@387
   237
  private:
jacint@387
   238
    
jacint@387
   239
    void balance();
jacint@387
   240
    void makeroot(int c);
jacint@387
   241
    void cut(int a, int b);
jacint@387
   242
    void cascade(int a);
jacint@387
   243
    void fuse(int a, int b);
jacint@387
   244
    void unlace(int a);
jacint@373
   245
jacint@373
   246
jacint@387
   247
    class store {
jacint@387
   248
      friend class FibHeap;
jacint@387
   249
      
jacint@387
   250
      Item name;
jacint@387
   251
      int parent;
jacint@387
   252
      int left_neighbor;
jacint@387
   253
      int right_neighbor;
jacint@387
   254
      int child;
jacint@387
   255
      int degree;  
jacint@387
   256
      bool marked;
jacint@387
   257
      bool in;
jacint@387
   258
      PrioType prio;
jacint@387
   259
      
jacint@387
   260
      store() : parent(-1), child(-1), degree(), marked(false), in(true) {} 
jacint@387
   261
    };
jacint@387
   262
  };    
jacint@387
   263
 
jacint@387
   264
jacint@373
   265
jacint@373
   266
    // **********************************************************************
jacint@373
   267
    //  IMPLEMENTATIONS
jacint@373
   268
    // **********************************************************************
jacint@373
   269
    
jacint@387
   270
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   271
    typename Compare>
jacint@387
   272
  void FibHeap<Item, Prio, ItemIntMap, Compare>::set 
jacint@387
   273
  (Item const item, PrioType const value) 
jacint@387
   274
  {
jacint@387
   275
    int i=iimap[item];
jacint@387
   276
    if ( i >= 0 && container[i].in ) {
jacint@387
   277
      if ( comp(value, container[i].prio) ) decrease(item, value); 
jacint@387
   278
      if ( comp(container[i].prio, value) ) increase(item, value); 
jacint@387
   279
    } else push(item, value);
jacint@387
   280
  }
alpar@255
   281
    
jacint@387
   282
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   283
    typename Compare>
jacint@387
   284
  void FibHeap<Item, Prio, ItemIntMap, Compare>::push 
jacint@387
   285
  (Item const item, PrioType const value) {
jacint@387
   286
      int i=iimap[item];      
alpar@255
   287
      if ( i < 0 ) {
alpar@255
   288
	int s=container.size();
jacint@387
   289
	iimap.set( item, s );	
alpar@255
   290
	store st;
jacint@387
   291
	st.name=item;
alpar@255
   292
	container.push_back(st);
alpar@255
   293
	i=s;
alpar@255
   294
      } else {
alpar@255
   295
	container[i].parent=container[i].child=-1;
alpar@255
   296
	container[i].degree=0;
alpar@255
   297
	container[i].in=true;
alpar@255
   298
	container[i].marked=false;
alpar@255
   299
      }
alpar@255
   300
alpar@255
   301
      if ( num_items ) {
alpar@255
   302
	container[container[minimum].right_neighbor].left_neighbor=i;
alpar@255
   303
	container[i].right_neighbor=container[minimum].right_neighbor;
alpar@255
   304
	container[minimum].right_neighbor=i;
alpar@255
   305
	container[i].left_neighbor=minimum;
alpar@255
   306
	if ( comp( value, container[minimum].prio) ) minimum=i; 
alpar@255
   307
      } else {
alpar@255
   308
	container[i].right_neighbor=container[i].left_neighbor=i;
alpar@255
   309
	minimum=i;	
alpar@255
   310
      }
alpar@255
   311
      container[i].prio=value;
alpar@255
   312
      ++num_items;
alpar@255
   313
    }
alpar@255
   314
    
jacint@387
   315
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   316
    typename Compare>
jacint@387
   317
  void FibHeap<Item, Prio, ItemIntMap, Compare>::pop() {
alpar@255
   318
      /*The first case is that there are only one root.*/
alpar@255
   319
      if ( container[minimum].left_neighbor==minimum ) {
alpar@255
   320
	container[minimum].in=false;
alpar@255
   321
	if ( container[minimum].degree!=0 ) { 
alpar@255
   322
	  makeroot(container[minimum].child);
alpar@255
   323
	  minimum=container[minimum].child;
alpar@255
   324
	  balance();
alpar@255
   325
	}
alpar@255
   326
      } else {
alpar@255
   327
	int right=container[minimum].right_neighbor;
alpar@255
   328
	unlace(minimum);
alpar@255
   329
	container[minimum].in=false;
alpar@255
   330
	if ( container[minimum].degree > 0 ) {
alpar@255
   331
	  int left=container[minimum].left_neighbor;
alpar@255
   332
	  int child=container[minimum].child;
alpar@255
   333
	  int last_child=container[child].left_neighbor;
alpar@255
   334
	
alpar@255
   335
	  makeroot(child);
alpar@255
   336
	  
alpar@255
   337
	  container[left].right_neighbor=child;
alpar@255
   338
	  container[child].left_neighbor=left;
alpar@255
   339
	  container[right].left_neighbor=last_child;
alpar@255
   340
	  container[last_child].right_neighbor=right;
alpar@255
   341
	}
alpar@255
   342
	minimum=right;
alpar@255
   343
	balance();
alpar@255
   344
      } // the case where there are more roots
alpar@255
   345
      --num_items;   
alpar@255
   346
    }
alpar@255
   347
jacint@387
   348
jacint@387
   349
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   350
    typename Compare>
jacint@387
   351
  void FibHeap<Item, Prio, ItemIntMap, Compare>::erase 
jacint@387
   352
  (const Item& item) {
jacint@387
   353
      int i=iimap[item];
alpar@255
   354
      
alpar@255
   355
      if ( i >= 0 && container[i].in ) { 	
alpar@255
   356
	if ( container[i].parent!=-1 ) {
alpar@255
   357
	  int p=container[i].parent;
alpar@255
   358
	  cut(i,p);	    
alpar@255
   359
	  cascade(p);
alpar@255
   360
	}
alpar@255
   361
	minimum=i;     //As if its prio would be -infinity
alpar@255
   362
	pop();
alpar@255
   363
      }
jacint@387
   364
  }
alpar@255
   365
    
jacint@387
   366
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   367
    typename Compare>
jacint@387
   368
  void FibHeap<Item, Prio, ItemIntMap, Compare>::decrease 
jacint@387
   369
  (Item item, PrioType const value) {
jacint@387
   370
      int i=iimap[item];
alpar@255
   371
      container[i].prio=value;
alpar@255
   372
      int p=container[i].parent;
alpar@255
   373
      
alpar@255
   374
      if ( p!=-1 && comp(value, container[p].prio) ) {
alpar@255
   375
	cut(i,p);	    
alpar@255
   376
	cascade(p);
alpar@255
   377
      }      
alpar@255
   378
      if ( comp(value, container[minimum].prio) ) minimum=i; 
jacint@387
   379
  }
jacint@387
   380
 
alpar@255
   381
jacint@387
   382
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   383
    typename Compare>
jacint@387
   384
  void FibHeap<Item, Prio, ItemIntMap, Compare>::balance() {      
alpar@255
   385
alpar@255
   386
    int maxdeg=int( floor( 2.08*log(double(container.size()))))+1;
alpar@255
   387
  
alpar@255
   388
    std::vector<int> A(maxdeg,-1); 
alpar@255
   389
    
alpar@255
   390
    /*
alpar@255
   391
     *Recall that now minimum does not point to the minimum prio element.
alpar@255
   392
     *We set minimum to this during balance().
alpar@255
   393
     */
alpar@255
   394
    int anchor=container[minimum].left_neighbor; 
alpar@255
   395
    int next=minimum; 
alpar@255
   396
    bool end=false; 
alpar@255
   397
    	
alpar@255
   398
       do {
alpar@255
   399
	int active=next;
alpar@255
   400
	if ( anchor==active ) end=true;
alpar@255
   401
	int d=container[active].degree;
alpar@255
   402
	next=container[active].right_neighbor;
alpar@255
   403
alpar@255
   404
	while (A[d]!=-1) {	  
alpar@255
   405
	  if( comp(container[active].prio, container[A[d]].prio) ) {
alpar@255
   406
	    fuse(active,A[d]); 
alpar@255
   407
	  } else { 
alpar@255
   408
	    fuse(A[d],active);
alpar@255
   409
	    active=A[d];
alpar@255
   410
	  } 
alpar@255
   411
	  A[d]=-1;
alpar@255
   412
	  ++d;
alpar@255
   413
	}	
alpar@255
   414
	A[d]=active;
alpar@255
   415
       } while ( !end );
alpar@255
   416
alpar@255
   417
alpar@255
   418
       while ( container[minimum].parent >=0 ) minimum=container[minimum].parent;
alpar@255
   419
       int s=minimum;
alpar@255
   420
       int m=minimum;
alpar@255
   421
       do {  
alpar@255
   422
	 if ( comp(container[s].prio, container[minimum].prio) ) minimum=s;
alpar@255
   423
	 s=container[s].right_neighbor;
alpar@255
   424
       } while ( s != m );
alpar@255
   425
    }
alpar@255
   426
jacint@387
   427
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   428
    typename Compare>
jacint@387
   429
  void FibHeap<Item, Prio, ItemIntMap, Compare>::makeroot 
jacint@387
   430
  (int c) {
alpar@255
   431
      int s=c;
alpar@255
   432
      do {  
alpar@255
   433
	container[s].parent=-1;
alpar@255
   434
	s=container[s].right_neighbor;
alpar@255
   435
      } while ( s != c );
alpar@255
   436
    }
jacint@387
   437
  
jacint@387
   438
  
jacint@387
   439
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   440
    typename Compare>
jacint@387
   441
  void FibHeap<Item, Prio, ItemIntMap, Compare>::cut 
jacint@387
   442
  (int a, int b) {    
jacint@387
   443
    /*
jacint@387
   444
     *Replacing a from the children of b.
jacint@387
   445
     */
jacint@387
   446
    --container[b].degree;
alpar@255
   447
    
jacint@387
   448
    if ( container[b].degree !=0 ) {
jacint@387
   449
      int child=container[b].child;
jacint@387
   450
      if ( child==a ) 
jacint@387
   451
	container[b].child=container[child].right_neighbor;
jacint@387
   452
      unlace(a);
jacint@387
   453
    }
jacint@387
   454
    
jacint@387
   455
    
jacint@387
   456
    /*Lacing a to the roots.*/
jacint@387
   457
    int right=container[minimum].right_neighbor;
jacint@387
   458
    container[minimum].right_neighbor=a;
jacint@387
   459
    container[a].left_neighbor=minimum;
jacint@387
   460
    container[a].right_neighbor=right;
jacint@387
   461
    container[right].left_neighbor=a;
jacint@387
   462
    
jacint@387
   463
    container[a].parent=-1;
jacint@387
   464
    container[a].marked=false;
jacint@387
   465
  }
jacint@387
   466
  
alpar@255
   467
jacint@387
   468
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   469
    typename Compare>
jacint@387
   470
  void FibHeap<Item, Prio, ItemIntMap, Compare>::cascade 
jacint@387
   471
  (int a) 
alpar@255
   472
    {
alpar@255
   473
      if ( container[a].parent!=-1 ) {
alpar@255
   474
	int p=container[a].parent;
alpar@255
   475
	
alpar@255
   476
	if ( container[a].marked==false ) container[a].marked=true;
alpar@255
   477
	else {
alpar@255
   478
	  cut(a,p);
alpar@255
   479
	  cascade(p);
alpar@255
   480
	}
alpar@255
   481
      }
alpar@255
   482
    }
alpar@255
   483
alpar@255
   484
jacint@387
   485
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   486
    typename Compare>
jacint@387
   487
  void FibHeap<Item, Prio, ItemIntMap, Compare>::fuse 
jacint@387
   488
  (int a, int b) {
alpar@255
   489
      unlace(b);
alpar@255
   490
      
alpar@255
   491
      /*Lacing b under a.*/
alpar@255
   492
      container[b].parent=a;
alpar@255
   493
alpar@255
   494
      if (container[a].degree==0) {
alpar@255
   495
	container[b].left_neighbor=b;
alpar@255
   496
	container[b].right_neighbor=b;
alpar@255
   497
	container[a].child=b;	
alpar@255
   498
      } else {
alpar@255
   499
	int child=container[a].child;
alpar@255
   500
	int last_child=container[child].left_neighbor;
alpar@255
   501
	container[child].left_neighbor=b;
alpar@255
   502
	container[b].right_neighbor=child;
alpar@255
   503
	container[last_child].right_neighbor=b;
alpar@255
   504
	container[b].left_neighbor=last_child;
alpar@255
   505
      }
alpar@255
   506
alpar@255
   507
      ++container[a].degree;
alpar@255
   508
      
alpar@255
   509
      container[b].marked=false;
alpar@255
   510
    }
alpar@255
   511
jacint@387
   512
  
jacint@387
   513
  /*
jacint@387
   514
   *It is invoked only if a has siblings.
jacint@387
   515
   */
jacint@387
   516
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   517
    typename Compare>
jacint@387
   518
  void FibHeap<Item, Prio, ItemIntMap, Compare>::unlace 
jacint@387
   519
  (int a) {      
alpar@255
   520
      int leftn=container[a].left_neighbor;
alpar@255
   521
      int rightn=container[a].right_neighbor;
alpar@255
   522
      container[leftn].right_neighbor=rightn;
alpar@255
   523
      container[rightn].left_neighbor=leftn;
jacint@387
   524
  }
alpar@255
   525
  
alpar@430
   526
  ///@}
alpar@430
   527
alpar@921
   528
} //namespace lemon
alpar@477
   529
alpar@921
   530
#endif //LEMON_FIB_HEAP_H
alpar@477
   531