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