lemon/fib_heap.h
author deba
Fri, 14 Oct 2005 10:52:15 +0000
changeset 1721 c0f5e8401373
parent 1435 8e85e6bbefdf
child 1753 98d83dd56c1d
permissions -rw-r--r--
Named parameter for heap and cross ref
It needs some redesign
alpar@906
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * 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@1359
     5
 * (Egervary Research Group on Combinatorial Optimization, 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>
deba@1332
    26
#include <cmath>
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
    
deba@1717
    91
    /// \brief The constructor
deba@1717
    92
    ///
deba@1717
    93
    /// \c _iimap should be given to the constructor, since it is
deba@1717
    94
    ///   used internally to handle the cross references.
deba@1185
    95
    explicit FibHeap(ItemIntMap &_iimap) 
deba@1185
    96
      : minimum(0), iimap(_iimap), num_items() {} 
jacint@1270
    97
 
deba@1717
    98
    /// \brief The constructor
deba@1717
    99
    ///
deba@1717
   100
    /// \c _iimap should be given to the constructor, since it is used
deba@1717
   101
    /// internally to handle the cross references. \c _comp is an
deba@1717
   102
    /// object for ordering of the priorities. 
jacint@373
   103
    FibHeap(ItemIntMap &_iimap, const Compare &_comp) : minimum(0), 
jacint@1270
   104
		  iimap(_iimap), comp(_comp), num_items() {}
alpar@255
   105
    
deba@1717
   106
    /// \brief The number of items stored in the heap.
deba@1717
   107
    ///
deba@1717
   108
    /// Returns the number of items stored in the heap.
jacint@373
   109
    int size() const { return num_items; }
jacint@373
   110
deba@1717
   111
    /// \brief Checks if the heap stores no items.
deba@1717
   112
    ///
deba@1717
   113
    ///   Returns \c true if and only if the heap stores no items.
jacint@373
   114
    bool empty() const { return num_items==0; }
jacint@373
   115
deba@1717
   116
    /// \brief Make empty this heap.
deba@1717
   117
    /// 
deba@1717
   118
    /// Make empty this heap.
deba@1717
   119
    void clear() { 
deba@1717
   120
      for (int i = 0; i < (int)container.size(); ++i) {
deba@1717
   121
	iimap[container[i].name] = -2;
deba@1717
   122
      }
deba@1717
   123
      container.clear(); minimum = 0; num_items = 0;
deba@1717
   124
    }
jacint@373
   125
deba@1717
   126
    /// \brief \c item gets to the heap with priority \c value independently 
deba@1717
   127
    /// if \c item was already there.
deba@1717
   128
    ///
deba@1717
   129
    /// This method calls \ref push(\c item, \c value) if \c item is not
deba@1717
   130
    /// stored in the heap and it calls \ref decrease(\c item, \c value) or
deba@1717
   131
    /// \ref increase(\c item, \c value) otherwise.
jacint@387
   132
    void set (Item const item, PrioType const value); 
jacint@373
   133
    
deba@1717
   134
    /// \brief Adds \c item to the heap with priority \c value. 
deba@1717
   135
    ///    
deba@1717
   136
    /// Adds \c item to the heap with priority \c value. 
deba@1717
   137
    /// \pre \c item must not be stored in the heap. 
jacint@387
   138
    void push (Item const item, PrioType const value);
jacint@373
   139
    
deba@1717
   140
    /// \brief Returns the item with minimum priority relative to \c Compare.
deba@1717
   141
    ///
deba@1717
   142
    /// This method returns the item with minimum priority relative to \c
deba@1717
   143
    /// Compare.  
deba@1717
   144
    /// \pre The heap must be nonempty.  
jacint@373
   145
    Item top() const { return container[minimum].name; }
jacint@373
   146
deba@1717
   147
    /// \brief Returns the minimum priority relative to \c Compare.
deba@1717
   148
    ///
deba@1717
   149
    /// It returns the minimum priority relative to \c Compare.
deba@1717
   150
    /// \pre The heap must be nonempty.
jacint@373
   151
    PrioType prio() const { return container[minimum].prio; }
jacint@373
   152
    
deba@1717
   153
    /// \brief Returns the priority of \c item.
deba@1717
   154
    ///
deba@1717
   155
    /// This function returns the priority of \c item.
deba@1717
   156
    /// \pre \c item must be in the heap.
jacint@387
   157
    PrioType& operator[](const Item& item) { 
jacint@387
   158
      return container[iimap[item]].prio; 
jacint@387
   159
    }
jacint@373
   160
    
deba@1717
   161
    /// \brief Returns the priority of \c item.
deba@1717
   162
    ///
deba@1717
   163
    /// It returns the priority of \c item.
deba@1717
   164
    /// \pre \c item must be in the heap.
jacint@387
   165
    const PrioType& operator[](const Item& item) const { 
jacint@387
   166
      return container[iimap[item]].prio; 
alpar@255
   167
    }
alpar@255
   168
alpar@255
   169
deba@1717
   170
    /// \brief Deletes the item with minimum priority relative to \c Compare.
deba@1717
   171
    ///
deba@1717
   172
    /// This method deletes the item with minimum priority relative to \c
deba@1717
   173
    /// Compare from the heap.  
deba@1717
   174
    /// \pre The heap must be non-empty.  
jacint@373
   175
    void pop();
jacint@373
   176
deba@1717
   177
    /// \brief Deletes \c item from the heap.
deba@1717
   178
    ///
deba@1717
   179
    /// This method deletes \c item from the heap, if \c item was already
deba@1717
   180
    /// stored in the heap. It is quite inefficient in Fibonacci heaps.
jacint@387
   181
    void erase (const Item& item); 
jacint@373
   182
deba@1717
   183
    /// \brief Decreases the priority of \c item to \c value.
deba@1717
   184
    ///
deba@1717
   185
    /// This method decreases the priority of \c item to \c value.
deba@1717
   186
    /// \pre \c item must be stored in the heap with priority at least \c
deba@1717
   187
    ///   value relative to \c Compare.
jacint@387
   188
    void decrease (Item item, PrioType const value); 
jacint@373
   189
deba@1717
   190
    /// \brief Increases the priority of \c item to \c value.
deba@1717
   191
    ///
deba@1717
   192
    /// This method sets the priority of \c item to \c value. Though
deba@1717
   193
    /// there is no precondition on the priority of \c item, this
deba@1717
   194
    /// method should be used only if it is indeed necessary to increase
deba@1717
   195
    /// (relative to \c Compare) the priority of \c item, because this
deba@1717
   196
    /// method is inefficient.
jacint@387
   197
    void increase (Item item, PrioType const value) {
jacint@387
   198
      erase(item);
jacint@387
   199
      push(item, value);
jacint@373
   200
    }
jacint@373
   201
jacint@373
   202
deba@1717
   203
    /// \brief Returns if \c item is in, has already been in, or has never 
deba@1717
   204
    /// been in the heap.
deba@1717
   205
    ///
deba@1717
   206
    /// This method returns PRE_HEAP if \c item has never been in the
deba@1717
   207
    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
deba@1717
   208
    /// otherwise. In the latter case it is possible that \c item will
deba@1717
   209
    /// get back to the heap again.
jacint@387
   210
    state_enum state(const Item &item) const {
jacint@387
   211
      int i=iimap[item];
jacint@387
   212
      if( i>=0 ) {
jacint@387
   213
	if ( container[i].in ) i=0;
jacint@387
   214
	else i=-2; 
jacint@387
   215
      }
jacint@387
   216
      return state_enum(i);
jacint@387
   217
    }    
jacint@387
   218
    
jacint@387
   219
  private:
jacint@387
   220
    
jacint@387
   221
    void balance();
jacint@387
   222
    void makeroot(int c);
jacint@387
   223
    void cut(int a, int b);
jacint@387
   224
    void cascade(int a);
jacint@387
   225
    void fuse(int a, int b);
jacint@387
   226
    void unlace(int a);
jacint@373
   227
jacint@373
   228
jacint@387
   229
    class store {
jacint@387
   230
      friend class FibHeap;
jacint@387
   231
      
jacint@387
   232
      Item name;
jacint@387
   233
      int parent;
jacint@387
   234
      int left_neighbor;
jacint@387
   235
      int right_neighbor;
jacint@387
   236
      int child;
jacint@387
   237
      int degree;  
jacint@387
   238
      bool marked;
jacint@387
   239
      bool in;
jacint@387
   240
      PrioType prio;
jacint@387
   241
      
jacint@387
   242
      store() : parent(-1), child(-1), degree(), marked(false), in(true) {} 
jacint@387
   243
    };
jacint@387
   244
  };    
