Skip to content

Commit c3381aa

Browse files
Translation completed
last steps
1 parent 3b74db1 commit c3381aa

19 files changed

+106
-188
lines changed

cpp/Platform.Collections/Arrays/ArrayFiller[TElement, TReturnConstant].h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@
1010

1111
protected: TReturnConstant _returnConstant;
1212

13-
public: ArrayFiller(TArray& array, std::int64_t offset, auto&& returnConstant) :
14-
ArrayFiller<TArray>(array, offset), _returnConstant(std::forward<decltype(returnConstant)>(returnConstant))
15-
{
16-
}
13+
public: ArrayFiller(TArray& array, std::int64_t offset, auto&& returnConstant) : ArrayFiller<TArray>(array, offset), _returnConstant(std::forward<decltype(returnConstant)>(returnConstant)) { }
1714

18-
public: ArrayFiller(TArray& array, auto&& returnConstant) :
19-
ArrayFiller(array, 0, std::forward<decltype(returnConstant)>(returnConstant))
20-
{
21-
}
15+
public: ArrayFiller(TArray& array, auto&& returnConstant) : ArrayFiller(array, 0, std::forward<decltype(returnConstant)>(returnConstant)) { }
2216

2317
public: TReturnConstant AddAndReturnConstant(auto&& element){ return Arrays::AddAndReturnConstant(base::_array, base::_position, std::forward<decltype(element)>(element), _returnConstant); }
2418

cpp/Platform.Collections/Arrays/ArrayFiller[TElement].h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@
1010
protected: TArray& _array;
1111
protected: std::int64_t _position = 0;
1212

13-
public: ArrayFiller(TArray& array, std::int64_t offset) :
14-
_array(array), _position(offset)
15-
{
16-
}
17-
18-
public: explicit ArrayFiller(TArray& array) :
19-
ArrayFiller(array, 0)
20-
{
21-
}
13+
public: ArrayFiller(TArray& array, std::int64_t offset) : _array(array), _position(offset) { }
14+
15+
public: explicit ArrayFiller(TArray& array) : ArrayFiller(array, 0) { }
2216

2317
public: void Add(auto&& element) { _array[_position++] = std::forward<decltype(element)>(element); }
2418

cpp/Platform.Collections/Arrays/GenericArrayExtensions.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424
}
2525

