added new file
[SXSI/TextCollection.git] / BlockArray.h
1 #ifndef _BLOCK_ARRAY_H_
2 #define _BLOCK_ARRAY_H_
3 #include <iostream>
4 #include "Tools.h"
5
6 class BlockArray
7 {
8 private:
9     ulong* data;
10     ulong n;
11     ulong index;
12     ulong blockLength;
13 public:
14     BlockArray(ulong len, ulong blockLen) {
15        n = len;
16        blockLength = blockLen;
17        data = new ulong[n*blockLength/W +1];
18     }
19     ~BlockArray() {
20        delete [] data;
21     }
22
23     BlockArray& operator[](ulong i)  {
24        index = i;
25        return *this;
26     }  
27
28     void operator=(const ulong x) {
29        Tools::SetField(data,blockLength,index,x);
30     }  
31
32     BlockArray& operator=(const BlockArray& ba) {
33        if (this == &ba) return *this;
34        ulong value = Tools::GetField(ba.data, ba.blockLength, ba.index);
35        Tools::SetField(data,blockLength,index,value);
36        return *this;
37     }  
38         
39     operator ulong() {
40        return Tools::GetField(data,blockLength,index);
41     }
42     
43     ulong spaceInBits() {
44         return n*blockLength+W; // plus 4 ulong's
45     }
46     
47 };
48
49 #endif
50