xref: /openbsd-src/gnu/lib/libiberty/include/fibheap.h (revision 20fce977aadac3358da45d5027d7d19cdc03b0fe)
19588ddcfSespie /* A Fibonacci heap datatype.
29588ddcfSespie    Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
39588ddcfSespie    Contributed by Daniel Berlin (dan@cgsoftware.com).
49588ddcfSespie 
59588ddcfSespie This file is part of GCC.
69588ddcfSespie 
79588ddcfSespie GCC is free software; you can redistribute it and/or modify it
89588ddcfSespie under the terms of the GNU General Public License as published by
99588ddcfSespie the Free Software Foundation; either version 2, or (at your option)
109588ddcfSespie any later version.
119588ddcfSespie 
129588ddcfSespie GCC is distributed in the hope that it will be useful, but
139588ddcfSespie WITHOUT ANY WARRANTY; without even the implied warranty of
149588ddcfSespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
159588ddcfSespie General Public License for more details.
169588ddcfSespie 
179588ddcfSespie You should have received a copy of the GNU General Public License
189588ddcfSespie along with GCC; see the file COPYING.  If not, write to
19*20fce977Smiod the Free Software Foundation, 51 Franklin Street - Fifth Floor,
20*20fce977Smiod Boston, MA 02110-1301, USA.  */
219588ddcfSespie 
229588ddcfSespie /* Fibonacci heaps are somewhat complex, but, there's an article in
239588ddcfSespie    DDJ that explains them pretty well:
249588ddcfSespie 
259588ddcfSespie    http://www.ddj.com/articles/1997/9701/9701o/9701o.htm?topic=algoritms
269588ddcfSespie 
279588ddcfSespie    Introduction to algorithms by Corman and Rivest also goes over them.
289588ddcfSespie 
299588ddcfSespie    The original paper that introduced them is "Fibonacci heaps and their
309588ddcfSespie    uses in improved network optimization algorithms" by Tarjan and
319588ddcfSespie    Fredman (JACM 34(3), July 1987).
329588ddcfSespie 
339588ddcfSespie    Amortized and real worst case time for operations:
349588ddcfSespie 
359588ddcfSespie    ExtractMin: O(lg n) amortized. O(n) worst case.
369588ddcfSespie    DecreaseKey: O(1) amortized.  O(lg n) worst case.
379588ddcfSespie    Insert: O(2) amortized. O(1) actual.
389588ddcfSespie    Union: O(1) amortized. O(1) actual.  */
399588ddcfSespie 
409588ddcfSespie #ifndef _FIBHEAP_H_
419588ddcfSespie #define _FIBHEAP_H_
429588ddcfSespie 
439588ddcfSespie #include "ansidecl.h"
449588ddcfSespie 
459588ddcfSespie typedef long fibheapkey_t;
469588ddcfSespie 
479588ddcfSespie typedef struct fibheap
489588ddcfSespie {
499588ddcfSespie   size_t nodes;
509588ddcfSespie   struct fibnode *min;
519588ddcfSespie   struct fibnode *root;
529588ddcfSespie } *fibheap_t;
539588ddcfSespie 
549588ddcfSespie typedef struct fibnode
559588ddcfSespie {
569588ddcfSespie   struct fibnode *parent;
579588ddcfSespie   struct fibnode *child;
589588ddcfSespie   struct fibnode *left;
599588ddcfSespie   struct fibnode *right;
609588ddcfSespie   fibheapkey_t key;
619588ddcfSespie   void *data;
62*20fce977Smiod #if defined (__GNUC__) && (!defined (SIZEOF_INT) || SIZEOF_INT < 4)
63*20fce977Smiod   __extension__ unsigned long int degree : 31;
64*20fce977Smiod   __extension__ unsigned long int mark : 1;
65*20fce977Smiod #else
669588ddcfSespie   unsigned int degree : 31;
679588ddcfSespie   unsigned int mark : 1;
68*20fce977Smiod #endif
699588ddcfSespie } *fibnode_t;
709588ddcfSespie 
71*20fce977Smiod extern fibheap_t fibheap_new (void);
72*20fce977Smiod extern fibnode_t fibheap_insert (fibheap_t, fibheapkey_t, void *);
73*20fce977Smiod extern int fibheap_empty (fibheap_t);
74*20fce977Smiod extern fibheapkey_t fibheap_min_key (fibheap_t);
75*20fce977Smiod extern fibheapkey_t fibheap_replace_key (fibheap_t, fibnode_t,
76*20fce977Smiod                                          fibheapkey_t);
77*20fce977Smiod extern void *fibheap_replace_key_data (fibheap_t, fibnode_t,
78*20fce977Smiod                                        fibheapkey_t, void *);
79*20fce977Smiod extern void *fibheap_extract_min (fibheap_t);
80*20fce977Smiod extern void *fibheap_min (fibheap_t);
81*20fce977Smiod extern void *fibheap_replace_data (fibheap_t, fibnode_t, void *);
82*20fce977Smiod extern void *fibheap_delete_node (fibheap_t, fibnode_t);
83*20fce977Smiod extern void fibheap_delete (fibheap_t);
84*20fce977Smiod extern fibheap_t fibheap_union (fibheap_t, fibheap_t);
859588ddcfSespie 
869588ddcfSespie #endif /* _FIBHEAP_H_ */
87