X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=tools%2Fdsync-0.0%2Flibdsync%2Fcontrib%2Fbitmap.h;fp=tools%2Fdsync-0.0%2Flibdsync%2Fcontrib%2Fbitmap.h;h=9859673b65daa3cf0767111e7b97e0fd0550afd0;hb=824e90cf1466f3d62db08f27b865ef8e301a9ae9;hp=0000000000000000000000000000000000000000;hpb=f9d876eacbc4c4c5a57f862b8d3a46443aad5da7;p=dak.git diff --git a/tools/dsync-0.0/libdsync/contrib/bitmap.h b/tools/dsync-0.0/libdsync/contrib/bitmap.h new file mode 100644 index 00000000..9859673b --- /dev/null +++ b/tools/dsync-0.0/libdsync/contrib/bitmap.h @@ -0,0 +1,49 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: bitmap.h,v 1.1 1999/11/05 05:47:06 jgg Exp $ +/* ###################################################################### + + Bitmap - A trivial class to implement an 1 bit per element boolean + vector + + This is deliberately extremely light weight so that it is fast for + the client. + + ##################################################################### */ + /*}}}*/ +#ifndef DSYNC_BITMAP +#define DSYNC_BITMAP + +#ifdef __GNUG__ +#pragma interface "dsync/bitmap.h" +#endif + +class BitmapVector +{ + unsigned long *Vect; + unsigned long Size; + + #define BITMAPVECTOR_SIZE sizeof(unsigned long)*8 + + // Compute the necessary size of the vector in bytes. + inline unsigned Bytes() {return (Size + BITMAPVECTOR_SIZE - 1)/BITMAPVECTOR_SIZE;}; + + public: + + inline void Set(unsigned long Elm) + {Vect[Elm/BITMAPVECTOR_SIZE] |= 1 << (Elm%BITMAPVECTOR_SIZE);}; + inline bool Get(unsigned long Elm) + {return (Vect[Elm/BITMAPVECTOR_SIZE] & (1 << (Elm%BITMAPVECTOR_SIZE))) != 0;}; + inline void Set(unsigned long Elm,bool To) + { + if (To) + Vect[Elm/BITMAPVECTOR_SIZE] |= 1 << (Elm%BITMAPVECTOR_SIZE); + else + Vect[Elm/BITMAPVECTOR_SIZE] &= ~(1 << (Elm%BITMAPVECTOR_SIZE)); + }; + + BitmapVector(unsigned long Size); + ~BitmapVector(); +}; + +#endif