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