Skip to content

Commit

Permalink
Translation completed
Browse files Browse the repository at this point in the history
last steps
  • Loading branch information
uselessgoddess committed Jul 10, 2021
1 parent 3b74db1 commit c3381aa
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@

protected: TReturnConstant _returnConstant;

public: ArrayFiller(TArray& array, std::int64_t offset, auto&& returnConstant) :
ArrayFiller<TArray>(array, offset), _returnConstant(std::forward<decltype(returnConstant)>(returnConstant))
{
}
public: ArrayFiller(TArray& array, std::int64_t offset, auto&& returnConstant) : ArrayFiller<TArray>(array, offset), _returnConstant(std::forward<decltype(returnConstant)>(returnConstant)) { }

public: ArrayFiller(TArray& array, auto&& returnConstant) :
ArrayFiller(array, 0, std::forward<decltype(returnConstant)>(returnConstant))
{
}
public: ArrayFiller(TArray& array, auto&& returnConstant) : ArrayFiller(array, 0, std::forward<decltype(returnConstant)>(returnConstant)) { }

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

Expand Down
12 changes: 3 additions & 9 deletions cpp/Platform.Collections/Arrays/ArrayFiller[TElement].h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@
protected: TArray& _array;
protected: std::int64_t _position = 0;

public: ArrayFiller(TArray& array, std::int64_t offset) :
_array(array), _position(offset)
{
}

public: explicit ArrayFiller(TArray& array) :
ArrayFiller(array, 0)
{
}
public: ArrayFiller(TArray& array, std::int64_t offset) : _array(array), _position(offset) { }

public: explicit ArrayFiller(TArray& array) : ArrayFiller(array, 0) { }

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

Expand Down
23 changes: 11 additions & 12 deletions cpp/Platform.Collections/Arrays/GenericArrayExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
}

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

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

template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
static auto&& AddFirstAndReturnConstant(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements, const auto& returnConstant)
static auto AddFirstAndReturnConstant(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements, auto returnConstant)
{
AddFirst(array, position, elements);
return returnConstant;
Expand All @@ -74,12 +73,19 @@
}
}

static auto&& AddAllAndReturnConstant(Interfaces::IArray auto& array, std::integral auto& position, Interfaces::IArray auto&& elements, auto returnConstant)
static auto AddAllAndReturnConstant(Interfaces::IArray auto& array, std::integral auto& position, Interfaces::IArray auto&& elements, auto returnConstant)
{
AddAll(array, position, elements);
return returnConstant;
}

template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
static auto AddSkipFirstAndReturnConstant(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements, auto constant)
{
AddSkipFirst(array, position, elements, 1);
return constant
}

template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
static void AddSkipFirst(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements, std::integral auto skip)
{
Expand All @@ -91,11 +97,4 @@

template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
static void AddSkipFirst(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements) { AddSkipFirst(array, position, elements, 1); }

template<Interfaces::IArray TArray, typename TItem = typename Interfaces::Array<TArray>::Item>
static auto&& AddSkipFirstAndReturnConstant(TArray& array, std::integral auto& position, Interfaces::IArray<TItem> auto&& elements, auto&& constant)
{
AddSkipFirst(array, position, elements, 1);
return std::forward<decltype(constant)>(constant);
}
}// namespace Platform::Collections::Arrays
4 changes: 2 additions & 2 deletions cpp/Platform.Collections/EnsureExtensions.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Platform::Collections::Always
namespace Platform::Collections::Ensure::Always
{
template<typename T>
void ArgumentNotEmpty(Interfaces::IEnumerable auto&& argument, const std::string& argumentName = {}, const std::string& message = {})
Expand Down Expand Up @@ -27,7 +27,7 @@
}
}// namespace Platform::Collections::Always

namespace Platform::Collections::Always
namespace Platform::Collections::Ensure::Always
{
static void ArgumentNotEmpty(auto&&... args)
{
Expand Down
6 changes: 3 additions & 3 deletions cpp/Platform.Collections/IDictionaryExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
{
throw std::logic_error("Unknown exception");
}

dictionary.insert({std::forward<decltype(key)>(key), std::forward<decltype(value)>(value)});
using Item = typename Interfaces::Dictionary<TDictionary>::Item;
dictionary.insert(Item{std::forward<decltype(key)>(key), std::forward<decltype(value)>(value)});
}

template<Interfaces::IDictionary TDictionary>
Expand All @@ -17,7 +17,7 @@
if (!dictionary.contains(key))
{
auto& value = dictionary[key];
value = std::forward<decltype(valueFactory(key))>(valueFactory(key));
value = valueFactory(key);
return value;
}
return dictionary[key];
Expand Down
2 changes: 1 addition & 1 deletion cpp/Platform.Collections/Lists/IListExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
template<Interfaces::IList TList, typename TItem = typename Interfaces::List<TList>::Item>
static void AddSkipFirst(TList& list, Interfaces::IArray<TItem> auto&& elements, std::integral auto skip)
{
for (const auto& element : elements | std::views::drop(skip))
for (auto&& element : elements | std::views::drop(skip))
{
list.push_back(element);
}
Expand Down
40 changes: 8 additions & 32 deletions cpp/Platform.Collections/Lists/ListFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@

protected: TReturnConstant _returnConstant;

public: ListFiller(TList& list, auto&& returnConstant)
: _list(list), _returnConstant(std::forward<decltype(returnConstant)>(returnConstant))
{
}
public: ListFiller(TList& list, auto&& returnConstant) : _list(list), _returnConstant(std::forward<decltype(returnConstant)>(returnConstant)) { }

public: explicit ListFiller(TList& list)
: ListFiller(list, {})
{
}
public: explicit ListFiller(TList& list) : ListFiller(list, {}) { }

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

Expand All @@ -37,40 +31,22 @@
return _returnConstant;
}

public: TReturnConstant AddFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &
{
Lists::AddFirst(_list, elements);
return std::move(_returnConstant);
}

public: TReturnConstant&& AddFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &&
public: TReturnConstant AddFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements)
{
Lists::AddFirst(_list, elements);
return std::move(_returnConstant);
}