jacint@387
   245
 
jacint@387
   246
jacint@373
   247
jacint@373
   248
    // **********************************************************************
jacint@373
   249
    //  IMPLEMENTATIONS
jacint@373
   250
    // **********************************************************************
jacint@373
   251
    
jacint@387
   252
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   253
    typename Compare>
jacint@387
   254
  void FibHeap<Item, Prio, ItemIntMap, Compare>::set 
jacint@387
   255
  (Item const item, PrioType const value) 
jacint@387
   256
  {
jacint@387
   257
    int i=iimap[item];
jacint@387
   258
    if ( i >= 0 && container[i].in ) {
jacint@387
   259
      if ( comp(value, container[i].prio) ) decrease(item, value); 
jacint@387
   260
      if ( comp(container[i].prio, value) ) increase(item, value); 
jacint@387
   261
    } else push(item, value);
jacint@387
   262
  }
alpar@255
   263
    
jacint@387
   264
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   265
    typename Compare>
jacint@387
   266
  void FibHeap<Item, Prio, ItemIntMap, Compare>::push 
jacint@387
   267
  (Item const item, PrioType const value) {
jacint@387
   268
      int i=iimap[item];      
alpar@255
   269
      if ( i < 0 ) {
alpar@255
   270
	int s=container.size();
jacint@387
   271
	iimap.set( item, s );	
alpar@255
   272
	store st;
jacint@387
   273
	st.name=item;
alpar@255
   274
	container.push_back(st);
alpar@255
   275
	i=s;
alpar@255
   276
      } else {
alpar@255
   277
	container[i].parent=container[i].child=-1;
alpar@255
   278
	container[i].degree=0;
alpar@255
   279
	container[i].in=true;
alpar@255
   280
	container[i].marked=false;
alpar@255
   281
      }
alpar@255
   282
alpar@255
   283
      if ( num_items ) {
alpar@255
   284
	container[container[minimum].right_neighbor].left_neighbor=i;
alpar@255
   285
	container[i].right_neighbor=container[minimum].right_neighbor;
alpar@255
   286
	container[minimum].right_neighbor=i;
alpar@255
   287
	container[i].left_neighbor=minimum;
alpar@255
   288
	if ( comp( value, container[minimum].prio) ) minimum=i; 
alpar@255
   289
      } else {
alpar@255
   290
	container[i].right_neighbor=container[i].left_neighbor=i;
alpar@255
   291
	minimum=i;	
alpar@255
   292
      }
alpar@255
   293
      container[i].prio=value;
alpar@255
   294
      ++num_items;
alpar@255
   295
    }
