1 /* A Fibonacci heap datatype.
2 Copyright (C) 1998-2022 Free Software Foundation, Inc.
3 Contributed by Daniel Berlin (dan@cgsoftware.com).
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
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)
12 GCC is distributed in the hope that it will be useful, but
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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Fibonacci heaps are somewhat complex, but, there's an article in
23 DDJ that explains them pretty well:
25 http://www.ddj.com/articles/1997/9701/9701o/9701o.htm?topic=algoritms
27 Introduction to algorithms by Corman and Rivest also goes over them.
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).
33 Amortized and real worst case time for operations:
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.
38 Union: O(1) amortized. O(1) actual. */
49 typedef long fibheapkey_t
;
51 typedef struct fibheap
58 typedef struct fibnode
60 struct fibnode
*parent
;
61 struct fibnode
*child
;
63 struct fibnode
*right
;
66 #if defined (__GNUC__) && (!defined (SIZEOF_INT) || SIZEOF_INT < 4)
67 __extension__
unsigned long int degree
: 31;
68 __extension__
unsigned long int mark
: 1;
70 unsigned int degree
: 31;
71 unsigned int mark
: 1;
75 extern fibheap_t
fibheap_new (void);
76 extern fibnode_t
fibheap_insert (fibheap_t
, fibheapkey_t
, void *);
77 extern int fibheap_empty (fibheap_t
);
78 extern fibheapkey_t
fibheap_min_key (fibheap_t
);
79 extern fibheapkey_t
fibheap_replace_key (fibheap_t
, fibnode_t
,
81 extern void *fibheap_replace_key_data (fibheap_t
, fibnode_t
,
82 fibheapkey_t
, void *);
83 extern void *fibheap_extract_min (fibheap_t
);
84 extern void *fibheap_min (fibheap_t
);
85 extern void *fibheap_replace_data (fibheap_t
, fibnode_t
, void *);
86 extern void *fibheap_delete_node (fibheap_t
, fibnode_t
);
87 extern void fibheap_delete (fibheap_t
);
88 extern fibheap_t
fibheap_union (fibheap_t
, fibheap_t
);
94 #endif /* _FIBHEAP_H_ */