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