public: TReturnConstant AddAllAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &
{
Lists::AddAll(_list, elements);
return std::move(_returnConstant);
return _returnConstant;
}

public: TReturnConstant&& AddAllAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &&
public: TReturnConstant AddAllAndReturnConstant(Interfaces::IArray<TElement> auto&& elements)
{
Lists::AddAll(_list, elements);
return std::move(_returnConstant);
}

public: TReturnConstant AddSkipFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &
{
Lists::AddSkipFirst(_list, elements);
return std::move(_returnConstant);
return _returnConstant;
}

public: TReturnConstant&& AddSkipFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements) &&
public: TReturnConstant AddSkipFirstAndReturnConstant(Interfaces::IArray<TElement> auto&& elements)
{
Lists::AddSkipFirst(_list, elements);
return std::move(_returnConstant);
return _returnConstant;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
template <typename ...> class AllSegmentsWalkerBase;
template<> class AllSegmentsWalkerBase<>
{
public: inline static const std::int32_t DefaultMinimumStringSegmentLength = 2;
public: static constexpr std::int32_t DefaultMinimumStringSegmentLength = 2;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
private: std::int32_t _minimumStringSegmentLength = 0;

protected: AllSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) { _minimumStringSegmentLength = minimumStringSegmentLength; }
protected: explicit AllSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) { _minimumStringSegmentLength = minimumStringSegmentLength; }

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

Expand All @@ -26,6 +26,6 @@

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

public: virtual ~AllSegmentsWalkerBase() {}
public: virtual ~AllSegmentsWalkerBase() = default;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
using base = AllSegmentsWalkerBase<T, TArray, std::span<T>>;
using TSegment = std::span<T>;

protected: AllSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) : base(minimumStringSegmentLength) {}
protected: explicit AllSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) : base(minimumStringSegmentLength) {}

protected: AllSegmentsWalkerBase() : base() { }

protected: TSegment CreateSegment(TArray& elements, std::int32_t offset, std::int32_t length)
{
return std::span<T>(std::ranges::begin(elements) + offset, length);
return std::span(std::ranges::begin(elements) + offset, length);
}
};
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,38 @@
namespace Platform::Collections::Segments::Walkers
{
template <typename ...> class DictionaryBasedDuplicateSegmentsWalkerBase;
template <typename T, Interfaces::IArray TArray, typename TDictionary, typename TSegment>
requires std::derived_from<TSegment, std::span<T>> && Interfaces::IDictionary<TDictionary, TSegment*, int>
template <typename T, Interfaces::IArray TArray, Interfaces::IDictionary TDictionary, typename TSegment>
requires std::derived_from<TSegment, std::span<T>> && Interfaces::IDictionary<TDictionary, int, TSegment>
class DictionaryBasedDuplicateSegmentsWalkerBase<T, TArray, TDictionary, TSegment> : public DuplicateSegmentsWalkerBase<T, TArray, TSegment>
{
using base = DuplicateSegmentsWalkerBase<T, TArray, TSegment>;

public: static constexpr bool DefaultResetDictionaryOnEachWalk = false; // change readonly to constexpr
public: static constexpr bool DefaultResetDictionaryOnEachWalk = false;

private: bool _resetDictionaryOnEachWalk = 0;
protected: TDictionary* Dictionary;
private: bool _resetDictionaryOnEachWalk = false;
protected: TDictionary Dictionary;

protected: DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary, std::int32_t minimumStringSegmentLength, bool resetDictionaryOnEachWalk)
: base(minimumStringSegmentLength), Dictionary(dictionary)
{
_resetDictionaryOnEachWalk = resetDictionaryOnEachWalk;
}
protected: DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary, std::int32_t minimumStringSegmentLength, bool resetDictionaryOnEachWalk) : base(minimumStringSegmentLength), Dictionary(dictionary), _resetDictionaryOnEachWalk(resetDictionaryOnEachWalk) { }

