12a6b7db3Sskrll /* A Fibonacci heap datatype. 2*cb63e24eSchristos Copyright (C) 1998-2024 Free Software Foundation, Inc. 32a6b7db3Sskrll Contributed by Daniel Berlin (dan@cgsoftware.com). 42a6b7db3Sskrll 52a6b7db3Sskrll This file is part of GCC. 62a6b7db3Sskrll 72a6b7db3Sskrll GCC is free software; you can redistribute it and/or modify it 82a6b7db3Sskrll under the terms of the GNU General Public License as published by 92a6b7db3Sskrll the Free Software Foundation; either version 2, or (at your option) 102a6b7db3Sskrll any later version. 112a6b7db3Sskrll 122a6b7db3Sskrll GCC is distributed in the hope that it will be useful, but 132a6b7db3Sskrll WITHOUT ANY WARRANTY; without even the implied warranty of 142a6b7db3Sskrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 152a6b7db3Sskrll General Public License for more details. 162a6b7db3Sskrll 172a6b7db3Sskrll You should have received a copy of the GNU General Public License 182a6b7db3Sskrll along with GCC; see the file COPYING. If not, write to 192a6b7db3Sskrll the Free Software Foundation, 51 Franklin Street - Fifth Floor, 202a6b7db3Sskrll Boston, MA 02110-1301, USA. */ 212a6b7db3Sskrll 222a6b7db3Sskrll /* Fibonacci heaps are somewhat complex, but, there's an article in 232a6b7db3Sskrll DDJ that explains them pretty well: 242a6b7db3Sskrll 252a6b7db3Sskrll http://www.ddj.com/articles/1997/9701/9701o/9701o.htm?topic=algoritms 262a6b7db3Sskrll 272a6b7db3Sskrll Introduction to algorithms by Corman and Rivest also goes over them. 282a6b7db3Sskrll 292a6b7db3Sskrll The original paper that introduced them is "Fibonacci heaps and their 302a6b7db3Sskrll uses in improved network optimization algorithms" by Tarjan and 312a6b7db3Sskrll Fredman (JACM 34(3), July 1987). 322a6b7db3Sskrll 332a6b7db3Sskrll Amortized and real worst case time for operations: 342a6b7db3Sskrll 352a6b7db3Sskrll ExtractMin: O(lg n) amortized. O(n) worst case. 362a6b7db3Sskrll DecreaseKey: O(1) amortized. O(lg n) worst case. 372a6b7db3Sskrll Insert: O(2) amortized. O(1) actual. 382a6b7db3Sskrll Union: O(1) amortized. O(1) actual. */ 392a6b7db3Sskrll 402a6b7db3Sskrll #ifndef _FIBHEAP_H_ 412a6b7db3Sskrll #define _FIBHEAP_H_ 422a6b7db3Sskrll 432a6b7db3Sskrll #include "ansidecl.h" 442a6b7db3Sskrll 4545548106Schristos #ifdef __cplusplus 4645548106Schristos extern "C" { 4745548106Schristos #endif 4845548106Schristos 492a6b7db3Sskrll typedef long fibheapkey_t; 502a6b7db3Sskrll 512a6b7db3Sskrll typedef struct fibheap 522a6b7db3Sskrll { 532a6b7db3Sskrll size_t nodes; 542a6b7db3Sskrll struct fibnode *min; 552a6b7db3Sskrll struct fibnode *root; 562a6b7db3Sskrll } *fibheap_t; 572a6b7db3Sskrll 582a6b7db3Sskrll typedef struct fibnode 592a6b7db3Sskrll { 602a6b7db3Sskrll struct fibnode *parent; 612a6b7db3Sskrll struct fibnode *child; 622a6b7db3Sskrll struct fibnode *left; 632a6b7db3Sskrll struct fibnode *right; 642a6b7db3Sskrll fibheapkey_t key; 652a6b7db3Sskrll void *data; 662a6b7db3Sskrll #if defined (__GNUC__) && (!defined (SIZEOF_INT) || SIZEOF_INT < 4) 672a6b7db3Sskrll __extension__ unsigned long int degree : 31; 682a6b7db3Sskrll __extension__ unsigned long int mark : 1; 692a6b7db3Sskrll #else 702a6b7db3Sskrll unsigned int degree : 31; 712a6b7db3Sskrll unsigned int mark : 1; 722a6b7db3Sskrll #endif 732a6b7db3Sskrll } *fibnode_t; 742a6b7db3Sskrll 752a6b7db3Sskrll extern fibheap_t fibheap_new (void); 762a6b7db3Sskrll extern fibnode_t fibheap_insert (fibheap_t, fibheapkey_t, void *); 772a6b7db3Sskrll extern int fibheap_empty (fibheap_t); 782a6b7db3Sskrll extern fibheapkey_t fibheap_min_key (fibheap_t); 792a6b7db3Sskrll extern fibheapkey_t fibheap_replace_key (fibheap_t, fibnode_t, 802a6b7db3Sskrll fibheapkey_t); 812a6b7db3Sskrll extern void *fibheap_replace_key_data (fibheap_t, fibnode_t, 822a6b7db3Sskrll fibheapkey_t, void *); 832a6b7db3Sskrll extern void *fibheap_extract_min (fibheap_t); 842a6b7db3Sskrll extern void *fibheap_min (fibheap_t); 852a6b7db3Sskrll extern void *fibheap_replace_data (fibheap_t, fibnode_t, void *); 862a6b7db3Sskrll extern void *fibheap_delete_node (fibheap_t, fibnode_t); 872a6b7db3Sskrll extern void fibheap_delete (fibheap_t); 882a6b7db3Sskrll extern fibheap_t fibheap_union (fibheap_t, fibheap_t); 892a6b7db3Sskrll 9045548106Schristos #ifdef __cplusplus 9145548106Schristos } 9245548106Schristos #endif 9345548106Schristos 942a6b7db3Sskrll #endif /* _FIBHEAP_H_ */ 95