| 1 | /* fibheap.h,v 1.2 2004/09/14 22:27:32 bird Exp */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * GNU, -liberty.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /* A Fibonacci heap datatype.
|
|---|
| 7 | Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
|---|
| 8 | Contributed by Daniel Berlin (dan@cgsoftware.com).
|
|---|
| 9 |
|
|---|
| 10 | This file is part of GCC.
|
|---|
| 11 |
|
|---|
| 12 | GCC is free software; you can redistribute it and/or modify it
|
|---|
| 13 | under the terms of the GNU General Public License as published by
|
|---|
| 14 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 15 | any later version.
|
|---|
| 16 |
|
|---|
| 17 | GCC is distributed in the hope that it will be useful, but
|
|---|
| 18 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 20 | General Public License for more details.
|
|---|
| 21 |
|
|---|
| 22 | You should have received a copy of the GNU General Public License
|
|---|
| 23 | along with GCC; see the file COPYING. If not, write to
|
|---|
| 24 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
|---|
| 25 | Boston, MA 02111-1307, USA. */
|
|---|
| 26 |
|
|---|
| 27 | /* Fibonacci heaps are somewhat complex, but, there's an article in
|
|---|
| 28 | DDJ that explains them pretty well:
|
|---|
| 29 |
|
|---|
| 30 | http://www.ddj.com/articles/1997/9701/9701o/9701o.htm?topic=algoritms
|
|---|
| 31 |
|
|---|
| 32 | Introduction to algorithms by Corman and Rivest also goes over them.
|
|---|
| 33 |
|
|---|
| 34 | The original paper that introduced them is "Fibonacci heaps and their
|
|---|
| 35 | uses in improved network optimization algorithms" by Tarjan and
|
|---|
| 36 | Fredman (JACM 34(3), July 1987).
|
|---|
| 37 |
|
|---|
| 38 | Amortized and real worst case time for operations:
|
|---|
| 39 |
|
|---|
| 40 | ExtractMin: O(lg n) amortized. O(n) worst case.
|
|---|
| 41 | DecreaseKey: O(1) amortized. O(lg n) worst case.
|
|---|
| 42 | Insert: O(2) amortized. O(1) actual.
|
|---|
| 43 | Union: O(1) amortized. O(1) actual. */
|
|---|
| 44 |
|
|---|
| 45 | #ifndef _FIBHEAP_H_
|
|---|
| 46 | #define _FIBHEAP_H_
|
|---|
| 47 |
|
|---|
| 48 | #include <ansidecl.h>
|
|---|
| 49 |
|
|---|
| 50 | typedef long fibheapkey_t;
|
|---|
| 51 |
|
|---|
| 52 | typedef struct fibheap
|
|---|
| 53 | {
|
|---|
| 54 | size_t nodes;
|
|---|
| 55 | struct fibnode *min;
|
|---|
| 56 | struct fibnode *root;
|
|---|
| 57 | } *fibheap_t;
|
|---|
| 58 |
|
|---|
| 59 | typedef struct fibnode
|
|---|
| 60 | {
|
|---|
| 61 | struct fibnode *parent;
|
|---|
| 62 | struct fibnode *child;
|
|---|
| 63 | struct fibnode *left;
|
|---|
| 64 | struct fibnode *right;
|
|---|
| 65 | fibheapkey_t key;
|
|---|
| 66 | void *data;
|
|---|
| 67 | unsigned int degree : 31;
|
|---|
| 68 | unsigned int mark : 1;
|
|---|
| 69 | } *fibnode_t;
|
|---|
| 70 |
|
|---|
| 71 | extern fibheap_t fibheap_new PARAMS ((void));
|
|---|
| 72 | extern fibnode_t fibheap_insert PARAMS ((fibheap_t, fibheapkey_t, void *));
|
|---|
| 73 | extern int fibheap_empty PARAMS ((fibheap_t));
|
|---|
| 74 | extern fibheapkey_t fibheap_min_key PARAMS ((fibheap_t));
|
|---|
| 75 | extern fibheapkey_t fibheap_replace_key PARAMS ((fibheap_t, fibnode_t,
|
|---|
| 76 | fibheapkey_t));
|
|---|
| 77 | extern void *fibheap_replace_key_data PARAMS ((fibheap_t, fibnode_t,
|
|---|
| 78 | fibheapkey_t, void *));
|
|---|
| 79 | extern void *fibheap_extract_min PARAMS ((fibheap_t));
|
|---|
| 80 | extern void *fibheap_min PARAMS ((fibheap_t));
|
|---|
| 81 | extern void *fibheap_replace_data PARAMS ((fibheap_t, fibnode_t, void *));
|
|---|
| 82 | extern void *fibheap_delete_node PARAMS ((fibheap_t, fibnode_t));
|
|---|
| 83 | extern void fibheap_delete PARAMS ((fibheap_t));
|
|---|
| 84 | extern fibheap_t fibheap_union PARAMS ((fibheap_t, fibheap_t));
|
|---|
| 85 |
|
|---|
| 86 | #endif /* _FIBHEAP_H_ */
|
|---|