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.
- package/DEPLOYMENT.md +22 -15
- package/README.md +37 -27
- package/binding.gyp +5 -7
- package/build_scripts/bootstrap.js +2 -1
- package/build_scripts/out/build.js +46 -68
- package/build_scripts/out/build_model.js +1 -1
- package/build_scripts/out/{build_ya.js → build_native.js} +1 -1
- package/build_scripts/out/ci.js +5 -5
- package/build_scripts/out/config.js +32 -18
- package/build_scripts/out/install.js +5 -3
- package/build_scripts/out/package_prepublish.js +1 -1
- package/build_scripts/out/packaging.js +1 -19
- package/build_scripts/out/run_tests.js +1 -1
- package/build_scripts/out/test.js +8 -3
- package/config.json +18 -11
- package/inc/catboost/libs/model_interface/c_api.h +349 -3
- package/lib/catboost.d.ts +65 -21
- package/package.json +4 -4
- package/src/api_helpers.cpp +100 -24
- package/src/api_helpers.h +8 -7
- package/src/api_module.cpp +1 -2
- package/src/model.cpp +483 -83
- package/src/model.h +24 -9
- package/inc/contrib/libs/cxxsupp/system_stl/include/stlfwd +0 -14
- package/inc/util/charset/recode_result.h +0 -9
- package/inc/util/charset/unicode_table.h +0 -123
- package/inc/util/charset/unidata.h +0 -421
- package/inc/util/charset/utf8.h +0 -384
- package/inc/util/charset/wide.h +0 -843
- package/inc/util/charset/wide_specific.h +0 -22
- package/inc/util/datetime/base.h +0 -669
- package/inc/util/datetime/constants.h +0 -7
- package/inc/util/datetime/cputimer.h +0 -124
- package/inc/util/datetime/parser.h +0 -292
- package/inc/util/datetime/systime.h +0 -47
- package/inc/util/datetime/uptime.h +0 -8
- package/inc/util/digest/city.h +0 -88
- package/inc/util/digest/fnv.h +0 -73
- package/inc/util/digest/multi.h +0 -14
- package/inc/util/digest/murmur.h +0 -57
- package/inc/util/digest/numeric.h +0 -86
- package/inc/util/digest/sequence.h +0 -48
- package/inc/util/draft/date.h +0 -129
- package/inc/util/draft/datetime.h +0 -184
- package/inc/util/draft/enum.h +0 -136
- package/inc/util/draft/holder_vector.h +0 -102
- package/inc/util/draft/ip.h +0 -131
- package/inc/util/draft/matrix.h +0 -108
- package/inc/util/draft/memory.h +0 -40
- package/inc/util/folder/dirent_win.h +0 -46
- package/inc/util/folder/dirut.h +0 -121
- package/inc/util/folder/filelist.h +0 -81
- package/inc/util/folder/fts.h +0 -108
- package/inc/util/folder/iterator.h +0 -109
- package/inc/util/folder/lstat_win.h +0 -20
- package/inc/util/folder/path.h +0 -225
- package/inc/util/folder/pathsplit.h +0 -113
- package/inc/util/folder/tempdir.h +0 -42
- package/inc/util/generic/adaptor.h +0 -134
- package/inc/util/generic/algorithm.h +0 -765
- package/inc/util/generic/array_ref.h +0 -282
- package/inc/util/generic/array_size.h +0 -24
- package/inc/util/generic/benchmark/vector_count_ctor/f.h +0 -9
- package/inc/util/generic/bitmap.h +0 -1115
- package/inc/util/generic/bitops.h +0 -459
- package/inc/util/generic/bt_exception.h +0 -24
- package/inc/util/generic/buffer.h +0 -232
- package/inc/util/generic/cast.h +0 -176
- package/inc/util/generic/deque.h +0 -24
- package/inc/util/generic/explicit_type.h +0 -42
- package/inc/util/generic/fastqueue.h +0 -55
- package/inc/util/generic/flags.h +0 -244
- package/inc/util/generic/function.h +0 -103
- package/inc/util/generic/fwd.h +0 -171
- package/inc/util/generic/guid.h +0 -61
- package/inc/util/generic/hash.h +0 -2032
- package/inc/util/generic/hash_primes.h +0 -140
- package/inc/util/generic/hash_set.h +0 -490
- package/inc/util/generic/hide_ptr.h +0 -3
- package/inc/util/generic/intrlist.h +0 -876
- package/inc/util/generic/is_in.h +0 -53
- package/inc/util/generic/iterator.h +0 -137
- package/inc/util/generic/iterator_range.h +0 -105
- package/inc/util/generic/lazy_value.h +0 -66
- package/inc/util/generic/list.h +0 -22
- package/inc/util/generic/map.h +0 -44
- package/inc/util/generic/mapfindptr.h +0 -60
- package/inc/util/generic/maybe.h +0 -713
- package/inc/util/generic/maybe_traits.h +0 -164
- package/inc/util/generic/mem_copy.h +0 -55
- package/inc/util/generic/noncopyable.h +0 -38
- package/inc/util/generic/object_counter.h +0 -53
- package/inc/util/generic/ptr.h +0 -1113
- package/inc/util/generic/queue.h +0 -57
- package/inc/util/generic/refcount.h +0 -162
- package/inc/util/generic/reserve.h +0 -11
- package/inc/util/generic/scope.h +0 -65
- package/inc/util/generic/serialized_enum.h +0 -406
- package/inc/util/generic/set.h +0 -42
- package/inc/util/generic/singleton.h +0 -136
- package/inc/util/generic/size_literals.h +0 -65
- package/inc/util/generic/stack.h +0 -18
- package/inc/util/generic/store_policy.h +0 -120
- package/inc/util/generic/strbase.h +0 -612
- package/inc/util/generic/strbuf.h +0 -552
- package/inc/util/generic/strfcpy.h +0 -17
- package/inc/util/generic/string.h +0 -1572
- package/inc/util/generic/string_hash.h +0 -21
- package/inc/util/generic/string_ut.h +0 -1175
- package/inc/util/generic/type_name.h +0 -34
- package/inc/util/generic/typelist.h +0 -114
- package/inc/util/generic/typetraits.h +0 -325
- package/inc/util/generic/utility.h +0 -132
- package/inc/util/generic/va_args.h +0 -400
- package/inc/util/generic/variant.h +0 -631
- package/inc/util/generic/variant_traits.h +0 -171
- package/inc/util/generic/vector.h +0 -119
- package/inc/util/generic/xrange.h +0 -258
- package/inc/util/generic/yexception.h +0 -212
- package/inc/util/generic/yexception_ut.h +0 -14
- package/inc/util/generic/ylimits.h +0 -92
- package/inc/util/generic/ymath.h +0 -206
- package/inc/util/memory/addstorage.h +0 -93
- package/inc/util/memory/alloc.h +0 -27
- package/inc/util/memory/blob.h +0 -296
- package/inc/util/memory/mmapalloc.h +0 -8
- package/inc/util/memory/pool.h +0 -432
- package/inc/util/memory/segmented_string_pool.h +0 -194
- package/inc/util/memory/segpool_alloc.h +0 -118
- package/inc/util/memory/smallobj.h +0 -141
- package/inc/util/memory/tempbuf.h +0 -111
- package/inc/util/network/address.h +0 -136
- package/inc/util/network/endpoint.h +0 -61
- package/inc/util/network/hostip.h +0 -16
- package/inc/util/network/init.h +0 -60
- package/inc/util/network/interface.h +0 -17
- package/inc/util/network/iovec.h +0 -65
- package/inc/util/network/ip.h +0 -116
- package/inc/util/network/nonblock.h +0 -8
- package/inc/util/network/pair.h +0 -9
- package/inc/util/network/poller.h +0 -58
- package/inc/util/network/pollerimpl.h +0 -707
- package/inc/util/network/sock.h +0 -608
- package/inc/util/network/socket.h +0 -421
- package/inc/util/random/common_ops.h +0 -130
- package/inc/util/random/easy.h +0 -47
- package/inc/util/random/entropy.h +0 -21
- package/inc/util/random/fast.h +0 -101
- package/inc/util/random/init_atfork.h +0 -3
- package/inc/util/random/lcg_engine.h +0 -66
- package/inc/util/random/mersenne.h +0 -46
- package/inc/util/random/mersenne32.h +0 -50
- package/inc/util/random/mersenne64.h +0 -50
- package/inc/util/random/normal.h +0 -38
- package/inc/util/random/random.h +0 -30
- package/inc/util/random/shuffle.h +0 -39
- package/inc/util/str_stl.h +0 -266
- package/inc/util/stream/aligned.h +0 -99
- package/inc/util/stream/buffer.h +0 -119
- package/inc/util/stream/buffered.h +0 -225
- package/inc/util/stream/debug.h +0 -53
- package/inc/util/stream/direct_io.h +0 -43
- package/inc/util/stream/file.h +0 -108
- package/inc/util/stream/format.h +0 -444
- package/inc/util/stream/fwd.h +0 -100
- package/inc/util/stream/hex.h +0 -8
- package/inc/util/stream/holder.h +0 -44
- package/inc/util/stream/input.h +0 -273
- package/inc/util/stream/labeled.h +0 -19
- package/inc/util/stream/length.h +0 -100
- package/inc/util/stream/mem.h +0 -255
- package/inc/util/stream/multi.h +0 -32
- package/inc/util/stream/null.h +0 -61
- package/inc/util/stream/output.h +0 -304
- package/inc/util/stream/pipe.h +0 -112
- package/inc/util/stream/printf.h +0 -25
- package/inc/util/stream/str.h +0 -207
- package/inc/util/stream/tee.h +0 -28
- package/inc/util/stream/tempbuf.h +0 -21
- package/inc/util/stream/tokenizer.h +0 -214
- package/inc/util/stream/trace.h +0 -60
- package/inc/util/stream/walk.h +0 -35
- package/inc/util/stream/zerocopy.h +0 -91
- package/inc/util/stream/zerocopy_output.h +0 -57
- package/inc/util/stream/zlib.h +0 -173
- package/inc/util/string/ascii.h +0 -236
- package/inc/util/string/builder.h +0 -39
- package/inc/util/string/cast.h +0 -347
- package/inc/util/string/cstriter.h +0 -14
- package/inc/util/string/escape.h +0 -70
- package/inc/util/string/hex.h +0 -59
- package/inc/util/string/join.h +0 -194
- package/inc/util/string/printf.h +0 -13
- package/inc/util/string/reverse.h +0 -16
- package/inc/util/string/split.h +0 -1080
- package/inc/util/string/strip.h +0 -257
- package/inc/util/string/strspn.h +0 -65
- package/inc/util/string/subst.h +0 -56
- package/inc/util/string/type.h +0 -50
- package/inc/util/string/util.h +0 -195
- package/inc/util/string/vector.h +0 -132
- package/inc/util/system/align.h +0 -50
- package/inc/util/system/atexit.h +0 -22
- package/inc/util/system/atomic.h +0 -51
- package/inc/util/system/atomic_gcc.h +0 -90
- package/inc/util/system/atomic_ops.h +0 -189
- package/inc/util/system/atomic_win.h +0 -114
- package/inc/util/system/backtrace.h +0 -39
- package/inc/util/system/byteorder.h +0 -186
- package/inc/util/system/compat.h +0 -84
- package/inc/util/system/compiler.h +0 -620
- package/inc/util/system/condvar.h +0 -71
- package/inc/util/system/context.h +0 -181
- package/inc/util/system/context_aarch64.h +0 -8
- package/inc/util/system/context_i686.h +0 -9
- package/inc/util/system/context_x86.h +0 -12
- package/inc/util/system/context_x86_64.h +0 -7
- package/inc/util/system/cpu_id.h +0 -159
- package/inc/util/system/daemon.h +0 -28
- package/inc/util/system/datetime.h +0 -98
- package/inc/util/system/defaults.h +0 -149
- package/inc/util/system/demangle.h +0 -5
- package/inc/util/system/demangle_impl.h +0 -23
- package/inc/util/system/direct_io.h +0 -71
- package/inc/util/system/dynlib.h +0 -119
- package/inc/util/system/env.h +0 -32
- package/inc/util/system/error.h +0 -95
- package/inc/util/system/event.h +0 -122
- package/inc/util/system/execpath.h +0 -17
- package/inc/util/system/fasttime.h +0 -6
- package/inc/util/system/fhandle.h +0 -27
- package/inc/util/system/file.h +0 -210
- package/inc/util/system/file_lock.h +0 -34
- package/inc/util/system/filemap.h +0 -383
- package/inc/util/system/flock.h +0 -35
- package/inc/util/system/fs.h +0 -156
- package/inc/util/system/fs_win.h +0 -29
- package/inc/util/system/fstat.h +0 -46
- package/inc/util/system/getpid.h +0 -12
- package/inc/util/system/guard.h +0 -179
- package/inc/util/system/hi_lo.h +0 -139
- package/inc/util/system/hostname.h +0 -10
- package/inc/util/system/hp_timer.h +0 -36
- package/inc/util/system/info.h +0 -12
- package/inc/util/system/interrupt_signals.h +0 -22
- package/inc/util/system/madvise.h +0 -30
- package/inc/util/system/maxlen.h +0 -32
- package/inc/util/system/mem_info.h +0 -18
- package/inc/util/system/mincore.h +0 -38
- package/inc/util/system/mktemp.h +0 -11
- package/inc/util/system/mlock.h +0 -43
- package/inc/util/system/mutex.h +0 -67
- package/inc/util/system/nice.h +0 -3
- package/inc/util/system/pipe.h +0 -90
- package/inc/util/system/platform.h +0 -246
- package/inc/util/system/progname.h +0 -13
- package/inc/util/system/protect.h +0 -25
- package/inc/util/system/rusage.h +0 -26
- package/inc/util/system/rwlock.h +0 -78
- package/inc/util/system/sanitizers.h +0 -122
- package/inc/util/system/sem.h +0 -41
- package/inc/util/system/shellcommand.h +0 -472
- package/inc/util/system/shmat.h +0 -32
- package/inc/util/system/sigset.h +0 -78
- package/inc/util/system/spin_wait.h +0 -10
- package/inc/util/system/spinlock.h +0 -121
- package/inc/util/system/src_location.h +0 -25
- package/inc/util/system/src_root.h +0 -68
- package/inc/util/system/sys_alloc.h +0 -43
- package/inc/util/system/sysstat.h +0 -52
- package/inc/util/system/tempfile.h +0 -34
- package/inc/util/system/thread.h +0 -167
- package/inc/util/system/tls.h +0 -307
- package/inc/util/system/types.h +0 -119
- package/inc/util/system/unaligned_mem.h +0 -67
- package/inc/util/system/user.h +0 -5
- package/inc/util/system/utime.h +0 -6
- package/inc/util/system/valgrind.h +0 -48
- package/inc/util/system/winint.h +0 -43
- package/inc/util/system/yassert.h +0 -121
- package/inc/util/system/yield.h +0 -4
- package/inc/util/thread/factory.h +0 -65
- package/inc/util/thread/fwd.h +0 -30
- package/inc/util/thread/lfqueue.h +0 -406
- package/inc/util/thread/lfstack.h +0 -188
- package/inc/util/thread/pool.h +0 -388
- package/inc/util/thread/singleton.h +0 -42
- package/inc/util/ysafeptr.h +0 -427
- package/inc/util/ysaveload.h +0 -700
|
@@ -1,459 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "ylimits.h"
|
|
4
|
-
#include "typelist.h"
|
|
5
|
-
|
|
6
|
-
#include <util/system/compiler.h>
|
|
7
|
-
#include <util/system/yassert.h>
|
|
8
|
-
|
|
9
|
-
#ifdef _MSC_VER
|
|
10
|
-
#include <intrin.h>
|
|
11
|
-
#endif
|
|
12
|
-
|
|
13
|
-
namespace NBitOps {
|
|
14
|
-
namespace NPrivate {
|
|
15
|
-
template <unsigned N, typename T>
|
|
16
|
-
struct TClp2Helper {
|
|
17
|
-
static Y_FORCE_INLINE T Calc(T t) noexcept {
|
|
18
|
-
const T prev = TClp2Helper<N / 2, T>::Calc(t);
|
|
19
|
-
|
|
20
|
-
return prev | (prev >> N);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
template <typename T>
|
|
25
|
-
struct TClp2Helper<0u, T> {
|
|
26
|
-
static Y_FORCE_INLINE T Calc(T t) noexcept {
|
|
27
|
-
return t - 1;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
extern const ui64 WORD_MASK[];
|
|
32
|
-
extern const ui64 INVERSE_WORD_MASK[];
|
|
33
|
-
|
|
34
|
-
// see http://www-graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
|
|
35
|
-
|
|
36
|
-
Y_FORCE_INLINE ui64 SwapOddEvenBits(ui64 v) {
|
|
37
|
-
return ((v >> 1ULL) & 0x5555555555555555ULL) | ((v & 0x5555555555555555ULL) << 1ULL);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
Y_FORCE_INLINE ui64 SwapBitPairs(ui64 v) {
|
|
41
|
-
return ((v >> 2ULL) & 0x3333333333333333ULL) | ((v & 0x3333333333333333ULL) << 2ULL);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
Y_FORCE_INLINE ui64 SwapNibbles(ui64 v) {
|
|
45
|
-
return ((v >> 4ULL) & 0x0F0F0F0F0F0F0F0FULL) | ((v & 0x0F0F0F0F0F0F0F0FULL) << 4ULL);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
Y_FORCE_INLINE ui64 SwapOddEvenBytes(ui64 v) {
|
|
49
|
-
return ((v >> 8ULL) & 0x00FF00FF00FF00FFULL) | ((v & 0x00FF00FF00FF00FFULL) << 8ULL);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
Y_FORCE_INLINE ui64 SwapBytePairs(ui64 v) {
|
|
53
|
-
return ((v >> 16ULL) & 0x0000FFFF0000FFFFULL) | ((v & 0x0000FFFF0000FFFFULL) << 16ULL);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Y_FORCE_INLINE ui64 SwapByteQuads(ui64 v) {
|
|
57
|
-
return (v >> 32ULL) | (v << 32ULL);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
#if defined(__GNUC__)
|
|
61
|
-
inline unsigned GetValueBitCountImpl(unsigned int value) noexcept {
|
|
62
|
-
Y_ASSERT(value); // because __builtin_clz* have undefined result for zero.
|
|
63
|
-
return std::numeric_limits<unsigned int>::digits - __builtin_clz(value);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
inline unsigned GetValueBitCountImpl(unsigned long value) noexcept {
|
|
67
|
-
Y_ASSERT(value); // because __builtin_clz* have undefined result for zero.
|
|
68
|
-
return std::numeric_limits<unsigned long>::digits - __builtin_clzl(value);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
inline unsigned GetValueBitCountImpl(unsigned long long value) noexcept {
|
|
72
|
-
Y_ASSERT(value); // because __builtin_clz* have undefined result for zero.
|
|
73
|
-
return std::numeric_limits<unsigned long long>::digits - __builtin_clzll(value);
|
|
74
|
-
}
|
|
75
|
-
#else
|
|
76
|
-
/// Stupid realization for non-GCC. Can use BSR from x86 instructions set.
|
|
77
|
-
template <typename T>
|
|
78
|
-
inline unsigned GetValueBitCountImpl(T value) noexcept {
|
|
79
|
-
Y_ASSERT(value); // because __builtin_clz* have undefined result for zero.
|
|
80
|
-
unsigned result = 1; // result == 0 - impossible value, see Y_ASSERT().
|
|
81
|
-
value >>= 1;
|
|
82
|
-
while (value) {
|
|
83
|
-
value >>= 1;
|
|
84
|
-
++result;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
#endif
|
|
90
|
-
|
|
91
|
-
#if defined(__GNUC__)
|
|
92
|
-
inline unsigned CountTrailingZeroBitsImpl(unsigned int value) noexcept {
|
|
93
|
-
Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero.
|
|
94
|
-
return __builtin_ctz(value);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
inline unsigned CountTrailingZeroBitsImpl(unsigned long value) noexcept {
|
|
98
|
-
Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero.
|
|
99
|
-
return __builtin_ctzl(value);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
inline unsigned CountTrailingZeroBitsImpl(unsigned long long value) noexcept {
|
|
103
|
-
Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero.
|
|
104
|
-
return __builtin_ctzll(value);
|
|
105
|
-
}
|
|
106
|
-
#else
|
|
107
|
-
/// Stupid realization for non-GCC. Can use BSF from x86 instructions set.
|
|
108
|
-
template <typename T>
|
|
109
|
-
inline unsigned CountTrailingZeroBitsImpl(T value) noexcept {
|
|
110
|
-
Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero.
|
|
111
|
-
unsigned result = 0;
|
|
112
|
-
while (!(value & 1)) {
|
|
113
|
-
value >>= 1;
|
|
114
|
-
++result;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
#endif
|
|
120
|
-
|
|
121
|
-
template <typename T>
|
|
122
|
-
Y_FORCE_INLINE T RotateBitsLeftImpl(T value, const ui8 shift) noexcept {
|
|
123
|
-
constexpr ui8 bits = sizeof(T) * 8;
|
|
124
|
-
constexpr ui8 mask = bits - 1;
|
|
125
|
-
Y_ASSERT(shift <= mask);
|
|
126
|
-
|
|
127
|
-
// do trick with mask to avoid undefined behaviour
|
|
128
|
-
return (value << shift) | (value >> ((-shift) & mask));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
template <typename T>
|
|
132
|
-
Y_FORCE_INLINE T RotateBitsRightImpl(T value, const ui8 shift) noexcept {
|
|
133
|
-
constexpr ui8 bits = sizeof(T) * 8;
|
|
134
|
-
constexpr ui8 mask = bits - 1;
|
|
135
|
-
Y_ASSERT(shift <= mask);
|
|
136
|
-
|
|
137
|
-
// do trick with mask to avoid undefined behaviour
|
|
138
|
-
return (value >> shift) | (value << ((-shift) & mask));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
#if defined(_x86_) && defined(__GNUC__)
|
|
142
|
-
Y_FORCE_INLINE ui8 RotateBitsRightImpl(ui8 value, ui8 shift) noexcept {
|
|
143
|
-
__asm__("rorb %%cl, %0"
|
|
144
|
-
: "=r"(value)
|
|
145
|
-
: "0"(value), "c"(shift));
|
|
146
|
-
return value;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
Y_FORCE_INLINE ui16 RotateBitsRightImpl(ui16 value, ui8 shift) noexcept {
|
|
150
|
-
__asm__("rorw %%cl, %0"
|
|
151
|
-
: "=r"(value)
|
|
152
|
-
: "0"(value), "c"(shift));
|
|
153
|
-
return value;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
Y_FORCE_INLINE ui32 RotateBitsRightImpl(ui32 value, ui8 shift) noexcept {
|
|
157
|
-
__asm__("rorl %%cl, %0"
|
|
158
|
-
: "=r"(value)
|
|
159
|
-
: "0"(value), "c"(shift));
|
|
160
|
-
return value;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
Y_FORCE_INLINE ui8 RotateBitsLeftImpl(ui8 value, ui8 shift) noexcept {
|
|
164
|
-
__asm__("rolb %%cl, %0"
|
|
165
|
-
: "=r"(value)
|
|
166
|
-
: "0"(value), "c"(shift));
|
|
167
|
-
return value;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
Y_FORCE_INLINE ui16 RotateBitsLeftImpl(ui16 value, ui8 shift) noexcept {
|
|
171
|
-
__asm__("rolw %%cl, %0"
|
|
172
|
-
: "=r"(value)
|
|
173
|
-
: "0"(value), "c"(shift));
|
|
174
|
-
return value;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
Y_FORCE_INLINE ui32 RotateBitsLeftImpl(ui32 value, ui8 shift) noexcept {
|
|
178
|
-
__asm__("roll %%cl, %0"
|
|
179
|
-
: "=r"(value)
|
|
180
|
-
: "0"(value), "c"(shift));
|
|
181
|
-
return value;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
#if defined(_x86_64_)
|
|
185
|
-
Y_FORCE_INLINE ui64 RotateBitsRightImpl(ui64 value, ui8 shift) noexcept {
|
|
186
|
-
__asm__("rorq %%cl, %0"
|
|
187
|
-
: "=r"(value)
|
|
188
|
-
: "0"(value), "c"(shift));
|
|
189
|
-
return value;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
Y_FORCE_INLINE ui64 RotateBitsLeftImpl(ui64 value, ui8 shift) noexcept {
|
|
193
|
-
__asm__("rolq %%cl, %0"
|
|
194
|
-
: "=r"(value)
|
|
195
|
-
: "0"(value), "c"(shift));
|
|
196
|
-
return value;
|
|
197
|
-
}
|
|
198
|
-
#endif
|
|
199
|
-
#endif
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Computes the next power of 2 higher or equal to the integer parameter `t`.
|
|
205
|
-
* If `t` is a power of 2 will return `t`.
|
|
206
|
-
* Result is undefined for `t == 0`.
|
|
207
|
-
*/
|
|
208
|
-
template <typename T>
|
|
209
|
-
static inline T FastClp2(T t) noexcept {
|
|
210
|
-
Y_ASSERT(t > 0);
|
|
211
|
-
using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
|
|
212
|
-
return 1 + ::NBitOps::NPrivate::TClp2Helper<sizeof(TCvt) * 4, T>::Calc(static_cast<TCvt>(t));
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Check if integer is a power of 2.
|
|
217
|
-
*/
|
|
218
|
-
template <typename T>
|
|
219
|
-
static inline constexpr bool IsPowerOf2(T v) noexcept {
|
|
220
|
-
return v > 0 && (v & (v - 1)) == 0;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Returns the number of leading 0-bits in `value`, starting at the most significant bit position.
|
|
225
|
-
*/
|
|
226
|
-
template <typename T>
|
|
227
|
-
static inline unsigned GetValueBitCount(T value) noexcept {
|
|
228
|
-
Y_ASSERT(value > 0);
|
|
229
|
-
using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
|
|
230
|
-
return ::NBitOps::NPrivate::GetValueBitCountImpl(static_cast<TCvt>(value));
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Returns the number of trailing 0-bits in `value`, starting at the least significant bit position
|
|
235
|
-
*/
|
|
236
|
-
template <typename T>
|
|
237
|
-
static inline unsigned CountTrailingZeroBits(T value) noexcept {
|
|
238
|
-
Y_ASSERT(value > 0);
|
|
239
|
-
using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
|
|
240
|
-
return ::NBitOps::NPrivate::CountTrailingZeroBitsImpl(static_cast<TCvt>(value));
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/*
|
|
244
|
-
* Returns 64-bit mask with `bits` lower bits set.
|
|
245
|
-
*/
|
|
246
|
-
Y_FORCE_INLINE ui64 MaskLowerBits(ui64 bits) {
|
|
247
|
-
return ::NBitOps::NPrivate::WORD_MASK[bits];
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/*
|
|
251
|
-
* Return 64-bit mask with `bits` set starting from `skipbits`.
|
|
252
|
-
*/
|
|
253
|
-
Y_FORCE_INLINE ui64 MaskLowerBits(ui64 bits, ui64 skipbits) {
|
|
254
|
-
return MaskLowerBits(bits) << skipbits;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/*
|
|
258
|
-
* Return 64-bit mask with all bits set except for `bits` lower bits.
|
|
259
|
-
*/
|
|
260
|
-
Y_FORCE_INLINE ui64 InverseMaskLowerBits(ui64 bits) {
|
|
261
|
-
return ::NBitOps::NPrivate::INVERSE_WORD_MASK[bits];
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/*
|
|
265
|
-
* Return 64-bit mask with all bits set except for `bits` bitst starting from `skipbits`.
|
|
266
|
-
*/
|
|
267
|
-
Y_FORCE_INLINE ui64 InverseMaskLowerBits(ui64 bits, ui64 skipbits) {
|
|
268
|
-
return ~MaskLowerBits(bits, skipbits);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/*
|
|
272
|
-
* Returns 0-based position of the most significant bit that is set. 0 for 0.
|
|
273
|
-
*/
|
|
274
|
-
Y_FORCE_INLINE ui64 MostSignificantBit(ui64 v) {
|
|
275
|
-
#ifdef __GNUC__
|
|
276
|
-
ui64 res = v ? (63 - __builtin_clzll(v)) : 0;
|
|
277
|
-
#elif defined(_MSC_VER) && defined(_64_)
|
|
278
|
-
unsigned long res = 0;
|
|
279
|
-
if (v)
|
|
280
|
-
_BitScanReverse64(&res, v);
|
|
281
|
-
#else
|
|
282
|
-
ui64 res = 0;
|
|
283
|
-
if (v)
|
|
284
|
-
while (v >>= 1)
|
|
285
|
-
++res;
|
|
286
|
-
#endif
|
|
287
|
-
return res;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Returns 0-based position of the least significant bit that is set. 0 for 0.
|
|
292
|
-
*/
|
|
293
|
-
Y_FORCE_INLINE ui64 LeastSignificantBit(ui64 v) {
|
|
294
|
-
#ifdef __GNUC__
|
|
295
|
-
ui64 res = v ? __builtin_ffsll(v) - 1 : 0;
|
|
296
|
-
#elif defined(_MSC_VER) && defined(_64_)
|
|
297
|
-
unsigned long res = 0;
|
|
298
|
-
if (v)
|
|
299
|
-
_BitScanForward64(&res, v);
|
|
300
|
-
#else
|
|
301
|
-
ui64 res = 0;
|
|
302
|
-
if (v) {
|
|
303
|
-
while (!(v & 1)) {
|
|
304
|
-
++res;
|
|
305
|
-
v >>= 1;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
#endif
|
|
309
|
-
return res;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/*
|
|
313
|
-
* Returns 0 - based position of the most significant bit (compile time)
|
|
314
|
-
* 0 for 0.
|
|
315
|
-
*/
|
|
316
|
-
constexpr ui64 MostSignificantBitCT(ui64 x) {
|
|
317
|
-
return x > 1 ? 1 + MostSignificantBitCT(x >> 1) : 0;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/*
|
|
321
|
-
* Return rounded up binary logarithm of `x`.
|
|
322
|
-
*/
|
|
323
|
-
Y_FORCE_INLINE ui8 CeilLog2(ui64 x) {
|
|
324
|
-
return static_cast<ui8>(MostSignificantBit(x - 1)) + 1;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
Y_FORCE_INLINE ui8 ReverseBytes(ui8 t) {
|
|
328
|
-
return t;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
Y_FORCE_INLINE ui16 ReverseBytes(ui16 t) {
|
|
332
|
-
return static_cast<ui16>(::NBitOps::NPrivate::SwapOddEvenBytes(t));
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
Y_FORCE_INLINE ui32 ReverseBytes(ui32 t) {
|
|
336
|
-
return static_cast<ui32>(::NBitOps::NPrivate::SwapBytePairs(
|
|
337
|
-
::NBitOps::NPrivate::SwapOddEvenBytes(t)));
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
Y_FORCE_INLINE ui64 ReverseBytes(ui64 t) {
|
|
341
|
-
return ::NBitOps::NPrivate::SwapByteQuads((::NBitOps::NPrivate::SwapOddEvenBytes(t)));
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
Y_FORCE_INLINE ui8 ReverseBits(ui8 t) {
|
|
345
|
-
return static_cast<ui8>(::NBitOps::NPrivate::SwapNibbles(
|
|
346
|
-
::NBitOps::NPrivate::SwapBitPairs(
|
|
347
|
-
::NBitOps::NPrivate::SwapOddEvenBits(t))));
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
Y_FORCE_INLINE ui16 ReverseBits(ui16 t) {
|
|
351
|
-
return static_cast<ui16>(::NBitOps::NPrivate::SwapOddEvenBytes(
|
|
352
|
-
::NBitOps::NPrivate::SwapNibbles(
|
|
353
|
-
::NBitOps::NPrivate::SwapBitPairs(
|
|
354
|
-
::NBitOps::NPrivate::SwapOddEvenBits(t)))));
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
Y_FORCE_INLINE ui32 ReverseBits(ui32 t) {
|
|
358
|
-
return static_cast<ui32>(::NBitOps::NPrivate::SwapBytePairs(
|
|
359
|
-
::NBitOps::NPrivate::SwapOddEvenBytes(
|
|
360
|
-
::NBitOps::NPrivate::SwapNibbles(
|
|
361
|
-
::NBitOps::NPrivate::SwapBitPairs(
|
|
362
|
-
::NBitOps::NPrivate::SwapOddEvenBits(t))))));
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
Y_FORCE_INLINE ui64 ReverseBits(ui64 t) {
|
|
366
|
-
return ::NBitOps::NPrivate::SwapByteQuads(
|
|
367
|
-
::NBitOps::NPrivate::SwapBytePairs(
|
|
368
|
-
::NBitOps::NPrivate::SwapOddEvenBytes(
|
|
369
|
-
::NBitOps::NPrivate::SwapNibbles(
|
|
370
|
-
::NBitOps::NPrivate::SwapBitPairs(
|
|
371
|
-
::NBitOps::NPrivate::SwapOddEvenBits(t))))));
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/*
|
|
375
|
-
* Reverse first `bits` bits
|
|
376
|
-
* 1000111000111000 , bits = 6 => 1000111000000111
|
|
377
|
-
*/
|
|
378
|
-
template <typename T>
|
|
379
|
-
Y_FORCE_INLINE T ReverseBits(T v, ui64 bits) {
|
|
380
|
-
return bits ? (T(v & ::InverseMaskLowerBits(bits)) | T(ReverseBits(T(v & ::MaskLowerBits(bits)))) >> ((ui64{sizeof(T)} << ui64{3}) - bits)) : v;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/*
|
|
384
|
-
* Referse first `bits` bits starting from `skipbits` bits
|
|
385
|
-
* 1000111000111000 , bits = 4, skipbits = 2 => 1000111000011100
|
|
386
|
-
*/
|
|
387
|
-
template <typename T>
|
|
388
|
-
Y_FORCE_INLINE T ReverseBits(T v, ui64 bits, ui64 skipbits) {
|
|
389
|
-
return (T(ReverseBits((v >> skipbits), bits)) << skipbits) | T(v & MaskLowerBits(skipbits));
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/* Rotate bits left. Also known as left circular shift.
|
|
393
|
-
*/
|
|
394
|
-
template <typename T>
|
|
395
|
-
Y_FORCE_INLINE T RotateBitsLeft(T value, const ui8 shift) noexcept {
|
|
396
|
-
static_assert(std::is_unsigned<T>::value, "must be unsigned arithmetic type");
|
|
397
|
-
return ::NBitOps::NPrivate::RotateBitsLeftImpl((TFixedWidthUnsignedInt<T>)value, shift);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/* Rotate bits right. Also known as right circular shift.
|
|
401
|
-
*/
|
|
402
|
-
template <typename T>
|
|
403
|
-
Y_FORCE_INLINE T RotateBitsRight(T value, const ui8 shift) noexcept {
|
|
404
|
-
static_assert(std::is_unsigned<T>::value, "must be unsigned arithmetic type");
|
|
405
|
-
return ::NBitOps::NPrivate::RotateBitsRightImpl((TFixedWidthUnsignedInt<T>)value, shift);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/* Rotate bits left. Also known as left circular shift.
|
|
409
|
-
*/
|
|
410
|
-
template <typename T>
|
|
411
|
-
constexpr T RotateBitsLeftCT(T value, const ui8 shift) noexcept {
|
|
412
|
-
static_assert(std::is_unsigned<T>::value, "must be unsigned arithmetic type");
|
|
413
|
-
|
|
414
|
-
// do trick with mask to avoid undefined behaviour
|
|
415
|
-
return (value << shift) | (value >> ((-shift) & (sizeof(T) * 8 - 1)));
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/* Rotate bits right. Also known as right circular shift.
|
|
419
|
-
*/
|
|
420
|
-
template <typename T>
|
|
421
|
-
constexpr T RotateBitsRightCT(T value, const ui8 shift) noexcept {
|
|
422
|
-
static_assert(std::is_unsigned<T>::value, "must be unsigned arithmetic type");
|
|
423
|
-
|
|
424
|
-
// do trick with mask to avoid undefined behaviour
|
|
425
|
-
return (value >> shift) | (value << ((-shift) & (sizeof(T) * 8 - 1)));
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/* Remain `size` bits to current `offset` of `value`
|
|
429
|
-
size, offset are less than number of bits in size_type
|
|
430
|
-
*/
|
|
431
|
-
template <size_t Offset, size_t Size, class T>
|
|
432
|
-
Y_FORCE_INLINE T SelectBits(T value) {
|
|
433
|
-
static_assert(Size < sizeof(T) * 8, "violated: Size < sizeof(T) * 8");
|
|
434
|
-
static_assert(Offset < sizeof(T) * 8, "violated: Offset < sizeof(T) * 8");
|
|
435
|
-
T id = 1;
|
|
436
|
-
return (value >> Offset) & ((id << Size) - id);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/* Set `size` bits of `bits` to current offset of `value`. Requires that bits <= (1 << size) - 1
|
|
440
|
-
size, offset are less than number of bits in size_type
|
|
441
|
-
*/
|
|
442
|
-
template <size_t Offset, size_t Size, class T>
|
|
443
|
-
void SetBits(T& value, T bits) {
|
|
444
|
-
static_assert(Size < sizeof(T) * 8, "violated: Size < sizeof(T) * 8");
|
|
445
|
-
static_assert(Offset < sizeof(T) * 8, "violated: Offset < sizeof(T) * 8");
|
|
446
|
-
T id = 1;
|
|
447
|
-
T maxValue = ((id << Size) - id);
|
|
448
|
-
Y_ASSERT(bits <= maxValue);
|
|
449
|
-
value &= ~(maxValue << Offset);
|
|
450
|
-
value |= bits << Offset;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
inline constexpr ui64 NthBit64(int bit) {
|
|
454
|
-
return ui64(1) << bit;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
inline constexpr ui64 Mask64(int bits) {
|
|
458
|
-
return NthBit64(bits) - 1;
|
|
459
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <utility>
|
|
4
|
-
#include "yexception.h"
|
|
5
|
-
|
|
6
|
-
#include <util/system/backtrace.h>
|
|
7
|
-
|
|
8
|
-
template <class T>
|
|
9
|
-
class TWithBackTrace: public T {
|
|
10
|
-
public:
|
|
11
|
-
template <typename... Args>
|
|
12
|
-
inline TWithBackTrace(Args&&... args)
|
|
13
|
-
: T(std::forward<Args>(args)...)
|
|
14
|
-
{
|
|
15
|
-
BT_.Capture();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const TBackTrace* BackTrace() const noexcept override {
|
|
19
|
-
return &BT_;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
private:
|
|
23
|
-
TBackTrace BT_;
|
|
24
|
-
};
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "utility.h"
|
|
4
|
-
|
|
5
|
-
#include <util/generic/fwd.h>
|
|
6
|
-
#include <util/system/align.h>
|
|
7
|
-
#include <util/system/yassert.h>
|
|
8
|
-
|
|
9
|
-
#include <cstring>
|
|
10
|
-
|
|
11
|
-
class TBuffer {
|
|
12
|
-
public:
|
|
13
|
-
using TIterator = char*;
|
|
14
|
-
using TConstIterator = const char*;
|
|
15
|
-
|
|
16
|
-
TBuffer(size_t len = 0);
|
|
17
|
-
TBuffer(const char* buf, size_t len);
|
|
18
|
-
|
|
19
|
-
TBuffer(const TBuffer& b)
|
|
20
|
-
: Data_(nullptr)
|
|
21
|
-
, Len_(0)
|
|
22
|
-
, Pos_(0)
|
|
23
|
-
{
|
|
24
|
-
*this = b;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
TBuffer(TBuffer&& b) noexcept;
|
|
28
|
-
|
|
29
|
-
TBuffer& operator=(TBuffer&& b) noexcept;
|
|
30
|
-
|
|
31
|
-
TBuffer& operator=(const TBuffer& b) {
|
|
32
|
-
if (this != &b) {
|
|
33
|
-
Assign(b.Data(), b.Size());
|
|
34
|
-
}
|
|
35
|
-
return *this;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
~TBuffer();
|
|
39
|
-
|
|
40
|
-
inline void Clear() noexcept {
|
|
41
|
-
Pos_ = 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
inline void EraseBack(size_t n) noexcept {
|
|
45
|
-
Y_ASSERT(n <= Pos_);
|
|
46
|
-
Pos_ -= n;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
inline void Reset() noexcept {
|
|
50
|
-
TBuffer().Swap(*this);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
inline void Assign(const char* data, size_t len) {
|
|
54
|
-
Clear();
|
|
55
|
-
Append(data, len);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
inline void Assign(const char* b, const char* e) {
|
|
59
|
-
Assign(b, e - b);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
inline char* Data() noexcept {
|
|
63
|
-
return Data_;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
inline const char* Data() const noexcept {
|
|
67
|
-
return Data_;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
inline char* Pos() noexcept {
|
|
71
|
-
return Data_ + Pos_;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
inline const char* Pos() const noexcept {
|
|
75
|
-
return Data_ + Pos_;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/// Used space in bytes (do not mix with Capacity!)
|
|
79
|
-
inline size_t Size() const noexcept {
|
|
80
|
-
return Pos_;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
Y_PURE_FUNCTION
|
|
84
|
-
inline bool Empty() const noexcept {
|
|
85
|
-
return !Size();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
inline explicit operator bool() const noexcept {
|
|
89
|
-
return Size();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
inline size_t Avail() const noexcept {
|
|
93
|
-
return Len_ - Pos_;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
void Append(const char* buf, size_t len);
|
|
97
|
-
|
|
98
|
-
inline void Append(const char* b, const char* e) {
|
|
99
|
-
Append(b, e - b);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
inline void Append(char ch) {
|
|
103
|
-
if (Len_ == Pos_) {
|
|
104
|
-
Reserve(Len_ + 1);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
*(Data() + Pos_++) = ch;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
void Fill(char ch, size_t len);
|
|
111
|
-
|
|
112
|
-
// Method is useful when first messages from buffer are processed, and
|
|
113
|
-
// the last message in buffer is incomplete, so we need to move partial
|
|
114
|
-
// message to the begin of the buffer and continue filling the buffer
|
|
115
|
-
// from the network.
|
|
116
|
-
inline void Chop(size_t pos, size_t count) {
|
|
117
|
-
const auto end = pos + count;
|
|
118
|
-
Y_ASSERT(end <= Pos_);
|
|
119
|
-
|
|
120
|
-
if (count == 0) {
|
|
121
|
-
return;
|
|
122
|
-
} else if (count == Pos_) {
|
|
123
|
-
Pos_ = 0;
|
|
124
|
-
} else {
|
|
125
|
-
memmove(Data_ + pos, Data_ + end, Pos_ - end);
|
|
126
|
-
Pos_ -= count;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
inline void ChopHead(size_t count) {
|
|
131
|
-
Chop(0U, count);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
inline void Proceed(size_t pos) {
|
|
135
|
-
//Y_ASSERT(pos <= Len_); // see discussion in REVIEW:29021
|
|
136
|
-
Resize(pos);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
inline void Advance(size_t len) {
|
|
140
|
-
Resize(Pos_ + len);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
inline void Reserve(size_t len) {
|
|
144
|
-
if (len > Len_) {
|
|
145
|
-
DoReserve(len);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
inline void ShrinkToFit() {
|
|
150
|
-
if (Pos_ < Len_) {
|
|
151
|
-
Realloc(Pos_);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
inline void Resize(size_t len) {
|
|
156
|
-
Reserve(len);
|
|
157
|
-
Pos_ = len;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
inline size_t Capacity() const noexcept {
|
|
161
|
-
return Len_;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
inline void AlignUp(size_t align, char fillChar = '\0') {
|
|
165
|
-
size_t diff = ::AlignUp(Pos_, align) - Pos_;
|
|
166
|
-
while (diff-- > 0) {
|
|
167
|
-
Append(fillChar);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
inline char* data() noexcept {
|
|
172
|
-
return Data();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
inline const char* data() const noexcept {
|
|
176
|
-
return Data();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
inline size_t size() const noexcept {
|
|
180
|
-
return Size();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
inline void Swap(TBuffer& r) noexcept {
|
|
184
|
-
DoSwap(Data_, r.Data_);
|
|
185
|
-
DoSwap(Len_, r.Len_);
|
|
186
|
-
DoSwap(Pos_, r.Pos_);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/*
|
|
190
|
-
* after this call buffer becomes empty
|
|
191
|
-
*/
|
|
192
|
-
void AsString(TString& s);
|
|
193
|
-
|
|
194
|
-
/*
|
|
195
|
-
* iterator-like interface
|
|
196
|
-
*/
|
|
197
|
-
inline TIterator Begin() noexcept {
|
|
198
|
-
return Data();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
inline TIterator End() noexcept {
|
|
202
|
-
return Begin() + Size();
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
inline TConstIterator Begin() const noexcept {
|
|
206
|
-
return Data();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
inline TConstIterator End() const noexcept {
|
|
210
|
-
return Begin() + Size();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
bool operator==(const TBuffer& other) const noexcept {
|
|
214
|
-
if (Empty()) {
|
|
215
|
-
return other.Empty();
|
|
216
|
-
}
|
|
217
|
-
return Size() == other.Size() && 0 == std::memcmp(Data(), other.Data(), Size());
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
bool operator!=(const TBuffer& other) const noexcept {
|
|
221
|
-
return !(*this == other);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
private:
|
|
225
|
-
void DoReserve(size_t len);
|
|
226
|
-
void Realloc(size_t len);
|
|
227
|
-
|
|
228
|
-
private:
|
|
229
|
-
char* Data_;
|
|
230
|
-
size_t Len_;
|
|
231
|
-
size_t Pos_;
|
|
232
|
-
};
|