-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathutils.h
58 lines (46 loc) · 1.32 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
#pragma once
#include <util/generic/algorithm.h>
#include <util/generic/bitops.h>
#include <util/generic/vector.h>
#include <google/protobuf/repeated_ptr_field.h>
namespace NCloud::NFileStore::NStorage {
////////////////////////////////////////////////////////////////////////////////
inline bool IsAligned(size_t len, size_t align) noexcept
{
Y_ASSERT(IsPowerOf2(align));
return (len & (align - 1)) == 0;
}
inline ui64 ShardedId(ui64 id, ui32 shardNo)
{
const auto realBits = 56U;
const auto realMask = Max<ui64>() >> (64 - realBits);
Y_DEBUG_ABORT_UNLESS(shardNo < (1UL << (64 - realBits)));
return (static_cast<ui64>(shardNo) << realBits) | (realMask & id);
}
inline ui32 ExtractShardNo(ui64 id)
{
const auto realBits = 56U;
return id >> realBits;
}
template <typename T>
void RemoveByIndices(
google::protobuf::RepeatedPtrField<T>& field,
TVector<ui32>& indices)
{
Sort(indices);
int j = 0;
for (int i = static_cast<int>(indices[0]); i < field.size(); ++i) {
if (j < static_cast<int>(indices.size())
&& i == static_cast<int>(indices[j]))
{
++j;
continue;
}
field[i - j] = std::move(field[i]);
}
while (j) {
field.RemoveLast();
--j;
}
}
} // namespace NCloud::NFileStore::NStorage