2 * Collection of basic tools and defines
9 time_t Tools::startTime;
11 void Tools::StartTimer()
13 startTime = time(NULL);
16 double Tools::GetTime()
18 time_t stopTime = time(NULL);
19 return difftime( stopTime, startTime );
22 uchar * Tools::GetRandomString(unsigned min, unsigned max, unsigned &alphabetSize)
24 unsigned len = std::rand() % (max - min) + min;
25 alphabetSize = std::rand() % 26 + 1;
26 uchar* temp = new uchar[len + 2];
27 for (unsigned i = 0; i < len; i++)
28 temp[i] = 97 + std::rand() % alphabetSize;
29 temp[len] = 0u ;temp[len+1] = '\0';
34 void Tools::PrintBitSequence(ulong *A, ulong len)
36 for(ulong i = 0; i < len; i++)
37 if (GetField(A, 1, i))
44 unsigned Tools::FloorLog2(ulong i)
57 unsigned Tools::CeilLog2(ulong i)
59 unsigned j = FloorLog2(i);
60 if ((ulong)(1lu << j) != i)
66 uchar * Tools::GetFileContents(char *filename, ulong maxSize)
68 std::ifstream::pos_type posSize;
69 std::ifstream file ((char *)filename, std::ios::in|std::ios::binary|std::ios::ate);
72 posSize = file.tellg();
74 if (maxSize != 0 && size > maxSize)
76 char *memblock = new char [size + 1];
77 file.seekg (0, std::ios::beg);
78 file.read (memblock, size);
79 memblock[size] = '\0';
81 return (uchar *)memblock;
87 unsigned Tools::bits (ulong n)