26-
static Interfaces::IArray auto ShiftRight(const Interfaces::IArray auto& array, std::integral auto shift)
26+
static Interfaces::IArray auto ShiftRight(Interfaces::IArray auto&& array, std::integral auto shift)
2727
{
2828
if (shift < 0)
2929
{
@@ -36,7 +36,6 @@
3636
else
3737
{
3838
using Item = typename Interfaces::Enumerable<decltype(array)>::Item;
39-
// TODO в оригинале возвращает IList, значит и мы так поступим
4039
auto restrictions = std::vector<Item>(std::ranges::size(array) + shift);
4140
std::ranges::copy(array, std::ranges::begin(restrictions) + shift);
4241
return restrictions;
@@ -49,7 +48,7 @@
4948
static void Add(TArray& array, std::integral auto& position, const TItem& element) { array[position++] = element; }
5049

5150
template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
52-
static auto&& AddAndReturnConstant(TArray& array, std::integral auto& position, const TItem& element, const auto& returnConstant)
51+
static auto AddAndReturnConstant(TArray& array, std::integral auto& position, const TItem& element, auto returnConstant)
5352
{
5453
Add(array, position, element);
5554
return returnConstant;
@@ -59,7 +58,7 @@
5958
static void AddFirst(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements) { array[position++] = elements[0]; }
6059

6160
template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
62-
static auto&& AddFirstAndReturnConstant(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements, const auto& returnConstant)
61+
static auto AddFirstAndReturnConstant(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements, auto returnConstant)
6362
{
6463
AddFirst(array, position, elements);
6564
return returnConstant;
@@ -74,12 +73,19 @@
7473
}
7574
}
7675

77-
static auto&& AddAllAndReturnConstant(Interfaces::IArray auto& array, std::integral auto& position, Interfaces::IArray auto&& elements, auto returnConstant)
76+
static auto AddAllAndReturnConstant(Interfaces::IArray auto& array, std::integral auto& position, Interfaces::IArray auto&& elements, auto returnConstant)
7877
{
7978
AddAll(array, position, elements);
8079
return returnConstant;
8180
}
8281

82+
template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
83+
static auto AddSkipFirstAndReturnConstant(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements, auto constant)
84+
{
85+
AddSkipFirst(array, position, elements, 1);
86+
return constant
87+
}
88+
8389
template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
8490
static void AddSkipFirst(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements, std::integral auto skip)
8591
{
@@ -91,11 +97,4 @@
9197

9298
template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
9399
static void AddSkipFirst(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements) { AddSkipFirst(array, position, elements, 1); }
94-
95-
template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
96-
static auto&& AddSkipFirstAndReturnConstant(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements, auto&& constant)
97-
{
98-
AddSkipFirst(array, position, elements, 1);
99-
return std::forward<decltype(constant)>(constant);
100-
}
101100
}// namespace Platform::Collections::Arrays

cpp/Platform.Collections/EnsureExtensions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Platform::Collections::Always
1+
namespace Platform::Collections::Ensure::Always
22
{
33
template<typename T>
44
void ArgumentNotEmpty(Interfaces::IEnumerable auto&& argument, const std::string& argumentName = {}, const std::string& message = {})
@@ -27,7 +27,7 @@
2727
}
2828
}// namespace Platform::Collections::Always
2929

30-
namespace Platform::Collections::Always
30+
namespace Platform::Collections::Ensure::Always
3131
{
3232
static void ArgumentNotEmpty(auto&&... args)
3333
{

cpp/Platform.Collections/IDictionaryExtensions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
{
88
throw std::logic_error("Unknown exception");
99
}
10-
11-
dictionary.insert({std::forward<decltype(key)>(key), std::forward<decltype(value)>(value)});
10+
using Item = typename Interfaces::Dictionary<TDictionary>::Item;
11+
dictionary.insert(Item{std::forward<decltype(key)>(key), std::forward<decltype(value)>(value)});
1212
}
1313

1414
template<Interfaces::IDictionary TDictionary>
@@ -17,7 +17,7 @@
1717
if (!dictionary.contains(key))
1818
{
1919
auto& value = dictionary[key];
20-
value = std::forward<decltype(valueFactory(key))>(valueFactory(key));
20+
value = valueFactory(key);
2121
return value;
2222
}
2323
return dictionary[key];

cpp/Platform.Collections/Lists/IListExtensions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
template<Interfaces::IList TList, typename TItem = typename Interfaces::List<TList>::Item>
7676
static void AddSkipFirst(TList& list, Interfaces::IArray<TItem> auto&& elements, std::integral auto skip)
7777
{
78-
for (const auto& element : elements | std::views::drop(skip))
78+
for (auto&& element : elements | std::views::drop(skip))
7979
{
8080
list.push_back(element);
8181
}

cpp/Platform.Collections/Lists/ListFiller.h

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@
1111

1212
protected: TReturnConstant _returnConstant;
1313

14-
public: ListFiller(TList& list, auto&& returnConstant)
15-
: _list(list), _returnConstant(std::forward<decltype(returnConstant)>(returnConstant))
16-
{
17-
}
14+
public: ListFiller(TList& list, auto&& returnConstant) : _list(list), _returnConstant(std::forward<decltype(returnConstant)>(returnConstant)) { }
1815

19-
public: explicit ListFiller(TList& list)
20-
: ListFiller(list, {})
21-
{
22-
}
16+
public: explicit ListFiller(TList& list) : ListFiller(list, {}) { }
2317

2418
public: void Add(TElement element) { _list.push_back(element); }
2519

@@ -37,40 +31,22 @@
3731
return _returnConstant;
3832
}
3933

40-
public: TReturnConstant AddFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &
41-
{
42-
Lists::AddFirst(_list, elements);
43-
return std::move(_returnConstant);
44-
}
45-
46-
public: TReturnConstant&& AddFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &&
34+
public: TReturnConstant AddFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements)
4735
{
4836
Lists::AddFirst(_list, elements);
49-
return std::move(_returnConstant);
50-
}
51-
52-
public: TReturnConstant AddAllAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &
53-
{
54-
Lists::AddAll(_list, elements);
55-
return std::move(_returnConstant);
37+
return _returnConstant;
5638
}
5739

58-
public: TReturnConstant&& AddAllAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &&
40+
public: TReturnConstant AddAllAndReturnConstant(Interfaces::IArray<TElement> auto&& elements)
5941
{
6042
Lists::AddAll(_list, elements);
61-
return std::move(_returnConstant);
62-
}
63-
64-
public: TReturnConstant AddSkipFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &
65-
{
66-
Lists::AddSkipFirst(_list, elements);
67-
return std::move(_returnConstant);
43+
return _returnConstant;
6844
}
6945

70-
public: TReturnConstant&& AddSkipFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &&
46+
public: TReturnConstant AddSkipFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements)
7147
{
7248
Lists::AddSkipFirst(_list, elements);
73-
return std::move(_returnConstant);
49+
return _returnConstant;
7450
}
7551
};
7652