alpar@255
   296
    
jacint@387
   297
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   298
    typename Compare>
jacint@387
   299
  void FibHeap<Item, Prio, ItemIntMap, Compare>::pop() {
alpar@255
   300
      /*The first case is that there are only one root.*/
alpar@255
   301
      if ( container[minimum].left_neighbor==minimum ) {
alpar@255
   302
	container[minimum].in=false;
alpar@255
   303
	if ( container[minimum].degree!=0 ) { 
alpar@255
   304
	  makeroot(container[minimum].child);
alpar@255
   305
	  minimum=container[minimum].child;
alpar@255
   306
	  balance();
alpar@255
   307
	}
alpar@255
   308
      } else {
alpar@255
   309
	int right=container[minimum].right_neighbor;
alpar@255
   310
	unlace(minimum);
alpar@255
   311
	container[minimum].in=false;
alpar@255
   312
	if ( container[minimum].degree > 0 ) {
alpar@255
   313
	  int left=container[minimum].left_neighbor;
alpar@255
   314
	  int child=container[minimum].child;
alpar@255
   315
	  int last_child=container[child].left_neighbor;
alpar@255
   316
	
alpar@255
   317
	  makeroot(child);
alpar@255
   318
	  
alpar@255
   319
	  container[left].right_neighbor=child;
alpar@255
   320
	  container[child].left_neighbor=left;
alpar@255
   321
	  container[right].left_neighbor=last_child;
alpar@255
   322
	  container[last_child].right_neighbor=right;
alpar@255
   323
	}
alpar@255
   324
	minimum=right;
alpar@255
   325
	balance();
alpar@255
   326
      } // the case where there are more roots
alpar@255
   327
      --num_items;   
alpar@255
   328
    }
alpar@255
   329
