1 #ifndef _BLOCK_ARRAY_H_
2 #define _BLOCK_ARRAY_H_
15 BlockArray(ulong len, ulong blockLen) {
17 blockLength = blockLen;
18 data = new ulong[n*blockLength/W +1];
24 BlockArray& operator[](ulong i) {
29 void operator=(const ulong x) {
30 Tools::SetField(data,blockLength,index,x);
33 BlockArray& operator=(const BlockArray& ba) {
34 if (this == &ba) return *this;
35 ulong value = Tools::GetField(ba.data, ba.blockLength, ba.index);
36 Tools::SetField(data,blockLength,index,value);
41 return Tools::GetField(data,blockLength,index);
45 return n*blockLength+W; // plus 4 ulong's
54 void Save(FILE *file) const
56 if (std::fwrite(&(this->n), sizeof(ulong), 1, file) != 1)
57 throw std::runtime_error("BlockArray::Save(): file write error (n).");
58 if (std::fwrite(&(this->blockLength), sizeof(ulong), 1, file) != 1)
59 throw std::runtime_error("BlockArray::Save(): file write error (blockLength).");
61 for (ulong offset = 0; offset < n*blockLength/W+1; offset ++)
63 if (std::fwrite(this->data + offset, sizeof(ulong), 1, file) != 1)
64 throw std::runtime_error("BlockArray::Save(): file write error (data).");
71 BlockArray(FILE *file)
73 if (std::fread(&(this->n), sizeof(ulong), 1, file) != 1)
74 throw std::runtime_error("BlockArray::Load(): file read error (n).");
75 if (std::fread(&(this->blockLength), sizeof(ulong), 1, file) != 1)
76 throw std::runtime_error("BlockArray::Load(): file read error (blockLength).");
78 data = new ulong[n*blockLength/W+1];
79 for (ulong offset = 0; offset < n*blockLength/W+1; offset ++)
81 if (std::fread(this->data + offset, sizeof(ulong), 1, file) != 1)
82 throw std::runtime_error("BlockArray::Load(): file read error (data).");