catboost 1.25.1 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/DEPLOYMENT.md +22 -15
  2. package/README.md +37 -27
  3. package/binding.gyp +5 -7
  4. package/build_scripts/bootstrap.js +2 -1
  5. package/build_scripts/out/build.js +46 -68
  6. package/build_scripts/out/build_model.js +1 -1
  7. package/build_scripts/out/{build_ya.js → build_native.js} +1 -1
  8. package/build_scripts/out/ci.js +5 -5
  9. package/build_scripts/out/config.js +32 -18
  10. package/build_scripts/out/install.js +5 -3
  11. package/build_scripts/out/package_prepublish.js +1 -1
  12. package/build_scripts/out/packaging.js +1 -19
  13. package/build_scripts/out/run_tests.js +1 -1
  14. package/build_scripts/out/test.js +8 -3
  15. package/config.json +18 -11
  16. package/inc/catboost/libs/model_interface/c_api.h +349 -3
  17. package/lib/catboost.d.ts +65 -21
  18. package/package.json +4 -4
  19. package/src/api_helpers.cpp +100 -24
  20. package/src/api_helpers.h +8 -7
  21. package/src/api_module.cpp +1 -2
  22. package/src/model.cpp +483 -83
  23. package/src/model.h +24 -9
  24. package/inc/contrib/libs/cxxsupp/system_stl/include/stlfwd +0 -14
  25. package/inc/util/charset/recode_result.h +0 -9
  26. package/inc/util/charset/unicode_table.h +0 -123
  27. package/inc/util/charset/unidata.h +0 -421
  28. package/inc/util/charset/utf8.h +0 -384
  29. package/inc/util/charset/wide.h +0 -843
  30. package/inc/util/charset/wide_specific.h +0 -22
  31. package/inc/util/datetime/base.h +0 -669
  32. package/inc/util/datetime/constants.h +0 -7
  33. package/inc/util/datetime/cputimer.h +0 -124
  34. package/inc/util/datetime/parser.h +0 -292
  35. package/inc/util/datetime/systime.h +0 -47
  36. package/inc/util/datetime/uptime.h +0 -8
  37. package/inc/util/digest/city.h +0 -88
  38. package/inc/util/digest/fnv.h +0 -73
  39. package/inc/util/digest/multi.h +0 -14
  40. package/inc/util/digest/murmur.h +0 -57
  41. package/inc/util/digest/numeric.h +0 -86
  42. package/inc/util/digest/sequence.h +0 -48
  43. package/inc/util/draft/date.h +0 -129
  44. package/inc/util/draft/datetime.h +0 -184
  45. package/inc/util/draft/enum.h +0 -136
  46. package/inc/util/draft/holder_vector.h +0 -102
  47. package/inc/util/draft/ip.h +0 -131
  48. package/inc/util/draft/matrix.h +0 -108
  49. package/inc/util/draft/memory.h +0 -40
  50. package/inc/util/folder/dirent_win.h +0 -46
  51. package/inc/util/folder/dirut.h +0 -121
  52. package/inc/util/folder/filelist.h +0 -81
  53. package/inc/util/folder/fts.h +0 -108
  54. package/inc/util/folder/iterator.h +0 -109
  55. package/inc/util/folder/lstat_win.h +0 -20
  56. package/inc/util/folder/path.h +0 -225
  57. package/inc/util/folder/pathsplit.h +0 -113
  58. package/inc/util/folder/tempdir.h +0 -42
  59. package/inc/util/generic/adaptor.h +0 -134
  60. package/inc/util/generic/algorithm.h +0 -765
  61. package/inc/util/generic/array_ref.h +0 -282
  62. package/inc/util/generic/array_size.h +0 -24
  63. package/inc/util/generic/benchmark/vector_count_ctor/f.h +0 -9
  64. package/inc/util/generic/bitmap.h +0 -1115
  65. package/inc/util/generic/bitops.h +0 -459
  66. package/inc/util/generic/bt_exception.h +0 -24
  67. package/inc/util/generic/buffer.h +0 -232
  68. package/inc/util/generic/cast.h +0 -176
  69. package/inc/util/generic/deque.h +0 -24
  70. package/inc/util/generic/explicit_type.h +0 -42
  71. package/inc/util/generic/fastqueue.h +0 -55
  72. package/inc/util/generic/flags.h +0 -244
  73. package/inc/util/generic/function.h +0 -103
  74. package/inc/util/generic/fwd.h +0 -171
  75. package/inc/util/generic/guid.h +0 -61
  76. package/inc/util/generic/hash.h +0 -2032
  77. package/inc/util/generic/hash_primes.h +0 -140
  78. package/inc/util/generic/hash_set.h +0 -490
  79. package/inc/util/generic/hide_ptr.h +0 -3
  80. package/inc/util/generic/intrlist.h +0 -876
  81. package/inc/util/generic/is_in.h +0 -53
  82. package/inc/util/generic/iterator.h +0 -137
  83. package/inc/util/generic/iterator_range.h +0 -105
  84. package/inc/util/generic/lazy_value.h +0 -66
  85. package/inc/util/generic/list.h +0 -22
  86. package/inc/util/generic/map.h +0 -44
  87. package/inc/util/generic/mapfindptr.h +0 -60
  88. package/inc/util/generic/maybe.h +0 -713
  89. package/inc/util/generic/maybe_traits.h +0 -164
  90. package/inc/util/generic/mem_copy.h +0 -55
  91. package/inc/util/generic/noncopyable.h +0 -38
  92. package/inc/util/generic/object_counter.h +0 -53
  93. package/inc/util/generic/ptr.h +0 -1113
  94. package/inc/util/generic/queue.h +0 -57
  95. package/inc/util/generic/refcount.h +0 -162
  96. package/inc/util/generic/reserve.h +0 -11
  97. package/inc/util/generic/scope.h +0 -65
  98. package/inc/util/generic/serialized_enum.h +0 -406
  99. package/inc/util/generic/set.h +0 -42
  100. package/inc/util/generic/singleton.h +0 -136
  101. package/inc/util/generic/size_literals.h +0 -65
  102. package/inc/util/generic/stack.h +0 -18
  103. package/inc/util/generic/store_policy.h +0 -120
  104. package/inc/util/generic/strbase.h +0 -612
  105. package/inc/util/generic/strbuf.h +0 -552
  106. package/inc/util/generic/strfcpy.h +0 -17
  107. package/inc/util/generic/string.h +0 -1572
  108. package/inc/util/generic/string_hash.h +0 -21
  109. package/inc/util/generic/string_ut.h +0 -1175
  110. package/inc/util/generic/type_name.h +0 -34
  111. package/inc/util/generic/typelist.h +0 -114
  112. package/inc/util/generic/typetraits.h +0 -325
  113. package/inc/util/generic/utility.h +0 -132
  114. package/inc/util/generic/va_args.h +0 -400
  115. package/inc/util/generic/variant.h +0 -631
  116. package/inc/util/generic/variant_traits.h +0 -171
  117. package/inc/util/generic/vector.h +0 -119
  118. package/inc/util/generic/xrange.h +0 -258
  119. package/inc/util/generic/yexception.h +0 -212
  120. package/inc/util/generic/yexception_ut.h +0 -14
  121. package/inc/util/generic/ylimits.h +0 -92
  122. package/inc/util/generic/ymath.h +0 -206
  123. package/inc/util/memory/addstorage.h +0 -93
  124. package/inc/util/memory/alloc.h +0 -27
  125. package/inc/util/memory/blob.h +0 -296
  126. package/inc/util/memory/mmapalloc.h +0 -8
  127. package/inc/util/memory/pool.h +0 -432
  128. package/inc/util/memory/segmented_string_pool.h +0 -194
  129. package/inc/util/memory/segpool_alloc.h +0 -118
  130. package/inc/util/memory/smallobj.h +0 -141
  131. package/inc/util/memory/tempbuf.h +0 -111
  132. package/inc/util/network/address.h +0 -136
  133. package/inc/util/network/endpoint.h +0 -61
  134. package/inc/util/network/hostip.h +0 -16
  135. package/inc/util/network/init.h +0 -60
  136. package/inc/util/network/interface.h +0 -17
  137. package/inc/util/network/iovec.h +0 -65
  138. package/inc/util/network/ip.h +0 -116
  139. package/inc/util/network/nonblock.h +0 -8
  140. package/inc/util/network/pair.h +0 -9
  141. package/inc/util/network/poller.h +0 -58
  142. package/inc/util/network/pollerimpl.h +0 -707
  143. package/inc/util/network/sock.h +0 -608
  144. package/inc/util/network/socket.h +0 -421
  145. package/inc/util/random/common_ops.h +0 -130
  146. package/inc/util/random/easy.h +0 -47
  147. package/inc/util/random/entropy.h +0 -21
  148. package/inc/util/random/fast.h +0 -101
  149. package/inc/util/random/init_atfork.h +0 -3
  150. package/inc/util/random/lcg_engine.h +0 -66
  151. package/inc/util/random/mersenne.h +0 -46
  152. package/inc/util/random/mersenne32.h +0 -50
  153. package/inc/util/random/mersenne64.h +0 -50
  154. package/inc/util/random/normal.h +0 -38
  155. package/inc/util/random/random.h +0 -30
  156. package/inc/util/random/shuffle.h +0 -39
  157. package/inc/util/str_stl.h +0 -266
  158. package/inc/util/stream/aligned.h +0 -99
  159. package/inc/util/stream/buffer.h +0 -119
  160. package/inc/util/stream/buffered.h +0 -225
  161. package/inc/util/stream/debug.h +0 -53
  162. package/inc/util/stream/direct_io.h +0 -43
  163. package/inc/util/stream/file.h +0 -108
  164. package/inc/util/stream/format.h +0 -444
  165. package/inc/util/stream/fwd.h +0 -100
  166. package/inc/util/stream/hex.h +0 -8
  167. package/inc/util/stream/holder.h +0 -44
  168. package/inc/util/stream/input.h +0 -273
  169. package/inc/util/stream/labeled.h +0 -19
  170. package/inc/util/stream/length.h +0 -100
  171. package/inc/util/stream/mem.h +0 -255
  172. package/inc/util/stream/multi.h +0 -32
  173. package/inc/util/stream/null.h +0 -61
  174. package/inc/util/stream/output.h +0 -304
  175. package/inc/util/stream/pipe.h +0 -112
  176. package/inc/util/stream/printf.h +0 -25
  177. package/inc/util/stream/str.h +0 -207
  178. package/inc/util/stream/tee.h +0 -28
  179. package/inc/util/stream/tempbuf.h +0 -21
  180. package/inc/util/stream/tokenizer.h +0 -214
  181. package/inc/util/stream/trace.h +0 -60
  182. package/inc/util/stream/walk.h +0 -35
  183. package/inc/util/stream/zerocopy.h +0 -91
  184. package/inc/util/stream/zerocopy_output.h +0 -57
  185. package/inc/util/stream/zlib.h +0 -173
  186. package/inc/util/string/ascii.h +0 -236
  187. package/inc/util/string/builder.h +0 -39
  188. package/inc/util/string/cast.h +0 -347
  189. package/inc/util/string/cstriter.h +0 -14
  190. package/inc/util/string/escape.h +0 -70
  191. package/inc/util/string/hex.h +0 -59
  192. package/inc/util/string/join.h +0 -194
  193. package/inc/util/string/printf.h +0 -13
  194. package/inc/util/string/reverse.h +0 -16
  195. package/inc/util/string/split.h +0 -1080
  196. package/inc/util/string/strip.h +0 -257
  197. package/inc/util/string/strspn.h +0 -65
  198. package/inc/util/string/subst.h +0 -56
  199. package/inc/util/string/type.h +0 -50
  200. package/inc/util/string/util.h +0 -195
  201. package/inc/util/string/vector.h +0 -132
  202. package/inc/util/system/align.h +0 -50
  203. package/inc/util/system/atexit.h +0 -22
  204. package/inc/util/system/atomic.h +0 -51
  205. package/inc/util/system/atomic_gcc.h +0 -90
  206. package/inc/util/system/atomic_ops.h +0 -189
  207. package/inc/util/system/atomic_win.h +0 -114
  208. package/inc/util/system/backtrace.h +0 -39
  209. package/inc/util/system/byteorder.h +0 -186
  210. package/inc/util/system/compat.h +0 -84
  211. package/inc/util/system/compiler.h +0 -620
  212. package/inc/util/system/condvar.h +0 -71
  213. package/inc/util/system/context.h +0 -181
  214. package/inc/util/system/context_aarch64.h +0 -8
  215. package/inc/util/system/context_i686.h +0 -9
  216. package/inc/util/system/context_x86.h +0 -12
  217. package/inc/util/system/context_x86_64.h +0 -7
  218. package/inc/util/system/cpu_id.h +0 -159
  219. package/inc/util/system/daemon.h +0 -28
  220. package/inc/util/system/datetime.h +0 -98
  221. package/inc/util/system/defaults.h +0 -149
  222. package/inc/util/system/demangle.h +0 -5
  223. package/inc/util/system/demangle_impl.h +0 -23
  224. package/inc/util/system/direct_io.h +0 -71
  225. package/inc/util/system/dynlib.h +0 -119
  226. package/inc/util/system/env.h +0 -32
  227. package/inc/util/system/error.h +0 -95
  228. package/inc/util/system/event.h +0 -122
  229. package/inc/util/system/execpath.h +0 -17
  230. package/inc/util/system/fasttime.h +0 -6
  231. package/inc/util/system/fhandle.h +0 -27
  232. package/inc/util/system/file.h +0 -210
  233. package/inc/util/system/file_lock.h +0 -34
  234. package/inc/util/system/filemap.h +0 -383
  235. package/inc/util/system/flock.h +0 -35
  236. package/inc/util/system/fs.h +0 -156
  237. package/inc/util/system/fs_win.h +0 -29
  238. package/inc/util/system/fstat.h +0 -46
  239. package/inc/util/system/getpid.h +0 -12
  240. package/inc/util/system/guard.h +0 -179
  241. package/inc/util/system/hi_lo.h +0 -139
  242. package/inc/util/system/hostname.h +0 -10
  243. package/inc/util/system/hp_timer.h +0 -36
  244. package/inc/util/system/info.h +0 -12
  245. package/inc/util/system/interrupt_signals.h +0 -22
  246. package/inc/util/system/madvise.h +0 -30
  247. package/inc/util/system/maxlen.h +0 -32
  248. package/inc/util/system/mem_info.h +0 -18
  249. package/inc/util/system/mincore.h +0 -38
  250. package/inc/util/system/mktemp.h +0 -11
  251. package/inc/util/system/mlock.h +0 -43
  252. package/inc/util/system/mutex.h +0 -67
  253. package/inc/util/system/nice.h +0 -3
  254. package/inc/util/system/pipe.h +0 -90
  255. package/inc/util/system/platform.h +0 -246
  256. package/inc/util/system/progname.h +0 -13
  257. package/inc/util/system/protect.h +0 -25
  258. package/inc/util/system/rusage.h +0 -26
  259. package/inc/util/system/rwlock.h +0 -78
  260. package/inc/util/system/sanitizers.h +0 -122
  261. package/inc/util/system/sem.h +0 -41
  262. package/inc/util/system/shellcommand.h +0 -472
  263. package/inc/util/system/shmat.h +0 -32
  264. package/inc/util/system/sigset.h +0 -78
  265. package/inc/util/system/spin_wait.h +0 -10
  266. package/inc/util/system/spinlock.h +0 -121
  267. package/inc/util/system/src_location.h +0 -25
  268. package/inc/util/system/src_root.h +0 -68
  269. package/inc/util/system/sys_alloc.h +0 -43
  270. package/inc/util/system/sysstat.h +0 -52
  271. package/inc/util/system/tempfile.h +0 -34
  272. package/inc/util/system/thread.h +0 -167
  273. package/inc/util/system/tls.h +0 -307
  274. package/inc/util/system/types.h +0 -119
  275. package/inc/util/system/unaligned_mem.h +0 -67
  276. package/inc/util/system/user.h +0 -5
  277. package/inc/util/system/utime.h +0 -6
  278. package/inc/util/system/valgrind.h +0 -48
  279. package/inc/util/system/winint.h +0 -43
  280. package/inc/util/system/yassert.h +0 -121
  281. package/inc/util/system/yield.h +0 -4
  282. package/inc/util/thread/factory.h +0 -65
  283. package/inc/util/thread/fwd.h +0 -30
  284. package/inc/util/thread/lfqueue.h +0 -406
  285. package/inc/util/thread/lfstack.h +0 -188
  286. package/inc/util/thread/pool.h +0 -388
  287. package/inc/util/thread/singleton.h +0 -42
  288. package/inc/util/ysafeptr.h +0 -427
  289. package/inc/util/ysaveload.h +0 -700
