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