protected: DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary, std::int32_t minimumStringSegmentLength)
: DictionaryBasedDuplicateSegmentsWalkerBase(dictionary, minimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
protected: DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary, std::int32_t minimumStringSegmentLength) : DictionaryBasedDuplicateSegmentsWalkerBase(dictionary, minimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }

protected: DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary)
: DictionaryBasedDuplicateSegmentsWalkerBase(dictionary, base::DefaultMinimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
protected: explicit DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary dictionary) : DictionaryBasedDuplicateSegmentsWalkerBase(std::move(dictionary), base::DefaultMinimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }

protected: DictionaryBasedDuplicateSegmentsWalkerBase(std::int32_t minimumStringSegmentLength, bool resetDictionaryOnEachWalk)
: DictionaryBasedDuplicateSegmentsWalkerBase(resetDictionaryOnEachWalk ? nullptr : new TDictionary, minimumStringSegmentLength, resetDictionaryOnEachWalk) { }
protected: DictionaryBasedDuplicateSegmentsWalkerBase(std::int32_t minimumStringSegmentLength, bool resetDictionaryOnEachWalk) : DictionaryBasedDuplicateSegmentsWalkerBase(TDictionary{}, minimumStringSegmentLength, resetDictionaryOnEachWalk) { }

protected: DictionaryBasedDuplicateSegmentsWalkerBase(std::int32_t minimumStringSegmentLength)
: DictionaryBasedDuplicateSegmentsWalkerBase(minimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
protected: explicit DictionaryBasedDuplicateSegmentsWalkerBase(std::int32_t minimumStringSegmentLength) : DictionaryBasedDuplicateSegmentsWalkerBase(minimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }

protected: DictionaryBasedDuplicateSegmentsWalkerBase()
: DictionaryBasedDuplicateSegmentsWalkerBase(base::DefaultMinimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }
protected: DictionaryBasedDuplicateSegmentsWalkerBase() : DictionaryBasedDuplicateSegmentsWalkerBase(base::DefaultMinimumStringSegmentLength, DefaultResetDictionaryOnEachWalk) { }

public: void WalkAll(TArray elements) override
public: void WalkAll(const TArray& elements) override
{
if constexpr(decltype(*this)::_resetDictionaryOnEachWalk && requires(TDictionary dict, int capacity) {dict(capacity);})
{
auto capacity = std::ceil(std::pow(elements->size(), 2) / 2);
Dictionary = new TDictionary((std::int32_t)capacity);
}
auto capacity = std::ceil(std::pow(std::ranges::size(elements), 2) / 2);
Dictionary = TDictionary(capacity);
base::WalkAll(elements);
}

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

protected: void SetSegmentFrequency(TSegment segment, std::int64_t frequency) override { (*Dictionary)[segment] = frequency; }
protected: void SetSegmentFrequency(TSegment segment, std::int64_t frequency) override { Dictionary[segment] = frequency; }
};
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Platform::Collections::Segments::Walkers
{
template <typename ...> class DictionaryBasedDuplicateSegmentsWalkerBase;
template <typename T, Interfaces::IArray TArray, typename TDictionary>
requires Interfaces::IDictionary<TDictionary, std::span<int>*, int>
template <typename T, Interfaces::IArray<T> TArray, typename TDictionary>
requires Interfaces::IDictionary<TDictionary, int, std::span<T>>
class DictionaryBasedDuplicateSegmentsWalkerBase<T, TArray, TDictionary> : public DuplicateSegmentsWalkerBase<T, TArray, std::span<T>>
{
using base = DuplicateSegmentsWalkerBase<T, TArray, std::span<T>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
requires std::derived_from<TSegment, std::span<T>>
class DuplicateSegmentsWalkerBase<T, TArray, TSegment> : public AllSegmentsWalkerBase<T, TArray, TSegment>
{
using base = AllSegmentsWalkerBase<T, TSegment, TArray>; // TODO у меня просто код тогда в экран не поместится
using base = AllSegmentsWalkerBase<T, TSegment, TArray>;

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

protected: DuplicateSegmentsWalkerBase()/* : base()*/ { }
protected: DuplicateSegmentsWalkerBase() : base() { }

protected: void Iteration(TSegment segment)
protected: void Iteration(TSegment segment) override
{
auto frequency = GetSegmentFrequency(segment);
auto frequency = this->GetSegmentFrequency(segment);
if (frequency == 1)
{
OnDublicateFound(segment);
this->OnDublicateFound(segment);
}
SetSegmentFrequency(segment, frequency + 1);
this->SetSegmentFrequency(segment, frequency + 1);
}

protected: virtual void OnDublicateFound(TSegment segment) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
template <typename T, Interfaces::IArray TArray>
class DuplicateSegmentsWalkerBase<T, TArray> : public DuplicateSegmentsWalkerBase<T, TArray, std::span<T>>
{
using base = AllSegmentsWalkerBase<T, TArray, std::span<T>>;
using base = DuplicateSegmentsWalkerBase<T, TArray, std::span<T>>;

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

Expand Down
Loading

0 comments on commit c3381aa

Please sign in to comment.