I will probably use this bit array to store my extended arithmetic numbers for mesh generator, and as a flags container for finite elements properties.

And maybe for iterative corrections of large systems of linear equations.

The problem is that this will be the adaptive mesh for largre tasks (millions of nodes) in partial differential eqs. Now I am playing with different things

just to see possibilities it gives, etc. I needed to have my bitarray as small as possible and as fast as possible. I'm not saying I've done it better

than programming-artists like You gyus or Creators of STL or BOOST, but the thing is that I really need to have absolute control over this project.

I cannot afford to finally find a bug for solving which I will have to wait until next release of some library. That happend to me once

and I almost lost my job. So if it is possible I prefer to use my own code - not so efficient and well made but easy to modify etc.

And the second thing is that I am just learning, and trying to do some things.

to GDNet+: I have wrapped it in class and I will use some of the tips You wrote. However now I am just trying to make a quite good bit array :]

Thank You guys very very much for Your help :]

PS.: If someone wishes to see that class (unfinished yet) I paste it here:

#ifndef TBITARRAY_H_INCLUDED
#define TBITARRAY_H_INCLUDED
#include <stdlib.h>
#include <string>
class TBitArray
{
class TEightBits; //internal class implementing a byte with access to every bit
private:
TEightBits* Bits;
unsigned int BitsNumber; //number of bits
public:
inline TBitArray() //constructor
{
BitsNumber=0;
Bits=NULL;
}
inline TBitArray(unsigned int NumOfBits) //meritorical nonstructor
{
int NumOfBytes=NumOfBits/8; //jesli NumOfBits nie miesci sie w calkowitej liczbie bajtow
if (NumOfBits%8>0) NumOfBytes++; //trzeba zwiekszyc o 1 liczbe bajtow
BitsNumber=0;
Bits=NULL;
Bits=new TEightBits[NumOfBytes];
BitsNumber=NumOfBits;
}
inline ~TBitArray()
{
BitsNumber=0;
delete[] Bits;
Bits=NULL;
}
inline unsigned int GetNumberOfBytes(void)
{
unsigned int NumOfBytes=BitsNumber/8;
if (BitsNumber%8>0) NumOfBytes++;
return NumOfBytes;
}
inline bool GetBit(unsigned int BitPos)
{
return Bits[BitPos/8].GetBit(BitPos%8);
}
inline void SetBit(bool Bit,unsigned int BitPos)
{
Bits[BitPos/8].SetBit(Bit,BitPos%8);
}
inline void Resize(unsigned int NewSizeInBits)
{
unsigned int NewNumOfBytes=NewSizeInBits/8,
NumOfBytes=BitsNumber/8;
if (NewSizeInBits%8>0) NewNumOfBytes++;
if (BitsNumber%8>0) NumOfBytes++;
if (NewNumOfBytes!=NumOfBytes) //dodac dodatkowe warunki
{
TEightBits *tmp=new TEightBits[NewNumOfBytes];
std::copy(Bits,Bits+Min(NewNumOfBytes,NumOfBytes),tmp); //a faster stuff
delete[] Bits;
Bits=tmp;
BitsNumber=NewSizeInBits;
}
}
inline void Copy(const TBitArray& that)
{
unsigned int NewNumOfBytes=that.BitsNumber/8,
NumOfBytes=BitsNumber/8;
if (that.BitsNumber%8>0) NewNumOfBytes++;
if (BitsNumber%8>0) NumOfBytes++;
if (NewNumOfBytes!=NumOfBytes)
{
delete[] Bits;
Bits=NULL;
Bits=new TEightBits[NewNumOfBytes];
}
std::copy(that.Bits,that.Bits+NewNumOfBytes,Bits);
BitsNumber=that.BitsNumber;
}
inline unsigned int SizeInBytes(void)
{
unsigned int NumOfBytes=BitsNumber/8;
if (BitsNumber%8>0) NumOfBytes++;
return NumOfBytes;
}
inline void Negation(void)
{
for (unsigned int i=0;i<SizeInBytes();i++) Bits[i].Negation();
}
inline void IncByLastBit(void)
{
}
inline void IncByFirstBit(void)
{
}
std::string ToString(void)
{
std::string RetStr(BitsNumber,'0');
for (unsigned int i=0;i<BitsNumber;i++) if(GetBit(i))RetStr[i]='1';
return RetStr;
}
private:
inline unsigned int Min(unsigned int a,unsigned int b)
{
if(a<b) return a; else return b;
}
class TEightBits //internal class implementing a byte with access to every bit
{
private:
unsigned char bits;
public:
TEightBits()
{
bits=0;
}
inline bool GetBit(unsigned short BitPos)
{
return (bits & (1 << BitPos));
}
inline void SetBit(bool Bit, unsigned short BitPos)
{
bits |= Bit << BitPos;
}
inline void NegationBit(unsigned int BitPos)
{
bits ^= 1 << BitPos;
}
inline unsigned int ElementSize(void) const
{
return 8; //bits
}
inline void Negation(void)
{
bits=~bits;
}
inline void operator = (const TEightBits &Byte)
{
bits=Byte.bits;
}
/*
//operators
inline bool operator == (const TEightBits &Byte)
{
return (bits==Byte.bits);
}
inline bool operator != (const TEightBits &Byte)
{
return (bits!=Byte.bits);
}
inline bool operator >= (const TEightBits &Byte)
{
return (bits>=Byte.bits);
}
inline bool operator <= (const TEightBits &Byte)
{
return (bits<=Byte.bits);
}
inline bool operator > (const TEightBits &Byte)
{
return (bits>Byte.bits);
}
inline bool operator < (const TEightBits &Byte)
{
return (bits<Byte.bits);
}
*/
};
};
#endif // TBITARRAY_H_INCLUDED