Debug swcsa
[SXSI/TextCollection.git] / BlockArray.h
index 99aff91..1ee30c1 100644 (file)
@@ -16,6 +16,8 @@ public:
        n = len;
        blockLength = blockLen;
        data = new ulong[n*blockLength/W +1];
+       for (ulong i = 0; i < n*blockLength/W +1; ++i)
+           data[i] = 0;
     }
     ~BlockArray() {
        delete [] data;
@@ -58,11 +60,8 @@ public:
         if (std::fwrite(&(this->blockLength), sizeof(ulong), 1, file) != 1)
             throw std::runtime_error("BlockArray::Save(): file write error (blockLength).");
     
-        for (ulong offset = 0; offset < n*blockLength/W+1; offset ++)
-        {
-            if (std::fwrite(this->data + offset, sizeof(ulong), 1, file) != 1)
-                throw std::runtime_error("BlockArray::Save(): file write error (data).");
-        }
+        if (std::fwrite(this->data, sizeof(ulong), n*blockLength/W+1, file) != n*blockLength/W+1)
+            throw std::runtime_error("BlockArray::Save(): file write error (data).");
     }
 
     /**
@@ -76,11 +75,8 @@ public:
             throw std::runtime_error("BlockArray::Load(): file read error (blockLength).");
 
         data = new ulong[n*blockLength/W+1];
-        for (ulong offset = 0; offset < n*blockLength/W+1; offset ++)
-        {
-            if (std::fread(this->data + offset, sizeof(ulong), 1, file) != 1)
-                throw std::runtime_error("BlockArray::Load(): file read error (data).");
-        }
+        if (std::fread(this->data, sizeof(ulong), n*blockLength/W+1, file) != n*blockLength/W+1)
+            throw std::runtime_error("BlockArray::Load(): file read error (data).");
     }
 };