aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/util/repeated_field_utils.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/protobuf/util/repeated_field_utils.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/protobuf/util/repeated_field_utils.h')
-rw-r--r--library/cpp/protobuf/util/repeated_field_utils.h128
1 files changed, 64 insertions, 64 deletions
diff --git a/library/cpp/protobuf/util/repeated_field_utils.h b/library/cpp/protobuf/util/repeated_field_utils.h
index c07bd84647..74767eaafe 100644
--- a/library/cpp/protobuf/util/repeated_field_utils.h
+++ b/library/cpp/protobuf/util/repeated_field_utils.h
@@ -6,8 +6,8 @@
template <typename T>
void RemoveRepeatedPtrFieldElement(google::protobuf::RepeatedPtrField<T>* repeated, unsigned index) {
google::protobuf::RepeatedPtrField<T> r;
- Y_ASSERT(index < (unsigned)repeated->size());
- for (unsigned i = 0; i < (unsigned)repeated->size(); ++i) {
+ Y_ASSERT(index < (unsigned)repeated->size());
+ for (unsigned i = 0; i < (unsigned)repeated->size(); ++i) {
if (i == index) {
continue;
}
@@ -17,80 +17,80 @@ void RemoveRepeatedPtrFieldElement(google::protobuf::RepeatedPtrField<T>* repeat
}
namespace NProtoBuf {
- /// Move item to specified position
- template <typename TRepeated>
- static void MoveRepeatedFieldItem(TRepeated* field, size_t indexFrom, size_t indexTo) {
- if (!field->size() || indexFrom >= static_cast<size_t>(field->size()) || indexFrom == indexTo)
- return;
- if (indexTo >= static_cast<size_t>(field->size()))
- indexTo = field->size() - 1;
- if (indexFrom > indexTo) {
- for (size_t i = indexFrom; i > indexTo; --i)
- field->SwapElements(i, i - 1);
- } else {
- for (size_t i = indexFrom; i < indexTo; ++i)
- field->SwapElements(i, i + 1);
- }
- }
+ /// Move item to specified position
+ template <typename TRepeated>
+ static void MoveRepeatedFieldItem(TRepeated* field, size_t indexFrom, size_t indexTo) {
+ if (!field->size() || indexFrom >= static_cast<size_t>(field->size()) || indexFrom == indexTo)
+ return;
+ if (indexTo >= static_cast<size_t>(field->size()))
+ indexTo = field->size() - 1;
+ if (indexFrom > indexTo) {
+ for (size_t i = indexFrom; i > indexTo; --i)
+ field->SwapElements(i, i - 1);
+ } else {
+ for (size_t i = indexFrom; i < indexTo; ++i)
+ field->SwapElements(i, i + 1);
+ }
+ }
- template <typename T>
- static T* InsertRepeatedFieldItem(NProtoBuf::RepeatedPtrField<T>* field, size_t index) {
- T* ret = field->Add();
- MoveRepeatedFieldItem(field, field->size() - 1, index);
- return ret;
+ template <typename T>
+ static T* InsertRepeatedFieldItem(NProtoBuf::RepeatedPtrField<T>* field, size_t index) {
+ T* ret = field->Add();
+ MoveRepeatedFieldItem(field, field->size() - 1, index);
+ return ret;
}
- template <typename TRepeated> // suitable both for RepeatedField and RepeatedPtrField
- static void RemoveRepeatedFieldItem(TRepeated* field, size_t index) {
- if ((int)index >= field->size())
- return;
+ template <typename TRepeated> // suitable both for RepeatedField and RepeatedPtrField
+ static void RemoveRepeatedFieldItem(TRepeated* field, size_t index) {
+ if ((int)index >= field->size())
+ return;
- for (int i = index + 1; i < field->size(); ++i)
- field->SwapElements(i - 1, i);
+ for (int i = index + 1; i < field->size(); ++i)
+ field->SwapElements(i - 1, i);
- field->RemoveLast();
- }
+ field->RemoveLast();
+ }
- template <typename TRepeated, typename TPred> // suitable both for RepeatedField and RepeatedPtrField
- static void RemoveRepeatedFieldItemIf(TRepeated* repeated, TPred p) {
- auto last = std::remove_if(repeated->begin(), repeated->end(), p);
- if (last != repeated->end()) {
- size_t countToRemove = repeated->end() - last;
- while (countToRemove--)
- repeated->RemoveLast();
- }
- }
+ template <typename TRepeated, typename TPred> // suitable both for RepeatedField and RepeatedPtrField
+ static void RemoveRepeatedFieldItemIf(TRepeated* repeated, TPred p) {
+ auto last = std::remove_if(repeated->begin(), repeated->end(), p);
+ if (last != repeated->end()) {
+ size_t countToRemove = repeated->end() - last;
+ while (countToRemove--)
+ repeated->RemoveLast();
+ }
+ }
- namespace NImpl {
- template <typename TRepeated>
- static void ShiftLeft(TRepeated* field, int begIndex, int endIndex, size_t shiftSize) {
- Y_ASSERT(begIndex <= field->size());
- Y_ASSERT(endIndex <= field->size());
- size_t shiftIndex = (int)shiftSize < begIndex ? begIndex - shiftSize : 0;
- for (int i = begIndex; i < endIndex; ++i, ++shiftIndex)
- field->SwapElements(shiftIndex, i);
- }
+ namespace NImpl {
+ template <typename TRepeated>
+ static void ShiftLeft(TRepeated* field, int begIndex, int endIndex, size_t shiftSize) {
+ Y_ASSERT(begIndex <= field->size());
+ Y_ASSERT(endIndex <= field->size());
+ size_t shiftIndex = (int)shiftSize < begIndex ? begIndex - shiftSize : 0;
+ for (int i = begIndex; i < endIndex; ++i, ++shiftIndex)
+ field->SwapElements(shiftIndex, i);
+ }
}
- // Remove several items at once, could be more efficient compared to calling RemoveRepeatedFieldItem several times
+ // Remove several items at once, could be more efficient compared to calling RemoveRepeatedFieldItem several times
template <typename TRepeated>
- static void RemoveRepeatedFieldItems(TRepeated* field, const TVector<size_t>& sortedIndices) {
- if (sortedIndices.empty())
- return;
+ static void RemoveRepeatedFieldItems(TRepeated* field, const TVector<size_t>& sortedIndices) {
+ if (sortedIndices.empty())
+ return;
- size_t shift = 1;
- for (size_t i = 1; i < sortedIndices.size(); ++i, ++shift)
- NImpl::ShiftLeft(field, sortedIndices[i - 1] + 1, sortedIndices[i], shift);
- NImpl::ShiftLeft(field, sortedIndices.back() + 1, field->size(), shift);
+ size_t shift = 1;
+ for (size_t i = 1; i < sortedIndices.size(); ++i, ++shift)
+ NImpl::ShiftLeft(field, sortedIndices[i - 1] + 1, sortedIndices[i], shift);
+ NImpl::ShiftLeft(field, sortedIndices.back() + 1, field->size(), shift);
- for (; shift > 0; --shift)
- field->RemoveLast();
- }
+ for (; shift > 0; --shift)
+ field->RemoveLast();
+ }
- template <typename TRepeated>
- static void ReverseRepeatedFieldItems(TRepeated* field) {
- for (int i1 = 0, i2 = field->size() - 1; i1 < i2; ++i1, --i2)
- field->SwapElements(i1, i2);
- }
+ template <typename TRepeated>
+ static void ReverseRepeatedFieldItems(TRepeated* field) {
+ for (int i1 = 0, i2 = field->size() - 1; i1 < i2; ++i1, --i2)
+ field->SwapElements(i1, i2);
+ }
}