cpp/Platform.Collections/Segments/Walkers/AllSegmentsWalkerBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
template <typename ...> class AllSegmentsWalkerBase;
44
template<> class AllSegmentsWalkerBase<>
55
{
6-
public: inline static const std::int32_t DefaultMinimumStringSegmentLength = 2;
6+
public: static constexpr std::int32_t DefaultMinimumStringSegmentLength = 2;
77
};
88
}

cpp/Platform.Collections/Segments/Walkers/AllSegmentsWalkerBase[T, TSegment].h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
private: std::int32_t _minimumStringSegmentLength = 0;
99

10-
protected: AllSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) { _minimumStringSegmentLength = minimumStringSegmentLength; }
10+
protected: explicit AllSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) { _minimumStringSegmentLength = minimumStringSegmentLength; }
1111

1212
protected: AllSegmentsWalkerBase() : AllSegmentsWalkerBase(DefaultMinimumStringSegmentLength) { }
1313

@@ -26,6 +26,6 @@
2626

2727
protected: virtual void Iteration(TSegment segment) = 0;
2828

29-
public: virtual ~AllSegmentsWalkerBase() {}
29+
public: virtual ~AllSegmentsWalkerBase() = default;
3030
};
3131
}

cpp/Platform.Collections/Segments/Walkers/AllSegmentsWalkerBase[T].h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
using base = AllSegmentsWalkerBase<T, TArray, std::span<T>>;
88
using TSegment = std::span<T>;
99

10-
protected: AllSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) : base(minimumStringSegmentLength) {}
10+
protected: explicit AllSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) : base(minimumStringSegmentLength) {}
1111

1212
protected: AllSegmentsWalkerBase() : base() { }
1313

