home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_DEV08B.LHA / gerlib / libg++ / gperf / src / bool-array.cc next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  2.7 KB  |  100 lines

  1. /* Fast lookup table abstraction implemented as an Iteration Number Array
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  4.  
  5. This file is part of GNU GPERF.
  6.  
  7. GNU GPERF is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU GPERF is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU GPERF; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include <stdio.h>
  22. #include "options.h"
  23. #include "bool-array.h"
  24.  
  25. STORAGE_TYPE * Bool_Array::storage_array;
  26. STORAGE_TYPE Bool_Array::iteration_number;
  27. int Bool_Array::size;
  28.  
  29. /* Prints out debugging diagnostics. */
  30.  
  31. Bool_Array::~Bool_Array (void) 
  32. {
  33.   T (Trace t ("Bool_Array::~Bool_Array");)
  34.   if (option[DEBUG])
  35.     fprintf (stderr, "\ndumping boolean array information\n"
  36.              "size = %d\niteration number = %d\nend of array dump\n",
  37.              size, iteration_number);
  38. }
  39.  
  40. #ifndef __OPTIMIZE__
  41.  
  42. Bool_Array::Bool_Array (void)
  43. {
  44.   T (Trace t ("Bool_Array::Bool_Array");)
  45.   storage_array = 0;
  46.   iteration_number = size = 0;
  47. }
  48.  
  49. void
  50. Bool_Array::init (STORAGE_TYPE *buffer, STORAGE_TYPE s)
  51. {
  52.   T (Trace t ("Bool_Array::init");)
  53.   size             = s;
  54.   iteration_number = 1;
  55.   storage_array    = buffer;
  56.   memset (storage_array, 0, s * sizeof *storage_array);
  57.   if (option[DEBUG])
  58.     fprintf (stderr, "\nbool array size = %d, total bytes = %d\n",
  59.              size, size * sizeof *storage_array);
  60. }
  61.  
  62. int  
  63. Bool_Array::find (int index) 
  64. {
  65.   T (Trace t ("Bool_Array::find");)
  66.   if (storage_array[index] == iteration_number)
  67.     return 1;
  68.   else
  69.     {
  70.       storage_array[index] = iteration_number;
  71.       return 0;
  72.     }
  73. }
  74.  
  75. void 
  76. Bool_Array::reset (void)  
  77. {
  78.   T (Trace t ("Bool_Array::reset");)
  79.   /* If we wrap around it's time to zero things out again!  However, this only
  80.      occurs once about every 2^31 or 2^15 iterations, so it should probably
  81.      never happen! */
  82.  
  83.   if (++iteration_number == 0)
  84.     {
  85.       if (option[DEBUG])
  86.         {
  87.           fprintf (stderr, "(re-initializing bool_array)...");
  88.           fflush (stderr);
  89.         }
  90.       iteration_number = 1;
  91.       memset (storage_array, 0, size * sizeof *storage_array);
  92.       if (option[DEBUG])
  93.         {
  94.           fprintf (stderr, "done\n");
  95.           fflush (stderr);
  96.         }
  97.     }
  98. }
  99. #endif /* not defined __OPTIMIZE__ */
  100.