jacint@387
   330
jacint@387
   331
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   332
    typename Compare>
jacint@387
   333
  void FibHeap<Item, Prio, ItemIntMap, Compare>::erase 
jacint@387
   334
  (const Item& item) {
jacint@387
   335
      int i=iimap[item];
alpar@255
   336
      
alpar@255
   337
      if ( i >= 0 && container[i].in ) { 	
alpar@255
   338
	if ( container[i].parent!=-1 ) {
alpar@255
   339
	  int p=container[i].parent;
alpar@255
   340
	  cut(i,p);	    
alpar@255
   341
	  cascade(p);
alpar@255
   342
	}
alpar@255
   343
	minimum=i;     //As if its prio would be -infinity
alpar@255
   344
	pop();
alpar@255
   345
      }
jacint@387
   346
  }
alpar@255
   347
    
jacint@387
   348
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   349
    typename Compare>
jacint@387
   350
  void FibHeap<Item, Prio, ItemIntMap, Compare>::decrease 
jacint@387
   351
  (Item item, PrioType const value) {
jacint@387
   352
      int i=iimap[item];
alpar@255
   353
      container[i].prio=value;
alpar@255
   354
      int p=container[i].parent;
alpar@255
   355
      
alpar@255
   356
      if ( p!=-1 && comp(value, container[p].prio) ) {
alpar@255
   357
	cut(i,p);	    
alpar@255
   358
	cascade(p);
alpar@255
   359
      }      
alpar@255
   360
      if ( comp(value, container[minimum].prio) ) minimum=i; 
jacint@387
   361
  }
jacint@387
   362
 
alpar@255
   363
jacint@387
   364
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   365
    typename Compare>
jacint@387
   366
  void FibHeap<Item, Prio, ItemIntMap, Compare>::balance() {      
alpar@255
   367
deba@1332
   368
    int maxdeg=int( std::floor( 2.08*log(double(container.size()))))+1;
alpar@255
   369
  
alpar@255
   370
    std::vector<int> A(maxdeg,-1); 
alpar@255
   371
    
alpar@255
   372
    /*
alpar@255
   373
     *Recall that now minimum does not point to the minimum prio element.
alpar@255
   374
     *We set minimum to this during balance().
alpar@255
   375
     */
alpar@255
   376
    int anchor=container[minimum].left_neighbor; 
alpar@255
   377
    int next=minimum; 
alpar@255
   378
    bool end=false; 
alpar@255
   379
    	
alpar@255
   380
       do {
alpar@255
   381
	int active=next;
alpar@255
   382
	if ( anchor==active ) end=true;
alpar@255
   383
	int d=container[active].degree;
alpar@255
   384
	next=container[active].right_neighbor;
alpar@255
   385
alpar@255
   386
	while (A[d]!=-1) {	  
alpar@255
   387
	  if( comp(container[active].prio, container[A[d]].prio) ) {
alpar@255
   388
	    fuse(active,A[d]); 
alpar@255
   389
	  } else { 
alpar@255
   390
	    fuse(A[d],active);
alpar@255
   391
	    active=A[d];
alpar@255
   392
	  } 
alpar@255
   393
	  A[d]=-1;
alpar@255
   394
	  ++d;
alpar@255
   395
	}	
alpar@255
   396
	A[d]=active;
alpar@255
   397
       } while ( !end );
alpar@255
   398
alpar@255
   399
alpar@255
   400
       while ( container[minimum].parent >=0 ) minimum=container[minimum].parent;
alpar@255
   401
       int s=minimum;
alpar@255
   402
       int m=minimum;
alpar@255
   403
       do {  
alpar@255
   404
	 if ( comp(container[s].prio, container[minimum].prio) ) minimum=s;
alpar@255
   405
	 s=container[s].right_neighbor;
alpar@255
   406
       } while ( s != m );
alpar@255
   407
    }
alpar@255
   408
jacint@387
   409
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   410
    typename Compare>
jacint@387
   411
  void FibHeap<Item, Prio, ItemIntMap, Compare>::makeroot 
jacint@387
   412
  (int c) {
alpar@255
   413
      int s=c;
alpar@255
   414
      do {  
alpar@255
   415
	container[s].parent=-1;
alpar@255
   416
	s=container[s].right_neighbor;
alpar@255
   417
      } while ( s != c );
alpar@255
   418
    }
jacint@387
   419
  
