cfd2799d216ee7fde662f9aa01713413d1ab5d78
[SXSI/TextCollection.git] / incbwt / misc / utils.cpp
1 #include "utils.h"
2
3 #ifdef MULTITHREAD_SUPPORT
4 #include <omp.h>
5 #else
6 #include <cstdlib>
7 #endif
8
9
10 namespace CSA
11 {
12
13 //--------------------------------------------------------------------------
14
15 Triple::Triple() :
16   first(0), second(0), third(0)
17 {
18 }
19
20 Triple::Triple(usint a, usint b, usint c) :
21   first(a), second(b), third(c)
22 {
23 }
24
25 //--------------------------------------------------------------------------
26
27 std::streamoff
28 fileSize(std::ifstream& file)
29 {
30   std::streamoff curr = file.tellg();
31
32   file.seekg(0, std::ios::end);
33   std::streamoff size = file.tellg();
34   file.seekg(0, std::ios::beg);
35   size -= file.tellg();
36
37   file.seekg(curr, std::ios::beg);
38   return size;
39 }
40
41 std::streamoff
42 fileSize(std::ofstream& file)
43 {
44   std::streamoff curr = file.tellp();
45
46   file.seekp(0, std::ios::end);
47   std::streamoff size = file.tellp();
48   file.seekp(0, std::ios::beg);
49   size -= file.tellp();
50
51   file.seekp(curr, std::ios::beg);
52   return size;
53 }
54
55 std::ostream&
56 operator<<(std::ostream& stream, pair_type data)
57 {
58   return stream << "(" << data.first << ", " << data.second << ")";
59 }
60
61 void
62 readRows(std::ifstream& file, std::vector<std::string>& rows, bool skipEmptyRows)
63 {
64   while(file)
65   {
66     std::string buf;
67     std::getline(file, buf);
68     if(skipEmptyRows && buf.length() == 0) { continue; }
69     rows.push_back(buf);
70   }
71 }
72
73 double
74 readTimer()
75 {
76   #ifdef MULTITHREAD_SUPPORT
77   return omp_get_wtime();
78   #else
79   return clock() / (double)CLOCKS_PER_SEC;
80   #endif
81 }
82
83
84 } // namespace CSA