bitmap.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: bitmap.h,v 1.1 1999/11/05 05:47:06 jgg Exp $
  4. /* ######################################################################
  5. Bitmap - A trivial class to implement an 1 bit per element boolean
  6. vector
  7. This is deliberately extremely light weight so that it is fast for
  8. the client.
  9. ##################################################################### */
  10. /*}}}*/
  11. #ifndef DSYNC_BITMAP
  12. #define DSYNC_BITMAP
  13. #ifdef __GNUG__
  14. #pragma interface "dsync/bitmap.h"
  15. #endif
  16. class BitmapVector
  17. {
  18. unsigned long *Vect;
  19. unsigned long Size;
  20. #define BITMAPVECTOR_SIZE sizeof(unsigned long)*8
  21. // Compute the necessary size of the vector in bytes.
  22. inline unsigned Bytes() {return (Size + BITMAPVECTOR_SIZE - 1)/BITMAPVECTOR_SIZE;};
  23. public:
  24. inline void Set(unsigned long Elm)
  25. {Vect[Elm/BITMAPVECTOR_SIZE] |= 1 << (Elm%BITMAPVECTOR_SIZE);};
  26. inline bool Get(unsigned long Elm)
  27. {return (Vect[Elm/BITMAPVECTOR_SIZE] & (1 << (Elm%BITMAPVECTOR_SIZE))) != 0;};
  28. inline void Set(unsigned long Elm,bool To)
  29. {
  30. if (To)
  31. Vect[Elm/BITMAPVECTOR_SIZE] |= 1 << (Elm%BITMAPVECTOR_SIZE);
  32. else
  33. Vect[Elm/BITMAPVECTOR_SIZE] &= ~(1 << (Elm%BITMAPVECTOR_SIZE));
  34. };
  35. BitmapVector(unsigned long Size);
  36. ~BitmapVector();
  37. };
  38. #endif