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];
19 for (ulong i = 0; i < n*blockLength/W +1; ++i)
26 BlockArray& operator[](ulong i) {
31 void operator=(const ulong x) {
32 Tools::SetField(data,blockLength,index,x);
35 BlockArray& operator=(const BlockArray& ba) {
36 if (this == &ba) return *this;
37 ulong value = Tools::GetField(ba.data, ba.blockLength, ba.index);
38 Tools::SetField(data,blockLength,index,value);
43 return Tools::GetField(data,blockLength,index);
47 return n*blockLength+W; // plus 4 ulong's
56 void Save(FILE *file) const
58 if (std::fwrite(&(this->n), sizeof(ulong), 1, file) != 1)
59 throw std::runtime_error("BlockArray::Save(): file write error (n).");
60 if (std::fwrite(&(this->blockLength), sizeof(ulong), 1, file) != 1)
61 throw std::runtime_error("BlockArray::Save(): file write error (blockLength).");
63 for (ulong offset = 0; offset < n*blockLength/W+1; offset ++)
65 if (std::fwrite(this->data + offset, sizeof(ulong), 1, file) != 1)
66 throw std::runtime_error("BlockArray::Save(): file write error (data).");
73 BlockArray(FILE *file)
75 if (std::fread(&(this->n), sizeof(ulong), 1, file) != 1)
76 throw std::runtime_error("BlockArray::Load(): file read error (n).");
77 if (std::fread(&(this->blockLength), sizeof(ulong), 1, file) != 1)
78 throw std::runtime_error("BlockArray::Load(): file read error (blockLength).");
80 data = new ulong[n*blockLength/W+1];
81 for (ulong offset = 0; offset < n*blockLength/W+1; offset ++)
83 if (std::fread(this->data + offset, sizeof(ulong), 1, file) != 1)
84 throw std::runtime_error("BlockArray::Load(): file read error (data).");