Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
priority_queue.h
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00260 #ifndef prq_INCLUDED
00261 #define prq_INCLUDED
00262 #ifdef __cplusplus
00263 extern "C" {
00264 #endif
00265 
00266 #ifdef _KEEP_RCS_ID
00267 #ifndef PRQ_RCS_ID
00268 #define PRQ_RCS_ID
00269 #endif
00270 #endif
00271 
00272 #include "defs.h"
00273 
00274 struct mem_pool;
00275 
00276 typedef BOOL  (*PRQ_COMPARISON_FUNCTION) (void*,void*);
00277 typedef INT32 (*PRQ_GET_INDEX_FUNCTION)(void*);
00278 typedef void (*PRQ_SET_INDEX_FUNCTION)(void*,INT);
00279 typedef void (*PRQ_ELEMENT_PRINT_FUNCTION)(void*);
00280 
00281 typedef struct prq {
00286     PRQ_COMPARISON_FUNCTION comparison_fn;
00287                     /*  Function used to compare keys.
00288                      */
00289     struct mem_pool* mem_pool;
00290                     /* Where to [re]allocate
00291                      */
00292     INT32 size;
00293                     /*  Number of elements in the heap.
00294                      */
00295     INT32 allocated_size;
00296                     /*  Number of elements 'heap_vector' can hold.
00297                      */
00298 
00299     INT32 expansion_factor;
00300                     /*  Amount to grow heap.
00301                      */
00302 
00303     PRQ_GET_INDEX_FUNCTION get_index_fn;
00304     PRQ_SET_INDEX_FUNCTION set_index_fn;
00305                     /*  Functions to get/set the index of a heap element.
00306                      */
00307 
00308     void** heap_vector;
00309                     /*  The vector used to hold the heap elements.  It is
00310                      *  dynamically allocated.  It is a standard C 0-origin
00311                      *  vector.  Access utilities are used to map the 1-origin
00312                      *  indexing used by the heap algorithms onto the 0-origin
00313                      *  'heap_vector'.
00314                      */
00315 } PRQ;
00316 
00317 
00318 extern void
00319 PRQ_Initialize(
00320     PRQ*                    prq,
00321     PRQ_COMPARISON_FUNCTION comparison_fn,
00322     PRQ_GET_INDEX_FUNCTION  get_fn,
00323     PRQ_SET_INDEX_FUNCTION  set_fn,
00324     MEM_POOL*               pool,
00325     INT32                   initial_size,
00326     INT32                   expansion_factor
00327 );
00328 
00329 extern void*
00330 PRQ_Delete_Top(
00331     PRQ*    prq
00332 );
00333 
00334 extern void*
00335 PRQ_Top(
00336     PRQ*    prq
00337 );
00338 
00339 extern void
00340 PRQ_Insert(
00341     PRQ*    prq,
00342     void*   element
00343 );
00344 
00345 extern void
00346 PRQ_Remove(
00347     PRQ*    prq,
00348     void*   element
00349 );
00350 
00351 extern void
00352 PRQ_Reset(
00353     PRQ*    prq
00354 );
00355 
00356 extern INT32
00357 PRQ_Size(
00358     PRQ*    prq
00359 );
00360 
00361 extern void*
00362 PRQ_Ith(
00363     PRQ*    prq,
00364     INT32   i
00365 );
00366 
00367 
00368 /* Look Ma, no templates!
00369  */
00370 
00371 /* Generate the names used in the typesafe interface and invoke the low
00372  * level interface generation macro:
00373  */
00374 #define TYPE_PRQ(base_type,prq_type)                                    \
00375     _TYPE_PRQ(base_type,                                                \
00376               prq_type,                                                 \
00377               prq_type##_COMPARISON_FUNCTION,                           \
00378               prq_type##_GET_INDEX_FUNCTION,                            \
00379               prq_type##_SET_INDEX_FUNCTION,                            \
00380               prq_type##_Initialize,                                    \
00381               prq_type##_Delete_Top,                                    \
00382               prq_type##_Top,                                           \
00383               prq_type##_Insert,                                        \
00384               prq_type##_Remove,                                        \
00385               prq_type##_Reset,                                         \
00386               prq_type##_Size,                                          \
00387               prq_type##_Ith)
00388 
00389 
00390 /* Actually generate the typesafe interface:
00391  */
00392 #define _TYPE_PRQ(base_type,                                            \
00393                   prq_type,                                             \
00394                   comparison_function_type,                             \
00395                   get_index_function_type,                              \
00396                   set_index_function_type,                              \
00397                   initialize_function_name,                             \
00398                   delete_top_function_name,                             \
00399                   top_function_name,                                    \
00400                   insert_function_name,                                 \
00401                   remove_function_name,                                 \
00402                   reset_function_name,                                  \
00403                   size_function_name,                                   \
00404                   ith_function_name)                                    \
00405                                                                         \
00406 typedef PRQ prq_type;                                                   \
00407                                                                         \
00408 typedef INT (*comparison_function_type)(base_type*,base_type*);         \
00409 typedef INT32 (*get_index_function_type)(base_type*);                   \
00410 typedef void (*set_index_function_type)(base_type*,INT32);              \
00411                                                                         \
00412 /*REFERENCED*/                                                          \
00413 inline base_type*                                                       \
00414 delete_top_function_name(                                               \
00415   prq_type* prq                                                         \
00416 )                                                                       \
00417 {                                                                       \
00418   return (base_type*) PRQ_Delete_Top((PRQ*) prq);                       \
00419 }                                                                       \
00420                                                                         \
00421 /*REFERENCED*/                                                          \
00422 inline base_type*                                                       \
00423 top_function_name(                                                      \
00424   prq_type* prq                                                         \
00425 )                                                                       \
00426 {                                                                       \
00427   return (base_type*) PRQ_Top((PRQ*) prq);                              \
00428 }                                                                       \
00429                                                                         \
00430 /*REFERENCED*/                                                          \
00431 inline void                                                             \
00432 insert_function_name(                                                   \
00433   prq_type*    prq,                                                     \
00434   base_type*   element                                                  \
00435 )                                                                       \
00436 {                                                                       \
00437   PRQ_Insert((PRQ*)prq,(void*)element);                                 \
00438 }                                                                       \
00439                                                                         \
00440 /*REFERENCED*/                                                          \
00441 inline void                                                             \
00442 remove_function_name(                                                   \
00443   prq_type*   prq,                                                      \
00444   base_type*  element                                                   \
00445 )                                                                       \
00446 {                                                                       \
00447   PRQ_Remove((PRQ*)prq,(void*)element);                                 \
00448 }                                                                       \
00449                                                                         \
00450 /*REFERENCED*/                                                          \
00451 inline void                                                             \
00452 reset_function_name(                                                    \
00453   prq_type* prq                                                         \
00454 )                                                                       \
00455 {                                                                       \
00456   PRQ_Reset((PRQ*)prq);                                                 \
00457 }                                                                       \
00458                                                                         \
00459 /*REFERENCED*/                                                          \
00460 inline INT32                                                            \
00461 size_function_name(                                                     \
00462   prq_type*   prq                                                       \
00463 )                                                                       \
00464 {                                                                       \
00465   return PRQ_Size((PRQ*)prq);                                           \
00466 }                                                                       \
00467                                                                         \
00468 /*REFERENCED*/                                                          \
00469 inline base_type*                                                       \
00470 ith_function_name(                                                      \
00471   prq_type* prq,                                                        \
00472   INT32     i                                                           \
00473 )                                                                       \
00474 {                                                                       \
00475   return (base_type*)PRQ_Ith((PRQ*)prq,i);                              \
00476 }                                                                       \
00477                                                                         \
00478 /*REFERENCED*/                                                          \
00479 inline void                                                             \
00480 initialize_function_name(                                               \
00481   prq_type*                 prq,                                        \
00482   comparison_function_type  comparison_fn,                              \
00483   get_index_function_type   get_index,                                  \
00484   set_index_function_type   set_index,                                  \
00485   MEM_POOL*                 pool,                                       \
00486   INT32                     initial_size,                               \
00487   INT32                     expansion_factor                            \
00488 )                                                                       \
00489 {                                                                       \
00490   PRQ_Initialize((PRQ*)prq,(PRQ_COMPARISON_FUNCTION)comparison_fn,      \
00491                            (PRQ_GET_INDEX_FUNCTION)get_index,           \
00492                            (PRQ_SET_INDEX_FUNCTION)set_index,           \
00493                            pool,                                        \
00494                            initial_size,                                \
00495                            expansion_factor);                           \
00496 }
00497 
00498 
00499 #ifdef __cplusplus
00500 }
00501 #endif
00502 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines