source: trunk/src/opengl/glu/tess/priorityq-heap.h

Last change on this file was 2689, checked in by jeroen, 26 years ago

* empty log message *

File size: 4.5 KB
Line 
1/* $Id: priorityq-heap.h,v 1.1 2000-02-09 08:47:36 jeroen Exp $ */
2/*
3** License Applicability. Except to the extent portions of this file are
4** made subject to an alternative license as permitted in the SGI Free
5** Software License B, Version 1.0 (the "License"), the contents of this
6** file are subject only to the provisions of the License. You may not use
7** this file except in compliance with the License. You may obtain a copy
8** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10**
11** http://oss.sgi.com/projects/FreeB
12**
13** Note that, as provided in the License, the Software is distributed on an
14** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18**
19** Original Code. The Original Code is: OpenGL Sample Implementation,
20** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22** Copyright in any portions created by third parties is as indicated
23** elsewhere herein. All Rights Reserved.
24**
25** Additional Notice Provisions: The application programming interfaces
26** established by SGI in conjunction with the Original Code are The
27** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30** Window System(R) (Version 1.3), released October 19, 1998. This software
31** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32** published by SGI, but has not been independently verified as being
33** compliant with the OpenGL(R) version 1.2.1 Specification.
34**
35*/
36/*
37** Author: Eric Veach, July 1994.
38**
39** $Date: 2000-02-09 08:47:36 $ $Revision: 1.1 $
40** $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/tess/priorityq-heap.h,v 1.1 2000-02-09 08:47:36 jeroen Exp $
41*/
42
43#ifndef __priorityq_heap_h_
44#define __priorityq_heap_h_
45
46/* Use #define's so that another heap implementation can use this one */
47
48#define PQkey PQHeapKey
49#define PQhandle PQHeapHandle
50#define PriorityQ PriorityQHeap
51
52#define pqNewPriorityQ(leq) __gl_pqHeapNewPriorityQ(leq)
53#define pqDeletePriorityQ(pq) __gl_pqHeapDeletePriorityQ(pq)
54
55/* The basic operations are insertion of a new key (pqInsert),
56 * and examination/extraction of a key whose value is minimum
57 * (pqMinimum/pqExtractMin). Deletion is also allowed (pqDelete);
58 * for this purpose pqInsert returns a "handle" which is supplied
59 * as the argument.
60 *
61 * An initial heap may be created efficiently by calling pqInsert
62 * repeatedly, then calling pqInit. In any case pqInit must be called
63 * before any operations other than pqInsert are used.
64 *
65 * If the heap is empty, pqMinimum/pqExtractMin will return a NULL key.
66 * This may also be tested with pqIsEmpty.
67 */
68#define pqInit(pq) __gl_pqHeapInit(pq)
69#define pqInsert(pq,key) __gl_pqHeapInsert(pq,key)
70#define pqMinimum(pq) __gl_pqHeapMinimum(pq)
71#define pqExtractMin(pq) __gl_pqHeapExtractMin(pq)
72#define pqDelete(pq,handle) __gl_pqHeapDelete(pq,handle)
73#define pqIsEmpty(pq) __gl_pqHeapIsEmpty(pq)
74
75
76/* Since we support deletion the data structure is a little more
77 * complicated than an ordinary heap. "nodes" is the heap itself;
78 * active nodes are stored in the range 1..pq->size. When the
79 * heap exceeds its allocated size (pq->max), its size doubles.
80 * The children of node i are nodes 2i and 2i+1.
81 *
82 * Each node stores an index into an array "handles". Each handle
83 * stores a key, plus a pointer back to the node which currently
84 * represents that key (ie. nodes[handles[i].node].handle == i).
85 */
86
87typedef void *PQkey;
88typedef long PQhandle;
89typedef struct PriorityQ PriorityQ;
90
91typedef struct { PQhandle handle; } PQnode;
92typedef struct { PQkey key; PQhandle node; } PQhandleElem;
93
94struct PriorityQ {
95 PQnode *nodes;
96 PQhandleElem *handles;
97 long size, max;
98 PQhandle freeList;
99 int initialized;
100 int (*leq)(PQkey key1, PQkey key2);
101};
102
103PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) );
104void pqDeletePriorityQ( PriorityQ *pq );
105
106void pqInit( PriorityQ *pq );
107PQhandle pqInsert( PriorityQ *pq, PQkey key );
108PQkey pqExtractMin( PriorityQ *pq );
109void pqDelete( PriorityQ *pq, PQhandle handle );
110
111
112#define __gl_pqHeapMinimum(pq) ((pq)->handles[(pq)->nodes[1].handle].key)
113#define __gl_pqHeapIsEmpty(pq) ((pq)->size == 0)
114
115#endif
Note: See TracBrowser for help on using the repository browser.