]> git.ipfire.org Git - thirdparty/gcc.git/blame - include/fibheap.h
PR d/90651
[thirdparty/gcc.git] / include / fibheap.h
CommitLineData
522a00cd 1/* A Fibonacci heap datatype.
fbd26352 2 Copyright (C) 1998-2019 Free Software Foundation, Inc.
522a00cd 3 Contributed by Daniel Berlin (dan@cgsoftware.com).
4
59f59894 5This file is part of GCC.
522a00cd 6
59f59894 7GCC is free software; you can redistribute it and/or modify it
522a00cd 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
59f59894 12GCC is distributed in the hope that it will be useful, but
522a00cd 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
59f59894 18along with GCC; see the file COPYING. If not, write to
2f8ebb8e 19the Free Software Foundation, 51 Franklin Street - Fifth Floor,
20Boston, MA 02110-1301, USA. */
522a00cd 21
41653d01 22/* Fibonacci heaps are somewhat complex, but, there's an article in
23 DDJ that explains them pretty well:
522a00cd 24
25 http://www.ddj.com/articles/1997/9701/9701o/9701o.htm?topic=algoritms
26
41653d01 27 Introduction to algorithms by Corman and Rivest also goes over them.
522a00cd 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.
41653d01 38 Union: O(1) amortized. O(1) actual. */
522a00cd 39
40#ifndef _FIBHEAP_H_
41#define _FIBHEAP_H_
42
5f94337d 43#include "ansidecl.h"
522a00cd 44
74b36562 45#ifdef __cplusplus
46extern "C" {
47#endif
48
41653d01 49typedef long fibheapkey_t;
50
522a00cd 51typedef struct fibheap
52{
53 size_t nodes;
54 struct fibnode *min;
55 struct fibnode *root;
56} *fibheap_t;
41653d01 57
522a00cd 58typedef struct fibnode
59{
60 struct fibnode *parent;
61 struct fibnode *child;
62 struct fibnode *left;
63 struct fibnode *right;
522a00cd 64 fibheapkey_t key;
65 void *data;
4927c18d 66#if defined (__GNUC__) && (!defined (SIZEOF_INT) || SIZEOF_INT < 4)
199a2f4e 67 __extension__ unsigned long int degree : 31;
68 __extension__ unsigned long int mark : 1;
195309ab 69#else
41653d01 70 unsigned int degree : 31;
71 unsigned int mark : 1;
195309ab 72#endif
522a00cd 73} *fibnode_t;
74
8858115e 75extern fibheap_t fibheap_new (void);
76extern fibnode_t fibheap_insert (fibheap_t, fibheapkey_t, void *);
77extern int fibheap_empty (fibheap_t);
78extern fibheapkey_t fibheap_min_key (fibheap_t);
79extern fibheapkey_t fibheap_replace_key (fibheap_t, fibnode_t,
80 fibheapkey_t);
81extern void *fibheap_replace_key_data (fibheap_t, fibnode_t,
82 fibheapkey_t, void *);
83extern void *fibheap_extract_min (fibheap_t);
84extern void *fibheap_min (fibheap_t);
85extern void *fibheap_replace_data (fibheap_t, fibnode_t, void *);
86extern void *fibheap_delete_node (fibheap_t, fibnode_t);
87extern void fibheap_delete (fibheap_t);
88extern fibheap_t fibheap_union (fibheap_t, fibheap_t);
41653d01 89
74b36562 90#ifdef __cplusplus
91}
92#endif
93
522a00cd 94#endif /* _FIBHEAP_H_ */