-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
106 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 16 additions & 29 deletions
45
...orm.Collections/Segments/Walkers/DictionaryBasedDuplicateSegmentsWalkerBase[T, Segment].h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
}; | ||
} |
4 changes: 2 additions & 2 deletions
4
cpp/Platform.Collections/Segments/Walkers/DictionaryBasedDuplicateSegmentsWalkerBase[T].h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.