added new file
[SXSI/TextCollection.git] / BlockArray.h
diff --git a/BlockArray.h b/BlockArray.h
new file mode 100644 (file)
index 0000000..cc60c35
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef _BLOCK_ARRAY_H_
+#define _BLOCK_ARRAY_H_
+#include <iostream>
+#include "Tools.h"
+
+class BlockArray
+{
+private:
+    ulong* data;
+    ulong n;
+    ulong index;
+    ulong blockLength;
+public:
+    BlockArray(ulong len, ulong blockLen) {
+       n = len;
+       blockLength = blockLen;
+       data = new ulong[n*blockLength/W +1];
+    }
+    ~BlockArray() {
+       delete [] data;
+    }
+
+    BlockArray& operator[](ulong i)  {
+       index = i;
+       return *this;
+    }  
+
+    void operator=(const ulong x) {
+       Tools::SetField(data,blockLength,index,x);
+    }  
+
+    BlockArray& operator=(const BlockArray& ba) {
+       if (this == &ba) return *this;
+       ulong value = Tools::GetField(ba.data, ba.blockLength, ba.index);
+       Tools::SetField(data,blockLength,index,value);
+       return *this;
+    }  
+        
+    operator ulong() {
+       return Tools::GetField(data,blockLength,index);
+    }
+    
+    ulong spaceInBits() {
+        return n*blockLength+W; // plus 4 ulong's
+    }
+    
+};
+
+#endif
+