A dynamic vector like class for handling efficiently big continuous chunks of values.
If you have a huge vector that has a similar form to this:
[1,1,...,1,1,2,2,...,2,2,5,5,...,5,5,0,0,...,0]
where ... --> lots of same items,
then this class is for you !!!
Signature
template <BigInteger keyType = uint64_t, classvalueType = int64_t, bool arithmeticSafe = false, bool threadSafe = false>
classcompressedVectorAPI
constexprcompressedVector();
constexprexplicitcompressedVector(const valueType& initValue);
constexprcompressedVector(const keyType& minIndexArg, const keyType& maxIndexArg, const valueType& initValue);
constexprcompressedVector(keyType minIndexArg, const valueType& initValue, const std::vector<std::pair<valueType, std::size_t>>& vectorValues);
constexprcompressedVector(const compressedVector<keyType, valueType, arithmeticSafe, threadSafe>& other);
constexpr compressedVector<keyType, valueType, threadSafe>& operator=(const compressedVector<keyType, valueType, arithmeticSafe, threadSafe>& other) & noexcept;
constexprcompressedVector(compressedVector<keyType, valueType, arithmeticSafe, threadSafe>&& other);
constexpr compressedVector<keyType, valueType, arithmeticSafe, threadSafe>& operator=(compressedVector<keyType, valueType, arithmeticSafe, threadSafe>&& other) & noexcept;
constexprvoidreset(const valueType& value);
[[nodiscard]]constexprconst valueType& operator[](keyType const& key) const;
[[nodiscard]]constexprbooloperator==(const compressedVector<keyType, valueType, arithmeticSafe, threadSafe>& other) const;
[[nodiscard]]constexprconstauto& getInitialValue(void) constnoexcept;
[[nodiscard]]constexpr std::size_tgetMapSize(void) constnoexcept;
[[nodiscard]]constexpr std::size_tgetByteSize(void) constnoexcept;
[[nodiscard]]constexpr keyType getMinIndex(void) constnoexcept;
[[nodiscard]]constexpr keyType getMaxIndex(void) constnoexcept;
[[nodiscard]]constexpr std::pair<keyType, keyType> getMinMaxIndex(void) const;
[[nodiscard]]constexprautogetLength(void) constnoexcept;
[[nodiscard]]constexpr std::pair<keyType, keyType> getValidRange(const keyType& from, const keyType& to) const;
[[nodiscard]]constexprboolcontains(const keyType& fromArg, const keyType& toArg, const valueType& value) const;
[[nodiscard]]constexprboolcontains(const valueType& value) const;
[[maybe_unused]]constexprboolsetMinIndex(const keyType& index);
[[maybe_unused]]constexprboolsetMaxIndex(const keyType& index);
[[maybe_unused]]constexprboolsetMinMaxIndex(const keyType& minIndexArg, const keyType& maxIndexArg);
constexprvoidsetInitValue(const valueType& value);
constexprvoidassignValue(const keyType& fromArg, const keyType& toArg, const valueType& value);
constexprvoidassignValues(const std::vector<std::pair<valueType, std::size_t>>& values);
constexprvoidassignValues(const keyType& fromArg, const keyType& toArg, const std::vector<std::pair<valueType, std::size_t>>& values);
constexprvoidinsertValuesAfterPosition(const keyType& position, const std::vector<std::pair<valueType, std::size_t>>& values,constbool expandLeft = false);
constexprvoidappendValues(const std::vector<std::pair<valueType, std::size_t>>& values, constbool expandLeft = false);
constexprvoidprependValues(const std::vector<std::pair<valueType, std::size_t>>& values, constbool expandLeft = false);
constexprvoiderase(const keyType& fromArg, const keyType& toArg,constbool shrinkRight = false);
constexprvoidshiftLeft(const keyType& difference = keyType(1));
constexprvoidshiftRight(const keyType& difference = keyType(1));
constexprvoidreverseValues(void);
constexprvoidreverseValues(const keyType& fromArg, const keyType& toArg);
constexprvoidsortValues(constbool reverse = false, const std::function<bool(const valueType&, const valueType&)>& compareFunction = std::less<valueType>{});
constexprvoidsortValues(const keyType& fromArg, const keyType& toArg, constbool reverse = false, const std::function<bool(const valueType&, const valueType&)>& compareFunction = std::less<valueType>{});
constexprvoidreplaceValue(const valueType& oldValue, const valueType& newValue);
constexprvoidreplaceValue(const keyType& fromArg, const keyType& toArg, const valueType& oldValue, const valueType& newValue);
constexprvoidapply(const std::function<valueType(const valueType&)>& appliedFunction);
constexprvoidapply(const keyType& fromArg, const keyType& toArg, const std::function<valueType(const valueType&)>& appliedFunction);
[[nodiscard]]constexpr compressedVector<keyType, valueType, arithmeticSafe, threadSafe> getSubArray(const keyType& fromArg, const keyType& toArg) const;
[[nodiscard]]constexpr std::vector<std::tuple<keyType, keyType, valueType>> getValues(constbool shrink = false) const;
[[nodiscard]]constexpr std::vector<std::tuple<keyType, keyType, valueType>> getValues(const keyType& fromArg, const keyType& toArg, constbool shrink = false) const;
[[nodiscard]]constexpr std::unordered_set<valueType> getSetValues(void) const;
[[nodiscard]]constexpr std::unordered_set<valueType> getSetValues(const keyType& fromArg, const keyType& toArg) const;
[[nodiscard]]constexpr std::map<valueType, std::size_t> getRangeValueFrequencies(void) const;
[[nodiscard]]constexpr std::map<valueType, std::size_t> getRangeValueFrequencies(const keyType& fromArg, const keyType& toArg) const;
[[nodiscard]]constexpr std::vector<std::pair<keyType, keyType>> getValueRanges(const valueType& value, constbool shrink = false) const;
[[nodiscard]]constexpr std::unordered_map<valueType, std::vector<std::pair<keyType, keyType>>> getValuesRanges(const std::unordered_set<valueType>& values, constbool shrink = false) const;
[[nodiscard]]constexpr valueType getMinValue(const std::function<bool(const valueType&, const valueType&)>& compareFunction = std::less<valueType>{}) const;
[[nodiscard]]constexpr valueType getMinValue(const keyType& fromArg, const keyType& toArg, const std::function<bool(const valueType&, const valueType&)>& compareFunction = std::less<valueType>{}) const;
[[nodiscard]]constexpr valueType getMaxValue(const std::function<bool(const valueType&, const valueType&e)>& compareFunction = std::less<valueType>{}) const;
[[nodiscard]]constexpr valueType getMaxValue(const keyType& fromArg, const keyType& toArg, const std::function<bool(const valueType&, const valueType&)>& compareFunction = std::less{}) const;
[[nodiscard]]constexpr valueType getSum(const valueType& init = valueType(0)) const;
[[nodiscard]]constexpr valueType getSum(const keyType& fromArg, const keyType& toArg, const valueType& init = valueType(0)) const;
[[nodiscard]]constexpr valueType getProduct(const valueType& init = valueType(1)) const;
[[nodiscard]]constexpr valueType getProduct(const keyType& fromArg, const keyType& toArg, const valueType& init = valueType(1)) const;
[[nodiscard]]constexpr std::vector<valueType> uncompressToVector(void) const;
[[nodiscard]]constexpr std::vector<valueType> uncompressToVector(const keyType& fromArg, const keyType& toArg) const;
voidprint(bool uncopressed = false, std::ostream& os = std::cout, constbool newLine = true, constshort prec = 3) const;
voidprint(const keyType& fromArg, const keyType& toArg, bool uncopressed = false, std::ostream& os = std::cout, constbool newLine = true, constshort prec = 3) const;
friend std::ostream& operator<<(std::ostream& os, const compressedVector<keyType, valueType, arithmeticSafe, threadSafe>& array);
[[maybe_unused]]booltoFile(std::string_view filePath, const keyType& from, const keyType& to, bool append = false, bool uncopressed = false, bool trimEdges = true, constshort prec = 3) const;
[[nodiscard]]staticconstexpr compressedVector<keyType, valueType, arithmeticSafe, threadSafe> compress(const std::span<const valueType> buffer, keyType startIndex = keyType(0), const valueType& initValue = valueType(0), double* ratio = nullptr);
[[nodiscard]]staticconstexpr compressedVector<keyType, valueType, arithmeticSafe, threadSafe> compressFromFile(std::string_view filePath, const std::size_t indexFromStart = 0, const std::size_t indexFromEnd = 0, const valueType& initValue = valueType(0), double* ratio = nullptr);
[[nodiscard]]staticconstexpr compressedVector<keyType, valueType, arithmeticSafe, threadSafe> compressFromFileParts(std::string_view filePath,const std::vector<std::pair<const std::size_t, const std::size_t>>& ranges,const valueType& initValue = valueType(0), double* ratio = nullptr);TODO
constexprvoidassignRangeFromArray(compressedVector<keyType, valueType, arithmeticSafe, threadSafe>& array, const keyType& fromA, const keyType& toA,const keyType& fromB, const keyType& toB);
constexprvoidswapRangesWithArray(const keyType& fromA, const keyType& toA, compressedVector<keyType, valueType, arithmeticSafe, threadSafe>& array, const keyType& fromB, const keyType& toB);
constexprvoidswapRanges(const keyType& fromA, const keyType& toA, const keyType& fromB, const keyType& toB);
constexprvoidcopyRange(const keyType& fromA, const keyType& toA, const keyType& fromB, const keyType& toB);
constexprvoidincreaseValueRange(const keyType& from, const keyType& to, const valueType& value, const std::size_t amount, constbool expandLeft = false);
constexprvoiddecreaseValueRange(const keyType& from, const keyType& to, const valueType& value, const std::size_t amount, constbool shrinkRight = false);
constexprvoidchangeValueRange(const keyType& from, const keyType& to, const valueType& value, const std::size_t newRange);
constexprvoidshiftRangeLeft(const keyType& from, const keyType& to, const keyType& difference = keyType(1), const valueType& fillValue = valueType(0));
constexprvoidshiftRangeRight(const keyType& from, const keyType& to, const keyType& difference = keyType(1), const valueType& fillValue = valueType(0));
constexprvoidoperationWithArray(compressedVector<keyType, valueType, arithmeticSafe, threadSafe>& array, const keyType& fromArg, const keyType& toArg, const std::function<valueType(const valueType&, const valueType&)>& operation);
[[nodiscard]]constexpr std::vector<std::tuple<keyType, keyType, bool>> compareWithArray(compressedVector<keyType, valueType, arithmeticSafe, threadSafe>& array, const keyType& fromArgLeft, const keyType& toArgLeft, const keyType& fromArgRight, const keyType& toArgRight, const std::function<bool(const valueType&, const valueType&)>& compareFunction = std::equal_to<valueType>{}) const;