forked from equalpants/pigmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
executable file
·91 lines (67 loc) · 3.02 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2010 Michael J. Nelson
//
// This file is part of pigmap.
//
// pigmap is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// pigmap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with pigmap. If not, see <http://www.gnu.org/licenses/>.
#ifndef UTILS_H
#define UTILS_H
#include <vector>
#include <string>
#include <stdint.h>
// ensure that a directory exists (create any missing directories on path)
void makePath(const std::string& path);
void renameFile(const std::string& oldpath, const std::string& newpath);
void copyFile(const std::string& oldpath, const std::string& newpath);
// list names of entries in a directory, not including "." and ".."
// ...returns relative paths beginning with dirpath; appends results to vector
void listEntries(const std::string& dirpath, std::vector<std::string>& entries);
// -read a gzipped file into a buffer, overwriting its contents, and expanding it if necessary
// -return 0 on success, -1 for nonexistent file, -2 for other errors
int readGzFile(const std::string& filename, std::vector<uint8_t>& data);
// floored division; real value of a/b is floored instead of truncated toward 0
int64_t floordiv(int64_t a, int64_t b);
// ...same thing for ceiling
int64_t ceildiv(int64_t a, int64_t b);
// positive remainder mod 64, for chunk subdirectories
int64_t mod64pos(int64_t a);
// take a row-major index into a SIZExSIZE array and convert it to Z-order
uint32_t toZOrder(uint32_t i, const uint32_t SIZE);
// ...and vice versa
uint32_t fromZOrder(uint32_t i, const uint32_t SIZE);
bool fromBase36(const std::string& s, std::string::size_type pos, std::string::size_type n, int64_t& result);
int64_t fromBase36(const std::string& s);
std::string toBase36(int64_t i);
std::string tostring(int i);
// replace all occurrences of oldstr in text with newstr; return false if none found
bool replace(std::string& text, const std::string& oldstr, const std::string& newstr);
// find an assignment of costs to threads that attempts to minimize the difference
// between the min and max total thread costs; return the difference by itself, and
// also as a fraction of the max thread cost
std::pair<int64_t, double> schedule(const std::vector<int64_t>& costs, std::vector<int>& assignments, int threads);
class nocopy
{
protected:
nocopy() {}
~nocopy() {}
private:
nocopy(const nocopy& n);
const nocopy& operator=(const nocopy& n);
};
template <class T> struct arrayDeleter
{
T *array;
arrayDeleter(T *a) : array(a) {}
~arrayDeleter() {delete[] array;}
};
#endif // UTILS_H