2001-08-21 17:18:37 +02:00
|
|
|
/* A Fibonacci heap datatype.
|
2002-06-25 03:03:52 +02:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
2001-08-21 17:18:37 +02:00
|
|
|
Contributed by Daniel Berlin (dan@cgsoftware.com).
|
|
|
|
|
2001-08-23 16:51:49 +02:00
|
|
|
This file is part of GCC.
|
2001-08-21 17:18:37 +02:00
|
|
|
|
2001-08-23 16:51:49 +02:00
|
|
|
GCC is free software; you can redistribute it and/or modify it
|
2001-08-21 17:18:37 +02:00
|
|
|
under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
2001-08-23 16:51:49 +02:00
|
|
|
GCC is distributed in the hope that it will be useful, but
|
2001-08-21 17:18:37 +02:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2001-08-23 16:51:49 +02:00
|
|
|
along with GCC; see the file COPYING. If not, write to
|
2001-08-21 17:18:37 +02:00
|
|
|
the Free Software Foundation, 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
|
2001-08-22 04:11:38 +02:00
|
|
|
/* Fibonacci heaps are somewhat complex, but, there's an article in
|
|
|
|
DDJ that explains them pretty well:
|
2001-08-21 17:18:37 +02:00
|
|
|
|
|
|
|
http://www.ddj.com/articles/1997/9701/9701o/9701o.htm?topic=algoritms
|
|
|
|
|
2001-08-22 04:11:38 +02:00
|
|
|
Introduction to algorithms by Corman and Rivest also goes over them.
|
2001-08-21 17:18:37 +02:00
|
|
|
|
|
|
|
The original paper that introduced them is "Fibonacci heaps and their
|
|
|
|
uses in improved network optimization algorithms" by Tarjan and
|
|
|
|
Fredman (JACM 34(3), July 1987).
|
|
|
|
|
|
|
|
Amortized and real worst case time for operations:
|
|
|
|
|
|
|
|
ExtractMin: O(lg n) amortized. O(n) worst case.
|
|
|
|
DecreaseKey: O(1) amortized. O(lg n) worst case.
|
|
|
|
Insert: O(2) amortized. O(1) actual.
|
2001-08-22 04:11:38 +02:00
|
|
|
Union: O(1) amortized. O(1) actual. */
|
2001-08-21 17:18:37 +02:00
|
|
|
|
|
|
|
#ifndef _FIBHEAP_H_
|
|
|
|
#define _FIBHEAP_H_
|
|
|
|
|
2002-06-25 03:03:52 +02:00
|
|
|
#include "ansidecl.h"
|
2001-08-21 17:18:37 +02:00
|
|
|
|
2001-08-22 04:11:38 +02:00
|
|
|
typedef long fibheapkey_t;
|
|
|
|
|
2001-08-21 17:18:37 +02:00
|
|
|
typedef struct fibheap
|
|
|
|
{
|
|
|
|
size_t nodes;
|
|
|
|
struct fibnode *min;
|
|
|
|
struct fibnode *root;
|
|
|
|
} *fibheap_t;
|
2001-08-22 04:11:38 +02:00
|
|
|
|
2001-08-21 17:18:37 +02:00
|
|
|
typedef struct fibnode
|
|
|
|
{
|
|
|
|
struct fibnode *parent;
|
|
|
|
struct fibnode *child;
|
|
|
|
struct fibnode *left;
|
|
|
|
struct fibnode *right;
|
|
|
|
fibheapkey_t key;
|
|
|
|
void *data;
|
2004-12-10 23:04:33 +01:00
|
|
|
#if defined (__GNUC__) && (!defined (SIZEOF_INT) || SIZEOF_INT < 4)
|
2003-12-19 17:50:48 +01:00
|
|
|
__extension__ unsigned long int degree : 31;
|
|
|
|
__extension__ unsigned long int mark : 1;
|
2003-12-19 05:04:44 +01:00
|
|
|
#else
|
2001-08-22 04:11:38 +02:00
|
|
|
unsigned int degree : 31;
|
|
|
|
unsigned int mark : 1;
|
2003-12-19 05:04:44 +01:00
|
|
|
#endif
|
2001-08-21 17:18:37 +02:00
|
|
|
} *fibnode_t;
|
|
|
|
|
2005-03-28 04:08:50 +02:00
|
|
|
extern fibheap_t fibheap_new (void);
|
|
|
|
extern fibnode_t fibheap_insert (fibheap_t, fibheapkey_t, void *);
|
|
|
|
extern int fibheap_empty (fibheap_t);
|
|
|
|
extern fibheapkey_t fibheap_min_key (fibheap_t);
|
|
|
|
extern fibheapkey_t fibheap_replace_key (fibheap_t, fibnode_t,
|
|
|
|
fibheapkey_t);
|
|
|
|
extern void *fibheap_replace_key_data (fibheap_t, fibnode_t,
|
|
|
|
fibheapkey_t, void *);
|
|
|
|
extern void *fibheap_extract_min (fibheap_t);
|
|
|
|
extern void *fibheap_min (fibheap_t);
|
|
|
|
extern void *fibheap_replace_data (fibheap_t, fibnode_t, void *);
|
|
|
|
extern void *fibheap_delete_node (fibheap_t, fibnode_t);
|
|
|
|
extern void fibheap_delete (fibheap_t);
|
|
|
|
extern fibheap_t fibheap_union (fibheap_t, fibheap_t);
|
2001-08-22 04:11:38 +02:00
|
|
|
|
2001-08-21 17:18:37 +02:00
|
|
|
#endif /* _FIBHEAP_H_ */
|