2#ifndef _aspose_system_memory_extensions_h_
3#define _aspose_system_memory_extensions_h_
7#include <system/array_segment.h>
8#include <system/span.h>
9#include <system/memory.h>
10#include <system/object.h>
11#include <system/object_ext.h>
12#include <system/details/stack_array.h>
13#include <system/smart_ptr.h>
14#include <system/exceptions.h>
15#include <system/comparison.h>
16#include <system/range.h>
21namespace MemoryExtensions {
35template <
typename T,
typename U>
45 Compare(
const T& a,
const T& b);
53template <
typename T,
typename U>
84template <
typename TKey,
typename TValue>
86 std::function<int32_t(
const TKey&,
const TKey&)> comparer);
96template <
typename TKey,
typename TValue>
98 std::function<int32_t(
const TKey&,
const TKey&)> comparer, int32_t i, int32_t j);
106template <
typename TKey,
typename TValue>
115template <
typename TKey,
typename TValue>
126template <
typename TKey,
typename TValue>
128 std::function<int32_t(
const TKey&,
const TKey&)> comparer);
137template <
typename TKey,
typename TValue>
139 std::function<int32_t(
const TKey&,
const TKey&)> comparer);
149template <
typename T,
typename TValue,
typename TCompareFunc>
152template <
typename T,
typename U>
168 return (*a).CompareTo(b);
178template <
typename T,
typename U>
182 return (*a).CompareTo(b);
262template <
typename TKey,
typename TValue>
264 std::function<int32_t(
const TKey&,
const TKey&)> comparer)
266 int32_t partitionSize = keys.get_Length();
267 while (partitionSize > 1)
269 if (partitionSize <= 16)
271 if (partitionSize == 2)
277 if (partitionSize == 3)
299 int32_t rightSize = partitionSize - p - 1;
302 IntroSort(keys.Slice(p + 1, rightSize), values.Slice(p + 1, rightSize), depthLimit, comparer);
310template <
typename TKey,
typename TValue>
312 std::function<int32_t(
const TKey&,
const TKey&)> comparer, int32_t i, int32_t j)
314 if (comparer(keys.get(i), keys.get(j)) > 0)
316 std::swap(keys.get(i), keys.get(j));
317 std::swap(values.get(i), values.get(j));
321template <
typename TKey,
typename TValue>
324 for (int32_t i = 0; i < keys.get_Length() - 1; i++)
326 TKey t = keys.get(i + 1);
327 TValue tValue = values.get(i + 1);
330 while (j >= 0 && keys.get(j) != t && !comparer(t, keys.get(j)))
332 keys.get(j + 1) = keys.get(j);
333 values.get(j + 1) = values.get(j);
338 values.get(j + 1) = tValue;
342template <
typename TKey,
typename TValue>
346 for (int32_t i = keys.get_Length() / 2 - 1; i >= 0; i--)
348 Heapify(keys, values, keys.get_Length(), i, comparer);
352 for (int32_t i = keys.get_Length() - 1; i > 0; i--)
354 std::swap(keys.get(0), keys.get(i));
355 std::swap(values.get(0), values.get(i));
356 Heapify(keys, values, i, 0, comparer);
361template <
typename TKey,
typename TValue>
363 std::function<int32_t(
const TKey&,
const TKey&)> comparer)
366 int32_t left = 2 * i + 1;
367 int32_t right = 2 * i + 2;
369 if (left < n && comparer(keys.get(left), keys.get(largest)) > 0)
374 if (right < n && comparer(keys.get(right), keys.get(largest)) > 0)
381 std::swap(keys.get(i), keys.get(largest));
382 std::swap(values.get(i), values.get(largest));
383 Heapify(keys, values, n, largest, comparer);
387template <
typename TKey,
typename TValue>
389 std::function<int32_t(
const TKey&,
const TKey&)> comparer)
392 int32_t middle = keys.get_Length() / 2;
393 int32_t last = keys.get_Length() - 1;
396 if (comparer(keys.get(0), keys.get(middle)) > 0)
398 std::swap(keys.get(0), keys.get(middle));
399 std::swap(values.get(0), values.get(middle));
401 if (comparer(keys.get(0), keys.get(last)) > 0)
403 std::swap(keys.get(0), keys.get(last));
404 std::swap(values.get(0), values.get(last));
406 if (comparer(keys.get(middle), keys.get(last)) > 0)
408 std::swap(keys.get(middle), keys.get(last));
409 std::swap(values.get(middle), values.get(last));
413 std::swap(keys.get(middle), keys.get(last));
414 std::swap(values.get(middle), values.get(last));
416 TKey pivot = keys.get(last);
419 for (int32_t j = 0; j < last; j++)
421 if (comparer(keys.get(j), pivot) <= 0)
424 std::swap(keys.get(i), keys.get(j));
425 std::swap(values.get(i), values.get(j));
429 std::swap(keys.get(i + 1), keys.get(last));
430 std::swap(values.get(i + 1), values.get(last));
434template <
typename T,
typename TValue,
typename TCompareFunc>
438 int32_t hi = span.get_Length() - 1;
443 int32_t i =
static_cast<int32_t
>((
static_cast<uint32_t
>(hi) +
static_cast<uint32_t
>(lo)) >> 1);
444 int32_t c = compareFunc(value, span.get(i));
537template <
typename T,
typename TComparable>
547template <
typename T,
typename TComparer>
556template <
typename T,
typename TComparable>
566template <
typename T,
typename TComparer>
600template <
typename T,
typename TEqualityComparer>
612template <
typename T,
typename TEqualityComparer>
624template <
typename T,
typename TEqualityComparer>
685bool ContainsAny(
const Span<T>& span,
const T& value0,
const T& value1,
const T& value2);
988int32_t
IndexOfAny(
const Span<T>& span,
const T& value0,
const T& value1,
const T& value2);
1005template <
typename T>
1014template <
typename T>
1025template <
typename T>
1037template <
typename T>
1046template <
typename T>
1056template <
typename T>
1067template <
typename T>
1076template <
typename T>
1085template <
typename T>
1095template <
typename T>
1105template <
typename T>
1115template <
typename T>
1125template <
typename T>
1134template <
typename T>
1143template <
typename T>
1152template <
typename T>
1161template <
typename T>
1172template <
typename T>
1183template <
typename T>
1193template <
typename T>
1203template <
typename T>
1212template <
typename T>
1221template <
typename T>
1230template <
typename T>
1241template <
typename T>
1252template <
typename T>
1262template <
typename T>
1272template <
typename T>
1281template <
typename T>
1290template <
typename T>
1299template <
typename T>
1308template <
typename T>
1317template <
typename T>
1327template <
typename T>
1337template <
typename T>
1347template <
typename T>
1357template <
typename T>
1366template <
typename T>
1375template <
typename T>
1385template <
typename T>
1395template <
typename T>
1404template <
typename T>
1405void Replace(
Span<T>& span,
const T& oldValue,
const T& newValue);
1415template <
typename T>
1421template <
typename T>
1429template <
typename T>
1437template <
typename T>
1446template <
typename T>
1455template <
typename T>
1464template <
typename T>
1475template <
typename T,
typename TComparer>
1486template <
typename T,
typename TComparer>
1495template <
typename T,
typename TComparer>
1502template <
typename T>
1514template <
typename TKey,
typename TValue,
typename TComparer>
1525template <
typename TKey,
typename TValue>
1535template <
typename TKey,
typename TValue>
1544template <
typename T>
1553template <
typename T>
1562template <
typename T>
1571template <
typename T>
1580template <
typename T>
1589template <
typename T>
1598template <
typename T>
1607template <
typename T>
1616template <
typename T>
1625template <
typename T>
1634template <
typename T>
1643template <
typename T>
1652template <
typename T>
1661template <
typename T>
1670template <
typename T>
1679template <
typename T>
1688template <
typename T>
1697template <
typename T>
1706template <
typename T>
1715template <
typename T>
1724template <
typename T>
1829 if (span.get_Length() == 0)
1834 return (span.get(0)).Equals(value);
1875 int32_t endIndex = span.get_Length() - 1;
1876 while (endIndex >= 0 && span.get(endIndex) == trimchar)
1880 return span.Slice(0, endIndex + 1);
1889 int32_t endIndex = span.get_Length() - 1;
1890 while (endIndex >= 0 && span.get(endIndex) == trimchar)
1894 return span.Slice(0, endIndex + 1);
1903 int32_t endIndex = span.get_Length() - 1;
1904 while (endIndex >= 0 &&
Contains(trimChars, span.get(endIndex)))
1908 return span.Slice(0, endIndex + 1);
1917 int32_t endIndex = span.get_Length() - 1;
1918 while (endIndex >= 0 &&
Contains(trimchars, span.get(endIndex)))
1922 return span.Slice(0, endIndex + 1);
1947 int32_t startIndex = 0;
1948 while (startIndex < span.get_Length() && span.get(startIndex) == trimchar)
1952 return span.Slice(startIndex);
1961 int32_t startIndex = 0;
1962 while (startIndex < span.get_Length() && span.get(startIndex) == trimchar)
1966 return span.Slice(startIndex);
1975 int32_t startIndex = 0;
1976 while (startIndex < span.get_Length() &&
Contains(trimchars, span.get(startIndex)))
1980 return span.Slice(startIndex);
1989 int32_t startIndex = 0;
1990 while (startIndex < span.get_Length() &&
Contains(trimchars, span.get(startIndex)))
1994 return span.Slice(startIndex);
1997template <
typename T>
2000 return AsMemory<T>(array, 0, -1);
2003template <
typename T>
2006 return AsMemory<T>(array, start, -1);
2009template <
typename T>
2012 if (array ==
nullptr)
2014 throw ArgumentNullException(u
"array is null");
2016 if (start < 0 || (length < 0 && length != -1) ||
2017 (length == -1 ? start > array->get_Length() : start + length > array->get_Length()))
2019 throw ArgumentOutOfRangeException(u
"start or length is out of range");
2023 length = array->get_Length() - start;
2028template <
typename T>
2034template <
typename T>
2037 if (array ==
nullptr)
2041 throw ArgumentNullException(u
"array");
2048 return Memory<T>(array, ol.template Item<0>(), ol.template Item<1>());
2051template <
typename T>
2054 if (array ==
nullptr)
2056 throw ArgumentNullException(u
"array is null");
2058 if (start < 0 || (length < 0 && length != -1) ||
2059 (length == -1 ? start > array->get_Length() : start + length > array->get_Length()))
2061 throw ArgumentOutOfRangeException(u
"start or length is out of range");
2065 length = array->get_Length() - start;
2067 return Span<T>(array, start, length);
2070template <
typename T,
typename TComparable>
2074 [](
const TComparable& search_value,
const T& container_value) -> int32_t {
2079template <
typename T,
typename TComparer>
2083 [&comparerPtr](
const T& search_value,
const T& container_value) -> int32_t {
2084 return comparerPtr->Compare(search_value, container_value);
2088template <
typename T,
typename TComparable>
2094template <
typename T,
typename TComparer>
2100template <
typename T>
2103 int32_t commonLength = 0;
2104 int32_t minLength = std::min(span.get_Length(), other.get_Length());
2107 for (int32_t i = 0; i < minLength; ++i)
2119 return commonLength;
2122template <
typename T>
2128template <
typename T>
2134template <
typename T,
typename TEqualityComparer>
2138 int32_t commonLength = 0;
2139 int32_t minLength = std::min(span.get_Length(), other.get_Length());
2142 for (int32_t i = 0; i < minLength; ++i)
2145 (comparer !=
nullptr && comparer->Equals(span.get(i), other.get(i))))
2155 return commonLength;
2158template <
typename T,
typename TEqualityComparer>
2165template <
typename T,
typename TEqualityComparer>
2171template <
typename T>
2174 return std::find_if(span.begin(), span.end(), [&value](
const T& item) { return System::ObjectExt::Equals(value, item); }) !=
2178template <
typename T>
2181 return std::find(span.begin(), span.end(), value) != span.end();
2184template <
typename T>
2190template <
typename T>
2196template <
typename T>
2202template <
typename T>
2208template <
typename T>
2211 for (
const auto& value : values)
2221template <
typename T>
2227template <
typename T>
2230 for (
auto& member : span)
2241template <
typename T>
2247template <
typename T>
2250 for (
auto& member : span)
2260template <
typename T>
2266template <
typename T>
2269 for (
auto& member : span)
2279template <
typename T>
2285template <
typename T>
2288 switch (values.get_Length())
2291 return span.get_IsEmpty() ? false :
true;
2303 for (
auto& member : span)
2314template <
typename T>
2320template <
typename T>
2323 for (
const auto& value : span)
2325 if (value < lowInclusive || value > highInclusive)
2333template <
typename T>
2336 for (
const auto& value : span)
2338 if (value < lowInclusive || value > highInclusive)
2346template <
typename T>
2349 for (
const auto& value : span)
2351 if (value >= lowInclusive && value <= highInclusive)
2359template <
typename T>
2362 for (
const auto& value : span)
2364 if (value >= lowInclusive && value <= highInclusive)
2372template <
typename T>
2378template <
typename T>
2382 for (
const auto& item : span)
2392template <
typename T>
2395 switch (value.get_Length())
2401 return Count(span, value.get(0));
2407 while ((pos =
IndexOf(currentSpan, value)) >= 0)
2410 currentSpan = currentSpan.Slice(pos + value.get_Length());
2416template <
typename T>
2422template <
typename T>
2428template <
typename T>
2431 if (span.get_Length() == 0)
2438template <
typename T>
2441 int32_t spanLength = span.get_Length();
2442 int32_t valueLength = value.get_Length();
2444 if (valueLength > spanLength)
2449 if (valueLength == spanLength)
2454 return SequenceEqual(span.Slice(spanLength - valueLength), value);
2457template <
typename T>
2463template <
typename T>
2469template <
typename T>
2475template <
typename T>
2478 if (value.get_Length() == 0)
2483 const T& valueHead = value.get(0);
2484 int32_t valueTailLength = value.get_Length() - 1;
2489 if (index + valueTailLength > span.get_Length())
2495 int32_t remainingSearchSpaceLength = span.get_Length() - index - valueTailLength;
2496 int32_t relativeIndex = -1;
2498 for (int32_t i = 0; i < remainingSearchSpaceLength; ++i)
2507 if (relativeIndex == -1)
2512 index += relativeIndex;
2515 bool tailMatches =
true;
2516 for (int32_t i = 0; i < valueTailLength; ++i)
2518 if (span.get(index + 1 + i) != value.get(1 + i))
2520 tailMatches =
false;
2536template <
typename T>
2539 for (int32_t i = 0; i < span.get_Length(); ++i)
2549template <
typename T>
2555template <
typename T>
2561template <
typename T>
2564 for (int32_t i = 0; i < span.get_Length(); ++i)
2574template <
typename T>
2577 for (int32_t i = 0; i < span.get_Length(); ++i)
2588template <
typename T>
2594template <
typename T>
2600template <
typename T>
2603 for (int32_t i = 0; i < span.get_Length(); ++i)
2605 for (int32_t j = 0; j < values.get_Length(); ++j)
2616template <
typename T>
2622template <
typename T>
2625 for (int32_t i = 0; i < span.get_Length(); ++i)
2635template <
typename T>
2638 for (int32_t i = 0; i < span.get_Length(); ++i)
2648template <
typename T>
2651 for (int32_t i = 0; i < span.get_Length(); ++i)
2662template <
typename T>
2668template <
typename T>
2674template <
typename T>
2680template <
typename T>
2683 for (int32_t i = 0; i < span.get_Length(); ++i)
2686 for (int32_t j = 0; j < values.get_Length(); ++j)
2702template <
typename T>
2708template <
typename T>
2711 for (int32_t i = 0; i < span.get_Length(); ++i)
2721template <
typename T>
2727template <
typename T>
2730 for (int32_t i = 0; i < span.get_Length(); ++i)
2741template <
typename T>
2747template <
typename T>
2750 if (value.get_Length() == 0)
2751 return span.get_Length();
2753 int32_t valueTailLength = value.get_Length() - 1;
2754 if (valueTailLength == 0)
2756 return LastIndexOf<T>(span, value.get(0));
2761 T valueHead = value.get(0);
2766 int32_t remainingSearchSpaceLength = span.get_Length() - index - valueTail.get_Length();
2767 if (remainingSearchSpaceLength <= 0)
2771 int32_t relativeIndex = Details::LastIndexOfImpl<T>(span, remainingSearchSpaceLength, valueHead);
2772 if (relativeIndex < 0)
2776 if (Details::SequenceEqualImpl<T>(span, relativeIndex + 1, valueTail.get_Length(), valueTail))
2777 return relativeIndex;
2779 index += remainingSearchSpaceLength - relativeIndex;
2784template <
typename T>
2787 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2797template <
typename T>
2803template <
typename T>
2809template <
typename T>
2812 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2823template <
typename T>
2829template <
typename T>
2832 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2842template <
typename T>
2848template <
typename T>
2851 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2853 for (int32_t j = 0; j < values.get_Length(); ++j)
2864template <
typename T>
2870template <
typename T>
2876template <
typename T>
2879 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2881 const T& current = span.get(i);
2891template <
typename T>
2897template <
typename T>
2900 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2902 const T& current = span.get(i);
2911template <
typename T>
2917template <
typename T>
2920 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2922 T current = span.get(i);
2931template <
typename T>
2937template <
typename T>
2940 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2942 const T& current = span.get(i);
2944 for (
auto& value : values)
2960template <
typename T>
2966template <
typename T>
2972template <
typename T>
2975 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2985template <
typename T>
2991template <
typename T>
2994 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
3004template <
typename T>
3010template <
typename T>
3014 return Overlaps(span, other, offset);
3017template <
typename T>
3023template <
typename T>
3026 if (span.get_IsEmpty() || other.get_IsEmpty())
3031 ptrdiff_t Offset = other.begin() - span.begin();
3032 bool isOverlap = (Offset >= 0 && Offset < span.get_Length()) || (Offset < 0 && -Offset < other.get_Length());
3036 elementOffset =
static_cast<int32_t
>(Offset);
3045template <
typename T>
3051template <
typename T>
3054 for (int32_t i = 0; i < span.get_Length(); ++i)
3058 span.get(i) = newValue;
3063template <
typename T>
3066 if (destination.get_Length() < source.get_Length())
3068 throw ArgumentException(u
"Destination span is smaller than source span.");
3071 for (int32_t i = 0; i < source.get_Length(); ++i)
3075 destination.get(i) = newValue;
3079 destination.get(i) = source.get(i);
3084template <
typename T>
3088 int32_t right = span.get_Length() - 1;
3089 while (left < right)
3091 std::swap(span.get(left), span.get(right));
3097template <
typename T>
3100 auto spanIt = span.begin();
3101 auto otherIt = other.begin();
3102 auto spanEnd = span.end();
3103 auto otherEnd = other.end();
3105 while (spanIt != spanEnd && otherIt != otherEnd)
3107 if (*spanIt < *otherIt)
3111 if (*spanIt > *otherIt)
3121 if (span.get_Length() < other.get_Length())
3125 if (span.get_Length() > other.get_Length())
3133template <
typename T>
3139template <
typename T>
3145template <
typename T>
3148 if (first == second)
3151 if (first.get_Length() != second.get_Length())
3156 int32_t length = second.get_Length();
3161template <
typename T>
3167template <
typename T,
typename TComparer>
3170 if (comparer ==
nullptr)
3175 if (span.get_Length() != other.get_Length())
3180 for (int32_t i = 0; i < span.get_Length(); ++i)
3182 if (!comparer->Equals(span.get(i), other.get(i)))
3190template <
typename T,
typename TComparer>
3196template <
typename T,
typename TComparer>
3199 std::sort(span.begin(), span.end(), [&comparer](
const T& a,
const T& b) ->
bool { return comparer->Compare(a, b) < 0; });
3202template <
typename T>
3205 std::sort(span.begin(), span.end());
3208template <
typename TKey,
typename TValue,
typename TComparer>
3211 if (keys.get_Length() != values.get_Length())
3213 throw ArgumentException(u
"Keys and items must have the same length.");
3215 if (keys.get_Length() > 1)
3217 int32_t depthLimit = 2 * (
static_cast<int32_t
>(std::log2(keys.get_Length())) + 1);
3218 Details::IntroSort<TKey, TValue>(keys, values, depthLimit,
3219 [&comparer](TKey a, TKey b) ->
bool {
return comparer->Compare(a, b) > 0; });
3223template <
typename TKey,
typename TValue>
3226 if (keys.get_Length() != values.get_Length())
3228 throw ArgumentException(u
"Keys and items must have the same length.");
3230 if (keys.get_Length() > 1)
3232 int32_t depthLimit = 2 * (
static_cast<int32_t
>(std::log2(keys.get_Length())) + 1);
3233 Details::IntroSort<TKey, TValue>(keys, values, depthLimit,
3234 [&](
const TKey& a,
const TKey& b) {
return !comparer(a, b); });
3238template <
typename TKey,
typename TValue>
3241 if (keys.get_Length() != values.get_Length())
3243 throw ArgumentException(u
"Keys and items must have the same length.");
3245 if (keys.get_Length() > 1)
3247 int32_t depthLimit = 2 * (
static_cast<int32_t
>(std::log2(keys.get_Length())) + 1);
3248 Details::IntroSort<TKey, TValue>(keys, values, depthLimit, [&](
const TKey& a,
const TKey& b) {
return a > b; });
3252template <
typename T>
3255 if (span.get_Length() == 0)
3259 return System::ObjectExt::Equals<T>(span.get(0), value);
3262template <
typename T>
3265 if (value.get_Length() > span.get_Length())
3270 for (int32_t i = 0; i < value.get_Length(); ++i)
3281template <
typename T>
3287template <
typename T>
3293template <
typename T>
3299template <
typename T>
3305template <
typename T>
3308 if (span.get_IsEmpty())
3314 int32_t end = span.get_Length() - 1;
3317 while (start <= end &&
Contains(trimElements, span.get(start)))
3323 while (end >= start &&
Contains(trimElements, span.get(end)))
3328 return span.Slice(start, end - start + 1);
3331template <
typename T>
3334 if (span.get_IsEmpty())
3340 int32_t end = span.get_Length() - 1;
3343 while (start <= end &&
Contains(trimElements, span.get(start)))
3349 while (end >= start &&
Contains(trimElements, span.get(end)))
3354 return span.Slice(start, end - start + 1);
3357template <
typename T>
3360 int32_t endIndex = span.get_Length() - 1;
3365 return span.Slice(0, endIndex + 1);
3368template <
typename T>
3371 int32_t endIndex = span.get_Length() - 1;
3376 return span.Slice(0, endIndex + 1);
3379template <
typename T>
3382 int32_t endIndex = span.get_Length() - 1;
3383 while (endIndex >= 0 &&
Contains(trimElements, span.get(endIndex)))
3387 return span.Slice(0, endIndex + 1);
3390template <
typename T>
3393 int32_t endIndex = span.get_Length() - 1;
3394 while (endIndex >= 0 &&
Contains(trimElements, span.get(endIndex)))
3398 return span.Slice(0, endIndex + 1);
3401template <
typename T>
3404 int32_t startIndex = 0;
3409 return span.Slice(startIndex);
3412template <
typename T>
3415 int32_t startIndex = 0;
3420 return span.Slice(startIndex);
3423template <
typename T>
3426 int32_t startIndex = 0;
3427 while (startIndex < span.get_Length() &&
Contains(trimElements, span.get(startIndex)))
3431 return span.Slice(startIndex);
3434template <
typename T>
3437 int32_t startIndex = 0;
3438 while (startIndex < span.get_Length() &&
Contains(trimElements, span.get(startIndex)))
3442 return span.Slice(startIndex);
Represents a segment of the one-dimensional array. This type should be allocated on stack and passed ...
Definition: array_segment.h:62
int32_t get_Count() const
Definition: array_segment.h:80
System::ArrayPtr< T > get_Array() const
Definition: array_segment.h:70
int32_t get_Offset() const
Definition: array_segment.h:75
Represents a pointer to the method that compares two objects of the same type. This type should be al...
Definition: comparison.h:93
bool Equals(const Index &other) const
Determines whether the current instance and the specified Index represent the same position.
Definition: index.h:75
static constexpr Index get_Start() noexcept
Gets an Index object representing the start of a collection.
Definition: index.h:41
Represents a mutable memory segment backed by an array.
Definition: memory.h:154
static std::enable_if< IsExceptionWrapper< T >::value, bool >::type Equals(const T &obj, const T2 &another)
Definition: object_ext.h:36
Represents a range with a start and end index. This type should be allocated on stack and passed to f...
Definition: range.h:14
const Index & get_End() const noexcept
Gets the End index.
Definition: range.h:56
System::ValueTuple< int32_t, int32_t > GetOffsetAndLength(int32_t length) const
Computes the zero-based start offset and length for the specified collection length.
Definition: range.h:65
const Index & get_Start() const noexcept
Gets the Start index.
Definition: range.h:50
Represents a read-only memory segment backed by an array.
Definition: memory.h:232
Forward to use within Span class.
Definition: span.h:404
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Represents a contiguous region of arbitrary memory similar to C++20's std::span.
Definition: span.h:364
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:125
bool SequenceEqualImpl(const ReadOnlySpan< T > &first, const int32_t start, int32_t length, const ReadOnlySpan< T > &second)
Checks if two spans are equal starting from specified positions.
Definition: memory_extensions.h:226
void SwapIfGreaterWithValues(Span< TKey > &keys, Span< TValue > &values, std::function< int32_t(const TKey &, const TKey &)> comparer, int32_t i, int32_t j)
Swaps key-value pairs if comparison condition is met.
Definition: memory_extensions.h:311
int32_t PickPivotAndPartition(Span< TKey > &keys, Span< TValue > &values, std::function< int32_t(const TKey &, const TKey &)> comparer)
Selects pivot and partitions key-value pairs for quicksort.
Definition: memory_extensions.h:388
void HeapSort(Span< TKey > &keys, Span< TValue > &values, std::function< int32_t(const TKey &, const TKey &)> comparer)
Performs heap sort on key-value pairs.
Definition: memory_extensions.h:343
const std::array< char16_t, 22 > DefaultWhitespaceChars
Default whitespace characters used for trimming operations.
void InsertionSort(Span< TKey > &keys, Span< TValue > &values, std::function< int32_t(const TKey &, const TKey &)> comparer)
Performs insertion sort on key-value pairs.
Definition: memory_extensions.h:322
const ReadOnlySpan< char16_t > DefaultWhitespaceSpan
Static ReadOnlySpan for default whitespace characters to avoid array creation.
int32_t LastIndexOfImpl(const ReadOnlySpan< T > &searchSpace, int32_t length, const T &value)
Finds the last index of a value in a span.
Definition: memory_extensions.h:186
int32_t Compare(const SharedPtr< T > &a, const SharedPtr< U > &b)
Compares two smart pointers.
Definition: memory_extensions.h:153
int32_t BinarySearchImpl(const ReadOnlySpan< T > &span, const TValue &value, TCompareFunc compareFunc)
Common binary search implementation.
Definition: memory_extensions.h:435
void Heapify(Span< TKey > &keys, Span< TValue > &values, int32_t n, int32_t i, std::function< int32_t(const TKey &, const TKey &)> comparer)
Maintains heap property for key-value pairs.
Definition: memory_extensions.h:362
void IntroSort(Span< TKey > &keys, Span< TValue > &values, int32_t depthLimit, std::function< int32_t(const TKey &, const TKey &)> comparer)
Internal implementation of introsort algorithm for key-value pairs.
Definition: memory_extensions.h:263
int32_t BinarySearch(const ReadOnlySpan< T > &span, const TComparable &comparable)
Performs binary search on a sorted span.
Definition: memory_extensions.h:2071
int32_t SequenceCompareTo(const ReadOnlySpan< T > &span, const ReadOnlySpan< T > &other)
Compares two ReadOnlySpans lexicographically.
Definition: memory_extensions.h:3098
int32_t IndexOfAny(const ReadOnlySpan< T > &span, const T &value0, const T &value1)
Finds the index of the first occurrence of any of two specified values in a ReadOnlySpan<T>
Definition: memory_extensions.h:2562
bool Overlaps(const ReadOnlySpan< T > &span, const ReadOnlySpan< T > &other)
Determines if two ReadOnlySpans overlap in memory without calculating offset.
Definition: memory_extensions.h:3011
int32_t LastIndexOfAnyExceptInRange(const ReadOnlySpan< T > &span, const T &lowInclusive, const T &highInclusive)
Finds the last occurrence of any element outside the specified range within a span.
Definition: memory_extensions.h:2973
ReadOnlySpan< T > TrimEnd(const ReadOnlySpan< T > &span, const T &trimElement)
Trims specified element from the end of a typed span.
Definition: memory_extensions.h:3358
int32_t LastIndexOfAnyInRange(const ReadOnlySpan< T > &span, const T &lowInclusive, const T &highInclusive)
Finds the last occurrence of any element within the specified range within a span.
Definition: memory_extensions.h:2992
int32_t ToUpperInvariant(const ReadOnlySpan< char16_t > &source, Span< char16_t > &destination)
Converts characters to uppercase using invariant culture.
Span< T > AsSpan(const ArrayPtr< T > &array, int32_t start=0, int32_t length=-1)
Creates a span from an array.
Definition: memory_extensions.h:2052
int32_t IndexOf(const ReadOnlySpan< T > &span, const ReadOnlySpan< T > &value)
Finds the index of a ReadOnlySpan<T> value in another ReadOnlySpan<T>
Definition: memory_extensions.h:2476
void Reverse(Span< T > &span)
Reverses the order of elements in a Span in-place.
Definition: memory_extensions.h:3085
bool ContainsAnyInRange(const ReadOnlySpan< T > &span, const T &lowInclusive, const T &highInclusive)
Checks if a read-only span contains any element within the specified range.
Definition: memory_extensions.h:2347
void CopyTo(const ArrayPtr< T > &source, Span< T > &destination)
Copies elements from an array to a span.
Definition: memory_extensions.h:2373
bool StartsWith(const ReadOnlySpan< T > &span, const T &value)
Checks if the span starts with the specified value.
Definition: memory_extensions.h:3253
void Replace(Span< T > &span, const T &oldValue, const T &newValue)
Replaces all occurrences of a value with a new value in a Span.
Definition: memory_extensions.h:3052
bool ContainsAnyExceptInRange(const ReadOnlySpan< T > &span, const T &lowInclusive, const T &highInclusive)
Checks if a read-only span contains any element outside the specified range.
Definition: memory_extensions.h:2321
bool Equals(const ReadOnlySpan< char16_t > &span, const ReadOnlySpan< char16_t > &other, StringComparison comparisonType)
Compares two ReadOnlySpan<char16_t> for equality using StringComparison.
int32_t ToLower(const ReadOnlySpan< char16_t > &source, Span< char16_t > &destination, const SharedPtr< Globalization::CultureInfo > &culture)
Converts characters to lowercase using specified culture.
int32_t LastIndexOfAnyExcept(const ReadOnlySpan< T > &span, const T &value0, const T &value1, const T &value2)
Finds the last occurrence of any element except three specified values within a span.
Definition: memory_extensions.h:2877
ReadOnlyMemory< char16_t > AsMemory(const System::String &text)
Creates a read-only memory from a string.
int32_t IndexOfAnyExcept(const ReadOnlySpan< T > &span, const T &value)
Finds the index of the first element that is not equal to the specified value in a ReadOnlySpan<T>
Definition: memory_extensions.h:2623
int32_t CommonPrefixLength(const ReadOnlySpan< T > &span, const ReadOnlySpan< T > &other)
Finds the length of the common prefix between two spans.
Definition: memory_extensions.h:2101
bool SequenceEqual(const ReadOnlySpan< T > &first, const ReadOnlySpan< T > &second)
Determines if two ReadOnlySpans contain identical elements in the same order.
Definition: memory_extensions.h:3146
int32_t LastIndexOfAny(const ReadOnlySpan< T > &span, const T &value0, const T &value1, const T &value2)
Finds the last occurrence of any of three specified values within a span.
Definition: memory_extensions.h:2810
int32_t IndexOfAnyExceptInRange(const ReadOnlySpan< T > &span, const T &lowInclusive, const T &highInclusive)
Finds the index of the first element that is outside the specified range in a ReadOnlySpan<T>
Definition: memory_extensions.h:2709
bool ContainsAny(const ReadOnlySpan< T > &span, const T &value0, const T &value1)
Checks if a read-only span contains any of two values.
Definition: memory_extensions.h:2185
bool EndsWith(const ReadOnlySpan< T > &span, const T &value)
Determines if a ReadOnlySpan<T> ends with a single value.
Definition: memory_extensions.h:2429
ReadOnlySpan< T > Trim(const ReadOnlySpan< T > &span, T trimElement)
Trims specified element from both ends of a typed span.
Definition: memory_extensions.h:3294
void Sort(const Span< T > &span, const SharedPtr< TComparer > &comparer)
Sorts a Span using a custom comparer.
Definition: memory_extensions.h:3197
int32_t CompareTo(const ReadOnlySpan< char16_t > &span, const ReadOnlySpan< char16_t > &other, StringComparison comparisonType)
Compares two character spans with specified string comparison rules.
bool ContainsAnyExcept(const ReadOnlySpan< T > &span, const T &value0, const T &value1, const T &value2)
Checks if a read-only span contains any element except three specified values.
Definition: memory_extensions.h:2228
int32_t Count(const ReadOnlySpan< T > &span, const T &value)
Counts occurrences of a value in a read-only span.
Definition: memory_extensions.h:2379
int32_t ToUpper(const ReadOnlySpan< char16_t > &source, Span< char16_t > &destination, const SharedPtr< Globalization::CultureInfo > &culture)
Converts characters to uppercase using specified culture.
int32_t LastIndexOf(const ReadOnlySpan< T > &span, const ReadOnlySpan< T > &value)
Finds the last occurrence of a sequence within a span.
Definition: memory_extensions.h:2748
ReadOnlySpan< T > TrimStart(const ReadOnlySpan< T > &span, const T &trimElement)
Trims specified element from the start of a typed span.
Definition: memory_extensions.h:3402
bool Contains(const ReadOnlySpan< T > &span, const T &value)
Checks if a read-only span contains a specific value.
Definition: memory_extensions.h:2172
int32_t IndexOfAnyInRange(const ReadOnlySpan< T > &span, const T &lowInclusive, const T &highInclusive)
Finds the index of the first element that is within the specified range in a ReadOnlySpan<T>
Definition: memory_extensions.h:2728
bool IsWhiteSpace(const ReadOnlySpan< char16_t > &span)
Checks if the entire span consists only of whitespace characters.
int32_t ToLowerInvariant(const ReadOnlySpan< char16_t > &source, Span< char16_t > &destination)
Converts characters to lowercase using invariant culture.
Definition: db_command.h:9
std::enable_if_t<!std::is_floating_point< TA >::value &&!std::is_floating_point< TB >::value, int > Compare(const TA &a, const TB &b)
Compares two values.
Definition: primitive_types.h:113
StringComparison
Defines string comparison style.
Definition: string_comparison.h:13