jacint@387
   420
  
jacint@387
   421
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   422
    typename Compare>
jacint@387
   423
  void FibHeap<Item, Prio, ItemIntMap, Compare>::cut 
jacint@387
   424
  (int a, int b) {    
jacint@387
   425
    /*
jacint@387
   426
     *Replacing a from the children of b.
jacint@387
   427
     */
jacint@387
   428
    --container[b].degree;
alpar@255
   429
    
jacint@387
   430
    if ( container[b].degree !=0 ) {
jacint@387
   431
      int child=container[b].child;
jacint@387
   432
      if ( child==a ) 
jacint@387
   433
	container[b].child=container[child].right_neighbor;
jacint@387
   434
      unlace(a);
jacint@387
   435
    }
jacint@387
   436
    
jacint@387
   437
    
jacint@387
   438
    /*Lacing a to the roots.*/
jacint@387
   439
    int right=container[minimum].right_neighbor;
jacint@387
   440
    container[minimum].right_neighbor=a;
jacint@387
   441
    container[a].left_neighbor=minimum;
jacint@387
   442
    container[a].right_neighbor=right;
jacint@387
   443
    container[right].left_neighbor=a;
jacint@387
   444
    
jacint@387
   445
    container[a].parent=-1;
jacint@387
   446
    container[a].marked=false;
jacint@387
   447
  }
jacint@387
   448
  
alpar@255
   449
jacint@387
   450
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   451
    typename Compare>
jacint@387
   452
  void FibHeap<Item, Prio, ItemIntMap, Compare>::cascade 
jacint@387
   453
  (int a) 
alpar@255
   454
    {
alpar@255
   455
      if ( container[a].parent!=-1 ) {
alpar@255
   456
	int p=container[a].parent;
alpar@255
   457
	
alpar@255
   458
	if ( container[a].marked==false ) container[a].marked=true;
alpar@255
   459
	else {
alpar@255
   460
	  cut(a,p);
alpar@255
   461
	  cascade(p);
alpar@255
   462
	}
alpar@255
   463
      }
alpar@255
   464
    }
alpar@255
   465
alpar@255
   466
jacint@387
   467
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   468
    typename Compare>
jacint@387
   469
  void FibHeap<Item, Prio, ItemIntMap, Compare>::fuse 
jacint@387
   470
  (int a, int b) {
alpar@255
   471
      unlace(b);
alpar@255
   472
      
alpar@255
   473
      /*Lacing b under a.*/
alpar@255
   474
      container[b].parent=a;
alpar@255
   475
alpar@255
   476
      if (container[a].degree==0) {
alpar@255
   477
	container[b].left_neighbor=b;
alpar@255
   478
	container[b].right_neighbor=b;
alpar@255
   479
	container[a].child=b;	
alpar@255
   480
      } else {
alpar@255
   481
	int child=container[a].child;
alpar@255
   482
	int last_child=container[child].left_neighbor;
alpar@255
   483
	container[child].left_neighbor=b;
alpar@255
   484
	container[b].right_neighbor=child;
alpar@255
   485
	container[last_child].right_neighbor=b;
alpar@255
   486
	container[b].left_neighbor=last_child;
alpar@255
   487
      }
alpar@255
   488
alpar@255
   489
      ++container[a].degree;
alpar@255
   490
      
alpar@255
   491
      container[b].marked=false;
alpar@255
   492
    }
alpar@255
   493
jacint@387
   494
  
jacint@387
   495
  /*
jacint@387
   496
   *It is invoked only if a has siblings.
jacint@387
   497
   */
jacint@387
   498
  template <typename Item, typename Prio, typename ItemIntMap, 
jacint@387
   499
    typename Compare>
jacint@387
   500
  void FibHeap<Item, Prio, ItemIntMap, Compare>::unlace 
jacint@387
   501
  (int a) {      
alpar@255
   502
      int leftn=container[a].left_neighbor;
alpar@255
   503
      int rightn=container[a].right_neighbor;
alpar@255
   504
      container[leftn].right_neighbor=rightn;
alpar@255
   505
      container[rightn].left_neighbor=leftn;
jacint@387
   506
  }
alpar@255
   507
  
alpar@430
   508
  ///@}
alpar@430
   509
alpar@921
   510
} //namespace lemon
alpar@477
   511
alpar@921
   512
#endif //LEMON_FIB_HEAP_H
alpar@477
   513