@@ -1,34 +0,0 @@
1
- #pragma once
2
-
3
- #include <util/generic/fwd.h>
4
- #include <util/generic/noncopyable.h>
5
- #include <util/system/file.h>
6
-
7
- enum class EFileLockType{
8
- Exclusive,
9
- Shared
10
- };
11
-
12
- class TFileLock: public TFile {
13
- public:
14
- TFileLock(const TString& filename, const EFileLockType type = EFileLockType::Exclusive);
15
-
16
- void Acquire();
17
- bool TryAcquire();
18
- void Release();
19
-
20
- inline void lock() {
21
- Acquire();
22
- }
23
-
24
- inline bool try_lock() {
25
- return TryAcquire();
26
- }
27
-
28
- inline void unlock() {
29
- Release();
30
- }
31
-
32
- private:
33
- EFileLockType Type;
34
- };
@@ -1,383 +0,0 @@
1
- #pragma once
2
-
3
- #include "file.h"
4
- #include "align.h"
5
- #include "yassert.h"
6
-
7
- #include <util/generic/noncopyable.h>
8
- #include <util/generic/ptr.h>
9
- #include <util/generic/utility.h>
10
- #include <util/generic/yexception.h>
11
- #include <util/generic/flags.h>
12
- #include <util/generic/string.h>
13
-
14
- #include <new>
15
- #include <cstdio>
16
-
17
- namespace NPrivate {
18
- // NB: use TFileMap::Precharge() and TFileMappedArray::Prechage()
19
- void Precharge(const void* data, size_t dataSize, size_t offset, size_t size);
20
- }
21
-
22
- struct TMemoryMapCommon {
23
- struct TMapResult {
24
- inline size_t MappedSize() const noexcept {
25
- return Size - Head;
26
- }
27
-
28
- inline void* MappedData() const noexcept {
29
- return Ptr ? (void*)((char*)Ptr + Head) : nullptr;
30
- }
31
-
32
- inline bool IsMapped() const noexcept {
33
- return Ptr != nullptr;
34
- }
35
-
36
- inline void Reset() noexcept {
37
- Ptr = nullptr;
38
- Size = 0;
39
- Head = 0;
40
- }
41
-
42
- void* Ptr;
43
- size_t Size;
44
- i32 Head;
45
-
46
- TMapResult(void) noexcept {
47
- Reset();
48
- }
49
- };
50
-
51
- enum EOpenModeFlag {
52
- oRdOnly = 1,
53
- oRdWr = 2,
54
- oCopyOnWr = 4,
55
-
56
- oAccessMask = 7,
57
- oNotGreedy = 8,
58
- oPrecharge = 16,
59
- oPopulate = 32, // Populate page table entries (see mmap's MAP_POPULATE)
60
- };
61
- Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag)
62
-
63
- /**
64
- * Name that will be printed in exceptions if not specified.
65
- * Overridden by name obtained from `TFile` if it's not empty.
66
- */
67
- static const TString UnknownFileName;
68
- };
69
- Y_DECLARE_OPERATORS_FOR_FLAGS(TMemoryMapCommon::EOpenMode)
70
-
71
- class TMemoryMap: public TMemoryMapCommon {
72
- public:
73
- explicit TMemoryMap(const TString& name);
74
- explicit TMemoryMap(const TString& name, EOpenMode om);
75
- TMemoryMap(const TString& name, i64 length, EOpenMode om);
76
- TMemoryMap(FILE* f, TString dbgName = UnknownFileName);
77
- TMemoryMap(FILE* f, EOpenMode om, TString dbgName = UnknownFileName);
78
- TMemoryMap(const TFile& file, TString dbgName = UnknownFileName);
79
- TMemoryMap(const TFile& file, EOpenMode om, TString dbgName = UnknownFileName);
80
-
81
- ~TMemoryMap();
82
-
83
- TMapResult Map(i64 offset, size_t size);
84
- bool Unmap(TMapResult region);
85
-
86
- void ResizeAndReset(i64 size);
87
- TMapResult ResizeAndRemap(i64 offset, size_t size);
88
-
89
- i64 Length() const noexcept;
90
- bool IsOpen() const noexcept;
91
- bool IsWritable() const noexcept;
92
- EOpenMode GetMode() const noexcept;
93
- TFile GetFile() const noexcept;
94
-
95
- void SetSequential();
96
- void Evict(void* ptr, size_t len);
97
- void Evict();
98
-
99
- /*
100
- * deprecated
101
- */
102
- bool Unmap(void* ptr, size_t size);
103
-
104
- private:
105
- class TImpl;
106
- TSimpleIntrusivePtr<TImpl> Impl_;
107
- };
108
-
109
- class TFileMap: public TMemoryMapCommon {
110
- public:
111
- TFileMap(const TMemoryMap& map) noexcept;
112
- TFileMap(const TString& name);
113
- TFileMap(const TString& name, EOpenMode om);
114
- TFileMap(const TString& name, i64 length, EOpenMode om);
115
- TFileMap(FILE* f, EOpenMode om = oRdOnly, TString dbgName = UnknownFileName);
116
- TFileMap(const TFile& file, EOpenMode om = oRdOnly, TString dbgName = UnknownFileName);
117
- TFileMap(const TFileMap& fm) noexcept;
118
-
119
- ~TFileMap();
120
-
121
- TMapResult Map(i64 offset, size_t size);
122
- TMapResult ResizeAndRemap(i64 offset, size_t size);
123
- void Unmap();
124
-
125
- void Flush(void* ptr, size_t size) {
126
- Flush(ptr, size, true);
127
- }
128
-
129
- void Flush() {
130
- Flush(Ptr(), MappedSize());
131
- }
132
-
133
- void FlushAsync(void* ptr, size_t size) {
134
- Flush(ptr, size, false);
135
- }
136
-
137
- void FlushAsync() {
138
- FlushAsync(Ptr(), MappedSize());
139
- }
140
-
141
- inline i64 Length() const noexcept {
142
- return Map_.Length();
143
- }
144
-
145
- inline bool IsOpen() const noexcept {
146
- return Map_.IsOpen();
147
- }
148
-
149
- inline bool IsWritable() const noexcept {
150
- return Map_.IsWritable();
151
- }
152
-
153
- EOpenMode GetMode() const noexcept {
154
- return Map_.GetMode();
155
- }
156
-
157
- inline void* Ptr() const noexcept {
158
- return Region_.MappedData();
159
- }
160
-
161
- inline size_t MappedSize() const noexcept {
162
- return Region_.MappedSize();
163
- }
164
-
165
- TFile GetFile() const noexcept {
166
- return Map_.GetFile();
167
- }
168
-
169
- void Precharge(size_t pos = 0, size_t size = (size_t)-1) const;
170
-
171
- void SetSequential() {
172
- Map_.SetSequential();
173
- }
174
-
175
- void Evict() {
176
- Map_.Evict();
177
- }
178
-
179
- private:
180
- void Flush(void* ptr, size_t size, bool sync);
181
-
182
- TMemoryMap Map_;
183
- TMapResult Region_;
184
- };
185
-
186
- template <class T>
187
- class TFileMappedArray {
188
- private:
189
- const T* Ptr_;
190
- const T* End_;
191
- size_t Size_;
192
- char DummyData_[sizeof(T) + PLATFORM_DATA_ALIGN];
193
- mutable THolder<T, TDestructor> Dummy_;
194
- THolder<TFileMap> DataHolder_;
195
-
196
- public:
197
- TFileMappedArray()
198
- : Ptr_(nullptr)
199
- , End_(nullptr)
200
- , Size_(0)
201
- {
202
- }
203
- ~TFileMappedArray() {
204
- Ptr_ = nullptr;
205
- End_ = nullptr;
206
- }
207
- void Init(const char* name) {
208
- DataHolder_.Reset(new TFileMap(name));
209
- DoInit(name);
210
- }
211
- void Init(const TFileMap& fileMap) {
212
- DataHolder_.Reset(new TFileMap(fileMap));
213
- DoInit(fileMap.GetFile().GetName());
214
- }
215
- void Term() {
216
- DataHolder_.Destroy();
217
- Ptr_ = nullptr;
218
- Size_ = 0;
219
- End_ = nullptr;
220
- }
221
- void Precharge() {
222
- DataHolder_->Precharge();
223
- }
224
- const T& operator[](size_t pos) const {
225
- Y_ASSERT(pos < size());
226
- return Ptr_[pos];
227
- }
228
- /// for STL compatibility only, Size() usage is recommended
229
- size_t size() const {
230
- return Size_;
231
- }
232
- size_t Size() const {
233
- return Size_;
234
- }
235
- const T& GetAt(size_t pos) const {
236
- if (pos < Size_)
237
- return Ptr_[pos];
238
- return Dummy();
239
- }
240
- void SetDummy(const T& n_Dummy) {
241
- Dummy_.Destroy();
242
- Dummy_.Reset(new (DummyData()) T(n_Dummy));
243
- }
244
- inline char* DummyData() const noexcept {
245
- return AlignUp((char*)DummyData_);
246
- }
247
- inline const T& Dummy() const {
248
- if (!Dummy_) {
249
- Dummy_.Reset(new (DummyData()) T());
250
- }
251
-
252
- return *Dummy_;
253
- }
254
- /// for STL compatibility only, Empty() usage is recommended
255
- Y_PURE_FUNCTION
256
- bool empty() const noexcept {
257
- return Empty();
258
- }
259
-
260
- Y_PURE_FUNCTION
261
- bool Empty() const noexcept {
262
- return 0 == Size_;
263
- }
264
- /// for STL compatibility only, Begin() usage is recommended
265
- const T* begin() const noexcept {
266
- return Begin();
267
- }
268
- const T* Begin() const noexcept {
269
- return Ptr_;
270
- }
271
- /// for STL compatibility only, End() usage is recommended
272
- const T* end() const noexcept {
273
- return End_;
274
- }
275
- const T* End() const noexcept {
276
- return End_;
277
- }
278
-
279
- private:
280
- void DoInit(const TString& fileName) {
281
- DataHolder_->Map(0, DataHolder_->Length());
282
- if (DataHolder_->Length() % sizeof(T)) {
283
- Term();
284
- ythrow yexception() << "Incorrect size of file " << fileName.Quote();
285
- }
286
- Ptr_ = (const T*)DataHolder_->Ptr();
287
- Size_ = DataHolder_->Length() / sizeof(T);
288
- End_ = Ptr_ + Size_;
289
- }
290
- };
291
-
292
- class TMappedAllocation : TMoveOnly {
293
- public:
294
- TMappedAllocation(size_t size = 0, bool shared = false, void* addr = nullptr);
295
- ~TMappedAllocation() {
296
- Dealloc();
297
- }
298
- TMappedAllocation(TMappedAllocation&& other) {
299
- this->swap(other);
300
- }
301
- TMappedAllocation& operator=(TMappedAllocation&& other) {
302
- this->swap(other);
303
- return *this;
304
- }
305
- void* Alloc(size_t size, void* addr = nullptr);
306
- void Dealloc();
307
- void* Ptr() const {
308
- return Ptr_;
309
- }
310
- char* Data(ui32 pos = 0) const {
311
- return (char*)(Ptr_ ? ((char*)Ptr_ + pos) : nullptr);
312
- }
313
- char* Begin() const noexcept {
314
- return (char*)Ptr();
315
- }
316
- char* End() const noexcept {
317
- return Begin() + MappedSize();
318
- }
319
- size_t MappedSize() const {
320
- return Size_;
321
- }
322
- void swap(TMappedAllocation& with);
323
-
324
- private:
325
- void* Ptr_ = nullptr;
326
- size_t Size_ = 0;
327
- bool Shared_ = false;
328
- #ifdef _win_
329
- void* Mapping_ = nullptr;
330
- #endif
331
- };
332
-
333
- template <class T>
334
- class TMappedArray: private TMappedAllocation {
335
- public:
336
- TMappedArray(size_t siz = 0)
337
- : TMappedAllocation(0)
338
- {
339
- if (siz)
340
- Create(siz);
341
- }
342
- ~TMappedArray() {
343
- Destroy();
344
- }
345
- T* Create(size_t siz) {
346
- Y_ASSERT(MappedSize() == 0 && Ptr() == nullptr);
347
- T* arr = (T*)Alloc((sizeof(T) * siz));
348
- if (!arr)
349
- return nullptr;
350
- Y_ASSERT(MappedSize() == sizeof(T) * siz);
351
- for (size_t n = 0; n < siz; n++)
352
- new (&arr[n]) T();
353
- return arr;
354
- }
355
- void Destroy() {
356
- T* arr = (T*)Ptr();
357
- if (arr) {
358
- for (size_t n = 0; n < size(); n++)
359
- arr[n].~T();
360
- Dealloc();
361
- }
362
- }
363
- T& operator[](size_t pos) {
364
- Y_ASSERT(pos < size());
365
- return ((T*)Ptr())[pos];
366
- }
367
- const T& operator[](size_t pos) const {
368
- Y_ASSERT(pos < size());
369
- return ((T*)Ptr())[pos];
370
- }
371
- T* begin() {
372
- return (T*)Ptr();
373
- }
374
- T* end() {
375
- return (T*)((char*)Ptr() + MappedSize());
376
- }
377
- size_t size() const {
378
- return MappedSize() / sizeof(T);
379
- }
380
- void swap(TMappedArray<T>& with) {
381
- TMappedAllocation::swap(with);
382
- }
383
- };
@@ -1,35 +0,0 @@
1
- #pragma once
2
-
3
- #include "error.h"
4
- #include "defaults.h"
5
- #include "file.h"
6
-
7
- #if defined(_unix_)
8
-
9
- #include <sys/file.h>
10
- #include <fcntl.h>
11
-
12
- static inline int Flock(int fd, int op) {
13
- return flock(fd, op);
14
- }
15
-
16
- #else // not _unix_
17
-
18
- #ifdef __cplusplus
19
- extern "C" {
20
- #endif
21
-
22
- #define LOCK_SH 1 /* shared lock */
23
- #define LOCK_EX 2 /* exclusive lock */
24
- #define LOCK_NB 4 /* don't block when locking */
25
- #define LOCK_UN 8 /* unlock */
26
-
27
- int Flock(void* hndl, int operation);
28
- int flock(int fd, int operation);
29
- int fsync(int fd);
30
-
31
- #ifdef __cplusplus
32
- }
33
- #endif
34
-
35
- #endif // not _unix_
@@ -1,156 +0,0 @@
1
- #pragma once
2
-
3
- #include <util/generic/flags.h>
4
- #include <util/generic/string.h>
5
- #include <util/generic/yexception.h>
6
-
7
- namespace NFs {
8
- enum EFilePermission {
9
- FP_ALL_EXEC = 01,
10
- FP_ALL_WRITE = 02,
11
- FP_ALL_READ = 04,
12
- FP_GROUP_READ = 040,
13
- FP_GROUP_WRITE = 020,
14
- FP_GROUP_EXEC = 010,
15
- FP_OWNER_READ = 0400,
16
- FP_OWNER_WRITE = 0200,
17
- FP_OWNER_EXEC = 0100,
18
-
19
- FP_COMMON_FILE = 0777,
20
- FP_SECRET_FILE = 0700,
21
- FP_NONSECRET_FILE = 0744,
22
- };
23
-
24
- Y_DECLARE_FLAGS(EFilePermissions, EFilePermission);
25
-
26
- /// Remove a file or empty directory
27
- ///
28
- /// @param[in] path Path to file or directory
29
- /// @returns true on success or false otherwise
30
- /// LastSystemError() is set in case of failure
31
- bool Remove(const TString& path);
32
-
33
- /// Remove a file or directory with contents
34
- ///
35
- /// @param[in] path Path to file or directory
36
- /// @throws
37
- void RemoveRecursive(const TString& path);
38
-
39
- /// Creates directory
40
- ///
41
- /// @param[in] path Path to the directory
42
- /// @param[in] mode Access permissions field; NOTE: ignored on win
43
- /// @returns true on success or false otherwise
44
- bool MakeDirectory(const TString& path, EFilePermissions mode);
45
-
46
- /// Creates directory
47
- ///
48
- /// @param[in] path Path to the directory
49
- /// @returns true on success or false otherwise
50
- /// NOTE: access permissions is set to 0777
51
- inline bool MakeDirectory(const TString& path) {
52
- return MakeDirectory(path, FP_COMMON_FILE);
53
- }
54
-
55
- /// Creates directory and all non-existings parents
56
- ///
57
- /// @param[in] path Path to be created
58
- /// @param[in] mode Access permissions field; NOTE: ignored on win
59
- /// @param[in] alwaysCreate Throw if path already exists or failed to create
60
- /// @returns true if target path created or exists (and directory)
61
- bool MakeDirectoryRecursive(const TString& path, EFilePermissions mode, bool alwaysCreate);
62
-
63
- /// Creates directory and all non-existings parents
64
- ///
65
- /// @param[in] path Path to be created
66
- /// @param[in] mode Access permissions field; NOTE: ignored on win
67
- /// @returns true if target path created or exists (and directory)
68
- inline bool MakeDirectoryRecursive(const TString& path, EFilePermissions mode) {
69
- return MakeDirectoryRecursive(path, mode, false);
70
- }
71
-
72
- /// Creates directory and all non-existings parents
73
- ///
74
- /// @param[in] path Path to be created
75
- /// @returns true if target path created or exists (and directory)
76
- inline bool MakeDirectoryRecursive(const TString& path) {
77
- return MakeDirectoryRecursive(path, FP_COMMON_FILE, false);
78
- }
79
-
80
- /// Rename a file or directory.
81
- /// Removes newPath if it exists
82
- ///
83
- /// @param[in] oldPath Path to file or directory to rename
84
- /// @param[in] newPath New path of file or directory
85
- /// @returns true on success or false otherwise
86
- /// LastSystemError() is set in case of failure
87
- bool Rename(const TString& oldPath, const TString& newPath);
88
-
89
- /// Creates a new directory entry for a file
90
- /// or creates a new one with the same content
91
- ///
92
- /// @param[in] existingPath Path to an existing file
93
- /// @param[in] newPath New path of file
94
- void HardLinkOrCopy(const TString& existingPath, const TString& newPath);
95
-
96
- /// Creates a new directory entry for a file
97
- ///
98
- /// @param[in] existingPath Path to an existing file
99
- /// @param[in] newPath New path of file
100
- /// @returns true if new link was created or false otherwise
101
- /// LastSystemError() is set in case of failure
102
- bool HardLink(const TString& existingPath, const TString& newPath);
103
-
104
- /// Creates a symlink to a file
105
- ///
106
- /// @param[in] targetPath Path to a target file
107
- /// @param[in] linkPath Path of symlink
108
- /// @returns true if new link was created or false otherwise
109
- /// LastSystemError() is set in case of failure
110
- bool SymLink(const TString& targetPath, const TString& linkPath);
111
-
112
- /// Reads value of a symbolic link
113
- ///
114
- /// @param[in] path Path to a symlink
115
- /// @returns File path that a symlink points to
116
- TString ReadLink(const TString& path);
117
-
118
- /// Append contents of a file to a new file
119
- ///
120
- /// @param[in] dstPath Path to a destination file
121
- /// @param[in] srcPath Path to a source file
122
- void Cat(const TString& dstPath, const TString& srcPath);
123
-
124
- /// Copy contents of a file to a new file
125
- ///
126
- /// @param[in] existingPath Path to an existing file
127
- /// @param[in] newPath New path of file
128
- void Copy(const TString& existingPath, const TString& newPath);
129
-
130
- /// Returns path to the current working directory
131
- ///
132
- /// Note: is not threadsafe
133
- TString CurrentWorkingDirectory();
134
-
135
- /// Changes current working directory
136
- ///
137
- /// @param[in] path Path for new cwd
138
- /// Note: is not threadsafe
139
- void SetCurrentWorkingDirectory(TString path);
140
-
141
- /// Checks if file exists
142
- ///
143
- /// @param[in] path Path to check
144
- bool Exists(const TString& path);
145
-
146
- /// Ensures that file exists
147
- ///
148
- /// @param[in] path Path to check
149
- /// @returns input argument
150
- inline const TString& EnsureExists(const TString& path) {
151
- Y_ENSURE_EX(Exists(path), TFileError{} << "Path " << path << " does not exists (checked from cwd:" << NFs::CurrentWorkingDirectory() << ")");
152
- return path;
153
- }
154
- }
155
-
156
- Y_DECLARE_OPERATORS_FOR_FLAGS(NFs::EFilePermissions)
@@ -1,29 +0,0 @@
1
- #pragma once
2
-
3
- #include "winint.h"
4
- #include "defaults.h"
5
-
6
- #include <util/generic/strbuf.h>
7
- #include <util/generic/string.h>
8
-
9
- namespace NFsPrivate {
10
- bool WinRename(const TString& oldPath, const TString& newPath);
11
-
12
- bool WinSymLink(const TString& targetName, const TString& linkName);
13
-
14
- bool WinHardLink(const TString& existingPath, const TString& newPath);
15
-
16
- TString WinReadLink(const TString& path);
17
-
18
- HANDLE CreateFileWithUtf8Name(const TStringBuf fName, ui32 accessMode, ui32 shareMode, ui32 createMode, ui32 attributes, bool inheritHandle);
19
-
20
- bool WinRemove(const TString& path);
21
-
22
- bool WinExists(const TString& path);
23
-
24
- TString WinCurrentWorkingDirectory();
25
-
26
- bool WinSetCurrentWorkingDirectory(const TString& path);
27
-
28
- bool WinMakeDirectory(const TString path);
29
- }
@@ -1,46 +0,0 @@
1
- #pragma once
2
-
3
- #include <util/generic/fwd.h>
4
- #include <util/system/fhandle.h>
5
-
6
- class TFile;
7
- class TFsPath;
8
-
9
- struct TFileStat {
10
- ui32 Mode = 0; /* protection */
11
- ui32 Uid = 0; /* user ID of owner */
12
- ui32 Gid = 0; /* group ID of owner */
13
-
14
- ui64 NLinks = 0; /* number of hard links */
15
- ui64 Size = 0; /* total size, in bytes */
16
- ui64 INode = 0; /* inode number */
17
-
18
- time_t ATime = 0; /* time of last access */
19
- time_t MTime = 0; /* time of last modification */
20
- time_t CTime = 0; /* time of last status change */
21
-
22
- public:
23
- TFileStat();
24
-
25
- bool IsNull() const noexcept;
26
-
27
- bool IsFile() const noexcept;
28
- bool IsDir() const noexcept;
29
- bool IsSymlink() const noexcept;
30
-
31
- explicit TFileStat(const TFile& f);
32
- explicit TFileStat(FHANDLE f);
33
- TFileStat(const TFsPath& fileName, bool nofollow = false);
34
- TFileStat(const TString& fileName, bool nofollow = false);
35
- TFileStat(const char* fileName, bool nofollow = false);
36
-
37
- friend bool operator==(const TFileStat& l, const TFileStat& r) noexcept;
38
- friend bool operator!=(const TFileStat& l, const TFileStat& r) noexcept;
39
-
40
- private:
41
- void MakeFromFileName(const char* fileName, bool nofollow);
42
- };
43
-
44
- i64 GetFileLength(FHANDLE fd);
45
- i64 GetFileLength(const char* name);
46
- i64 GetFileLength(const TString& name);
@@ -1,12 +0,0 @@
1
- #pragma once
2
-
3
- #include "platform.h"
4
- #include "types.h"
5
-
6
- #if defined(_win_)
7
- using TProcessId = ui32; // DWORD
8
- #else
9
- using TProcessId = pid_t;
10
- #endif
11
-
12
- TProcessId GetPID();