home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gperf.lzh / GPERF / BOOL-ARR.H < prev    next >
C/C++ Source or Header  |  1993-07-30  |  3KB  |  111 lines

  1. /* This may look like C code, but it is really -*- C++ -*- */
  2.  
  3. /* Simple lookup table abstraction implemented as an Iteration Number Array.
  4.  
  5.    Copyright (C) 1989 Free Software Foundation, Inc.
  6.    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  7.  
  8. This file is part of GNU GPERF.
  9.  
  10. GNU GPERF is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 1, or (at your option)
  13. any later version.
  14.  
  15. GNU GPERF is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. GNU General Public License for more details.
  19.  
  20. You should have received a copy of the GNU General Public License
  21. along with GNU GPERF; see the file COPYING.  If not, write to
  22. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  23.  
  24. /* Define and implement a simple boolean array abstraction,
  25.    uses an Iteration Numbering implementation to save on initialization time. */
  26.  
  27. #pragma once
  28. #include <std.h>
  29. #include "trace.h"
  30.  
  31. #ifdef LO_CAL
  32. /* If we are on a memory diet then we'll only make these use a limited
  33.    amount of storage space. */
  34. typedef unsigned short STORAGE_TYPE;
  35. #else
  36. typedef int STORAGE_TYPE;
  37. #endif
  38.  
  39. class Bool_Array 
  40. {
  41. private:
  42.   static STORAGE_TYPE *storage_array;    /* Initialization of the index space. */
  43.   static STORAGE_TYPE  iteration_number; /* Keep track of the current iteration. */
  44.   static int           size;             /* Keep track of array size. */
  45.  
  46. public:
  47.        Bool_Array (void);
  48.       ~Bool_Array (void);
  49.   static void init (STORAGE_TYPE *buffer, STORAGE_TYPE s);
  50.   static int  find (int hash_value);
  51.   static void reset (void);
  52. };
  53.  
  54. #ifdef __OPTIMIZE__  /* efficiency hack! */
  55.  
  56. inline 
  57. Bool_Array::Bool_Array (void)
  58. {
  59.   T (Trace t ("Bool_Array::Bool_Array");)
  60.   storage_array = 0;
  61.   iteration_number = size = 0;
  62. }
  63.  
  64. inline void
  65. Bool_Array::init (STORAGE_TYPE *buffer, STORAGE_TYPE s)
  66. {
  67.   T (Trace t ("Bool_Array::init");)
  68.   size             = s;
  69.   iteration_number = 1;
  70.   storage_array    = buffer;
  71.   bzero (storage_array, s * sizeof *storage_array);
  72.   if (option[DEBUG])
  73.     fprintf (stderr, "\nbool array size = %d, total bytes = %d\n",
  74.              size, size * sizeof *storage_array);
  75. }
  76.  
  77. inline int  
  78. Bool_Array::find (int index) 
  79. {
  80.   T (Trace t ("Bool_Array::find");)
  81.   if (storage_array[index] == iteration_number)
  82.     return 1;
  83.   else
  84.     {
  85.       storage_array[index] = iteration_number;
  86.       return 0;
  87.     }
  88. }
  89.  
  90. inline void 
  91. Bool_Array::reset (void) 
  92.   T (Trace t ("Bool_Array::reset");)
  93.   if (++iteration_number == 0)
  94.     {
  95.       if (option[DEBUG])
  96.         {
  97.           fprintf (stderr, "(re-initializing bool_array)...");
  98.           fflush (stderr);
  99.         }
  100.       iteration_number = 1;
  101.       bzero (storage_array, size * sizeof *storage_array);
  102.       if (option[DEBUG])
  103.         {
  104.           fprintf (stderr, "done\n");
  105.           fflush (stderr);
  106.         }
  107.     }
  108. }
  109. #endif
  110.