1414
protected: TSegment CreateSegment(TArray& elements, std::int32_t offset, std::int32_t length)
1515
{
16-
return std::span<T>(std::ranges::begin(elements) + offset, length);
16+
return std::span(std::ranges::begin(elements) + offset, length);
1717
}
1818
};
1919
}
Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,38 @@
11
namespace Platform::Collections::Segments::Walkers
22
{
33
template <typename ...> class DictionaryBasedDuplicateSegmentsWalkerBase;
4-
template <typename T, Interfaces::IArray TArray, typename TDictionary, typename TSegment>
5-
requires std::derived_from<TSegment, std::span<T>> && Interfaces::IDictionary<TDictionary, TSegment*, int>
4+
template <typename T, Interfaces::IArray TArray, Interfaces::IDictionary TDictionary, typename TSegment>
5+
requires std::derived_from<TSegment, std::span<T>> && Interfaces::IDictionary<TDictionary, int, TSegment>
66
class DictionaryBasedDuplicateSegmentsWalkerBase<T, TArray, TDictionary, TSegment> : public DuplicateSegmentsWalkerBase<T, TArray, TSegment>
77
{
88
using base = DuplicateSegmentsWalkerBase<T, TArray, TSegment>;
99

10-
public: static constexpr bool DefaultResetDictionaryOnEachWalk = false; // change readonly to constexpr
10+
public: static constexpr bool DefaultResetDictionaryOnEachWalk = false;
1111

12-
private: bool _resetDictionaryOnEachWalk = 0;
13-
protected: TDictionary* Dictionary;
12+
private: bool _resetDictionaryOnEachWalk = false;
13+
protected: TDictionary Dictionary;
1414

15-
protected: DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary, std::int32_t minimumStringSegmentLength, bool resetDictionaryOnEachWalk)
16-
: base(minimumStringSegmentLength), Dictionary(dictionary)
17-
{
18-
_resetDictionaryOnEachWalk = resetDictionaryOnEachWalk;
19-
}
15+
protected: DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary, std::int32_t minimumStringSegmentLength, bool resetDictionaryOnEachWalk) : base(minimumStringSegmentLength), Dictionary(dictionary), _resetDictionaryOnEachWalk(resetDictionaryOnEachWalk) { }
2016

21-
protected: DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary, std::int32_t minimumStringSegmentLength)
22-
: DictionaryBasedDuplicateSegmentsWalkerBase(dictionary, minimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
17+
protected: DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary, std::int32_t minimumStringSegmentLength) : DictionaryBasedDuplicateSegmentsWalkerBase(dictionary, minimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
2318

24-
protected: DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary)
25-
: DictionaryBasedDuplicateSegmentsWalkerBase(dictionary, base::DefaultMinimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
19+
protected: explicit DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary) : DictionaryBasedDuplicateSegmentsWalkerBase(std::move(dictionary), base::DefaultMinimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
2620

27-
protected: DictionaryBasedDuplicateSegmentsWalkerBase(std::int32_t minimumStringSegmentLength, bool resetDictionaryOnEachWalk)
28-
: DictionaryBasedDuplicateSegmentsWalkerBase(resetDictionaryOnEachWalk ? nullptr : new TDictionary, minimumStringSegmentLength, resetDictionaryOnEachWalk) { }
21+
protected: DictionaryBasedDuplicateSegmentsWalkerBase(std::int32_t minimumStringSegmentLength, bool resetDictionaryOnEachWalk) : DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary{}, minimumStringSegmentLength, resetDictionaryOnEachWalk) { }
2922

