bit_array.h

Go to the documentation of this file.
00001 #ifndef _PFC_BIT_ARRAY_H_
00002 #define _PFC_BIT_ARRAY_H_
00003 
00004 class NOVTABLE bit_array {
00005 public:
00006         virtual bool get(t_size n) const = 0;
00007         virtual t_size find(bool val,t_size start,t_ssize count) const//can be overridden for improved speed; returns first occurance of val between start and start+count (excluding start+count), or start+count if not found; count may be negative if we're searching back
00008         {
00009                 t_ssize d, todo, ptr = start;
00010                 if (count==0) return start;
00011                 else if (count<0) {d = -1; todo = -count;}
00012                 else {d = 1; todo = count;}
00013                 while(todo>0 && get(ptr)!=val) {ptr+=d;todo--;}
00014                 return ptr;
00015         }
00016         inline bool operator[](t_size n) const {return get(n);}
00017 
00018         t_size calc_count(bool val,t_size start,t_size count,t_size count_max = ~0) const//counts number of vals for start<=n<start+count
00019         {
00020                 t_size found = 0;
00021                 t_size max = start+count;
00022                 t_size ptr;
00023                 for(ptr=find(val,start,count);found<count_max && ptr<max;ptr=find(val,ptr+1,max-ptr-1)) found++;
00024                 return found;
00025         }
00026 
00027         inline t_size find_first(bool val,t_size start,t_size max) const {return find(val,start,max-start);}
00028         inline t_size find_next(bool val,t_size previous,t_size max) const {return find(val,previous+1,max-(previous+1));}
00029         //for(n = mask.find_first(true,0,m); n < m; n = mask.find_next(true,n,m) )
00030 protected:
00031         bit_array() {}
00032         ~bit_array() {}
00033 };
00034 
00035 class NOVTABLE bit_array_var : public bit_array {
00036 public:
00037         virtual void set(t_size n,bool val)=0;
00038 protected:
00039         bit_array_var() {}
00040         ~bit_array_var() {}
00041 };
00042 
00043 
00044 class bit_array_wrapper_permutation : public bit_array {
00045 public:
00046         bit_array_wrapper_permutation(const t_size * p_permutation, t_size p_size) : m_permutation(p_permutation), m_size(p_size) {}
00047         bool get(t_size n) const {
00048                 if (n < m_size) {
00049                         return m_permutation[n] != n;
00050                 } else {
00051                         return false;
00052                 }
00053         }
00054 private:
00055         const t_size * const m_permutation;
00056         const t_size m_size;
00057 };
00058 
00059 #endif

Generated on Fri Apr 25 18:49:36 2008 for foobar2000 SDK by  doxygen 1.5.5