30-
protected: DictionaryBasedDuplicateSegmentsWalkerBase(std::int32_t minimumStringSegmentLength)
31-
: DictionaryBasedDuplicateSegmentsWalkerBase(minimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
23+
protected: explicit DictionaryBasedDuplicateSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) : DictionaryBasedDuplicateSegmentsWalkerBase(minimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
3224

33-
protected: DictionaryBasedDuplicateSegmentsWalkerBase()
34-
: DictionaryBasedDuplicateSegmentsWalkerBase(base::DefaultMinimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
25+
protected: DictionaryBasedDuplicateSegmentsWalkerBase() : DictionaryBasedDuplicateSegmentsWalkerBase(base::DefaultMinimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
3526

36-
public: void WalkAll(TArray elements) override
27+
public: void WalkAll(const TArray& elements) override
3728
{
38-
if constexpr(decltype(*this)::_resetDictionaryOnEachWalk && requires(TDictionary dict, int capacity) {dict(capacity);})
39-
{
40-
auto capacity = std::ceil(std::pow(elements->size(), 2) / 2);
41-
Dictionary = new TDictionary((std::int32_t)capacity);
42-
}
29+
auto capacity = std::ceil(std::pow(std::ranges::size(elements), 2) / 2);
30+
Dictionary = TDictionary(capacity);
4331
base::WalkAll(elements);
4432
}
4533

46-
// TODO см. IDictionaryExtensions.h
47-
protected: std::int64_t GetSegmentFrequency(TSegment segment) override { return (*Dictionary)[segment]; }
34+
protected: std::int64_t GetSegmentFrequency(TSegment segment) override { return Dictionary[segment]; }
4835

49-
protected: void SetSegmentFrequency(TSegment segment, std::int64_t frequency) override { (*Dictionary)[segment] = frequency; }
36+
protected: void SetSegmentFrequency(TSegment segment, std::int64_t frequency) override { Dictionary[segment] = frequency; }
5037
};
5138
}

cpp/Platform.Collections/Segments/Walkers/DictionaryBasedDuplicateSegmentsWalkerBase[T].h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace Platform::Collections::Segments::Walkers
22
{
33
template <typename ...> class DictionaryBasedDuplicateSegmentsWalkerBase;
4-
template <typename T, Interfaces::IArray TArray, typename TDictionary>
5-
requires Interfaces::IDictionary<TDictionary, std::span<int>*, int>
4+
template <typename T, Interfaces::IArray<T> TArray, typename TDictionary>
5+
requires Interfaces::IDictionary<TDictionary, int, std::span<T>>
66
class DictionaryBasedDuplicateSegmentsWalkerBase<T, TArray, TDictionary> : public DuplicateSegmentsWalkerBase<T, TArray, std::span<T>>
77
{
88
using base = DuplicateSegmentsWalkerBase<T, TArray, std::span<T>>;

cpp/Platform.Collections/Segments/Walkers/DuplicateSegmentsWalkerBase[T, TSegment].h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
requires std::derived_from<TSegment, std::span<T>>
66
class DuplicateSegmentsWalkerBase<T, TArray, TSegment> : public AllSegmentsWalkerBase<T, TArray, TSegment>
77
{
8-
using base = AllSegmentsWalkerBase<T, TSegment, TArray>; // TODO у меня просто код тогда в экран не поместится
8+
using base = AllSegmentsWalkerBase<T, TSegment, TArray>;
99

1010
protected: DuplicateSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) : base(minimumStringSegmentLength) { }
1111

12-
protected: DuplicateSegmentsWalkerBase()/* : base()*/ { }
12+
protected: DuplicateSegmentsWalkerBase() : base() { }
1313

14-
protected: void Iteration(TSegment segment)
14+
protected: void Iteration(TSegment segment) override
1515
{
16-
auto frequency = GetSegmentFrequency(segment);
16+
auto frequency = this->GetSegmentFrequency(segment);
1717
if (frequency == 1)
1818
{
19-
OnDublicateFound(segment);
19+
this->OnDublicateFound(segment);
2020
}
21-
SetSegmentFrequency(segment, frequency + 1);
21+
this->SetSegmentFrequency(segment, frequency + 1);
2222
}
2323

2424
protected: virtual void OnDublicateFound(TSegment segment) = 0;

cpp/Platform.Collections/Segments/Walkers/DuplicateSegmentsWalkerBase[T].h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
template <typename T, Interfaces::IArray TArray>
55
class DuplicateSegmentsWalkerBase<T, TArray> : public DuplicateSegmentsWalkerBase<T, TArray, std::span<T>>
66
{
7-
using base = AllSegmentsWalkerBase<T, TArray, std::span<T>>;
7+
using base = DuplicateSegmentsWalkerBase<T, TArray, std::span<T>>;
88

99
protected: DuplicateSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) : base(minimumStringSegmentLength) { }
1010

0 commit comments

Comments
 (0)