2#ifndef _aspose_system_memory_extensions_h_
3#define _aspose_system_memory_extensions_h_
7#include <system/span.h>
8#include <system/object.h>
9#include <system/object_ext.h>
10#include <system/details/stack_array.h>
11#include <system/smart_ptr.h>
12#include <system/exceptions.h>
13#include <system/comparison.h>
18namespace MemoryExtensions {
32template <
typename T,
typename U>
42 Compare(
const T& a,
const T& b);
50template <
typename T,
typename U>
81template <
typename TKey,
typename TValue>
83 std::function<int32_t(
const TKey&,
const TKey&)> comparer);
93template <
typename TKey,
typename TValue>
95 std::function<int32_t(
const TKey&,
const TKey&)> comparer, int32_t i, int32_t j);
103template <
typename TKey,
typename TValue>
112template <
typename TKey,
typename TValue>
123template <
typename TKey,
typename TValue>
125 std::function<int32_t(
const TKey&,
const TKey&)> comparer);
134template <
typename TKey,
typename TValue>
136 std::function<int32_t(
const TKey&,
const TKey&)> comparer);
146template <
typename T,
typename TValue,
typename TCompareFunc>
149template <
typename T,
typename U>
165 return (*a).CompareTo(b);
175template <
typename T,
typename U>
179 return (*a).CompareTo(b);
259template <
typename TKey,
typename TValue>
261 std::function<int32_t(
const TKey&,
const TKey&)> comparer)
263 int32_t partitionSize = keys.get_Length();
264 while (partitionSize > 1)
266 if (partitionSize <= 16)
268 if (partitionSize == 2)
274 if (partitionSize == 3)
296 int32_t rightSize = partitionSize - p - 1;
299 IntroSort(keys.Slice(p + 1, rightSize), values.Slice(p + 1, rightSize), depthLimit, comparer);
307template <
typename TKey,
typename TValue>
309 std::function<int32_t(
const TKey&,
const TKey&)> comparer, int32_t i, int32_t j)
311 if (comparer(keys.get(i), keys.get(j)) > 0)
313 std::swap(keys.get(i), keys.get(j));
314 std::swap(values.get(i), values.get(j));
318template <
typename TKey,
typename TValue>
321 for (int32_t i = 0; i < keys.get_Length() - 1; i++)
323 TKey t = keys.get(i + 1);
324 TValue tValue = values.get(i + 1);
327 while (j >= 0 && keys.get(j) != t && !comparer(t, keys.get(j)))
329 keys.get(j + 1) = keys.get(j);
330 values.get(j + 1) = values.get(j);
335 values.get(j + 1) = tValue;
339template <
typename TKey,
typename TValue>
343 for (int32_t i = keys.get_Length() / 2 - 1; i >= 0; i--)
345 Heapify(keys, values, keys.get_Length(), i, comparer);
349 for (int32_t i = keys.get_Length() - 1; i > 0; i--)
351 std::swap(keys.get(0), keys.get(i));
352 std::swap(values.get(0), values.get(i));
353 Heapify(keys, values, i, 0, comparer);
358template <
typename TKey,
typename TValue>
360 std::function<int32_t(
const TKey&,
const TKey&)> comparer)
363 int32_t left = 2 * i + 1;
364 int32_t right = 2 * i + 2;
366 if (left < n && comparer(keys.get(left), keys.get(largest)) > 0)
371 if (right < n && comparer(keys.get(right), keys.get(largest)) > 0)
378 std::swap(keys.get(i), keys.get(largest));
379 std::swap(values.get(i), values.get(largest));
380 Heapify(keys, values, n, largest, comparer);
384template <
typename TKey,
typename TValue>
386 std::function<int32_t(
const TKey&,
const TKey&)> comparer)
389 int32_t middle = keys.get_Length() / 2;
390 int32_t last = keys.get_Length() - 1;
393 if (comparer(keys.get(0), keys.get(middle)) > 0)
395 std::swap(keys.get(0), keys.get(middle));
396 std::swap(values.get(0), values.get(middle));
398 if (comparer(keys.get(0), keys.get(last)) > 0)
400 std::swap(keys.get(0), keys.get(last));
401 std::swap(values.get(0), values.get(last));
403 if (comparer(keys.get(middle), keys.get(last)) > 0)
405 std::swap(keys.get(middle), keys.get(last));
406 std::swap(values.get(middle), values.get(last));
410 std::swap(keys.get(middle), keys.get(last));
411 std::swap(values.get(middle), values.get(last));
413 TKey pivot = keys.get(last);
416 for (int32_t j = 0; j < last; j++)
418 if (comparer(keys.get(j), pivot) <= 0)
421 std::swap(keys.get(i), keys.get(j));
422 std::swap(values.get(i), values.get(j));
426 std::swap(keys.get(i + 1), keys.get(last));
427 std::swap(values.get(i + 1), values.get(last));
431template <
typename T,
typename TValue,
typename TCompareFunc>
435 int32_t hi = span.get_Length() - 1;
440 int32_t i =
static_cast<int32_t
>((
static_cast<uint32_t
>(hi) +
static_cast<uint32_t
>(lo)) >> 1);
441 int32_t c = compareFunc(value, span.get(i));
477template <
typename T,
typename TComparable>
488template <
typename T,
typename TComparer>
498template <
typename T,
typename TComparable>
509template <
typename T,
typename TComparer>
547template <
typename T,
typename TEqualityComparer>
560template <
typename T,
typename TEqualityComparer>
572template <
typename T,
typename TEqualityComparer>
633bool ContainsAny(
const Span<T>& span,
const T& value0,
const T& value1,
const T& value2);
936int32_t
IndexOfAny(
const Span<T>& span,
const T& value0,
const T& value1,
const T& value2);
1004template <
typename T>
1015template <
typename T>
1024template <
typename T>
1033template <
typename T>
1043template <
typename T>
1053template <
typename T>
1063template <
typename T>
1073template <
typename T>
1082template <
typename T>
1091template <
typename T>
1100template <
typename T>
1109template <
typename T>
1120template <
typename T>
1131template <
typename T>
1141template <
typename T>
1151template <
typename T>
1160template <
typename T>
1169template <
typename T>
1178template <
typename T>
1189template <
typename T>
1200template <
typename T>
1210template <
typename T>
1220template <
typename T>
1229template <
typename T>
1238template <
typename T>
1247template <
typename T>
1256template <
typename T>
1265template <
typename T>
1275template <
typename T>
1285template <
typename T>
1295template <
typename T>
1305template <
typename T>
1314template <
typename T>
1323template <
typename T>
1333template <
typename T>
1343template <
typename T>
1352template <
typename T>
1353void Replace(
Span<T>& span,
const T& oldValue,
const T& newValue);
1363template <
typename T>
1369template <
typename T>
1377template <
typename T>
1385template <
typename T>
1394template <
typename T>
1403template <
typename T>
1412template <
typename T>
1423template <
typename T,
typename TComparer>
1434template <
typename T,
typename TComparer>
1443template <
typename T,
typename TComparer>
1450template <
typename T>
1462template <
typename TKey,
typename TValue,
typename TComparer>
1473template <
typename TKey,
typename TValue>
1483template <
typename TKey,
typename TValue>
1492template <
typename T>
1501template <
typename T>
1510template <
typename T>
1519template <
typename T>
1528template <
typename T>
1537template <
typename T>
1546template <
typename T>
1555template <
typename T>
1564template <
typename T>
1573template <
typename T>
1582template <
typename T>
1591template <
typename T>
1600template <
typename T>
1609template <
typename T>
1618template <
typename T>
1627template <
typename T>
1636template <
typename T>
1645template <
typename T>
1654template <
typename T>
1663template <
typename T>
1672template <
typename T>
1777 if (span.get_Length() == 0)
1782 return (span.get(0)).Equals(value);
1823 int32_t endIndex = span.get_Length() - 1;
1824 while (endIndex >= 0 && span.get(endIndex) == trimchar)
1828 return span.Slice(0, endIndex + 1);
1837 int32_t endIndex = span.get_Length() - 1;
1838 while (endIndex >= 0 && span.get(endIndex) == trimchar)
1842 return span.Slice(0, endIndex + 1);
1851 int32_t endIndex = span.get_Length() - 1;
1852 while (endIndex >= 0 &&
Contains(trimChars, span.get(endIndex)))
1856 return span.Slice(0, endIndex + 1);
1865 int32_t endIndex = span.get_Length() - 1;
1866 while (endIndex >= 0 &&
Contains(trimchars, span.get(endIndex)))
1870 return span.Slice(0, endIndex + 1);
1895 int32_t startIndex = 0;
1896 while (startIndex < span.get_Length() && span.get(startIndex) == trimchar)
1900 return span.Slice(startIndex);
1909 int32_t startIndex = 0;
1910 while (startIndex < span.get_Length() && span.get(startIndex) == trimchar)
1914 return span.Slice(startIndex);
1923 int32_t startIndex = 0;
1924 while (startIndex < span.get_Length() &&
Contains(trimchars, span.get(startIndex)))
1928 return span.Slice(startIndex);
1937 int32_t startIndex = 0;
1938 while (startIndex < span.get_Length() &&
Contains(trimchars, span.get(startIndex)))
1942 return span.Slice(startIndex);
1945template <
typename T>
1948 if (array ==
nullptr)
1950 throw ArgumentNullException(u
"array is null");
1952 if (start < 0 || (length < 0 && length != -1) ||
1953 (length == -1 ? start > array->get_Length() : start + length > array->get_Length()))
1955 throw ArgumentOutOfRangeException(u
"start or length is out of range");
1959 length = array->get_Length() - start;
1961 return Span<T>(array, start, length);
1964template <
typename T,
typename TComparable>
1968 [](
const TComparable& search_value,
const T& container_value) -> int32_t {
1973template <
typename T,
typename TComparer>
1977 [&comparerPtr](
const T& search_value,
const T& container_value) -> int32_t {
1978 return comparerPtr->Compare(search_value, container_value);
1982template <
typename T,
typename TComparable>
1988template <
typename T,
typename TComparer>
1994template <
typename T>
1997 int32_t commonLength = 0;
1998 int32_t minLength = std::min(span.get_Length(), other.get_Length());
2001 for (int32_t i = 0; i < minLength; ++i)
2013 return commonLength;
2016template <
typename T>
2022template <
typename T>
2028template <
typename T,
typename TEqualityComparer>
2032 int32_t commonLength = 0;
2033 int32_t minLength = std::min(span.get_Length(), other.get_Length());
2036 for (int32_t i = 0; i < minLength; ++i)
2039 (comparer !=
nullptr && comparer->Equals(span.get(i), other.get(i))))
2049 return commonLength;
2052template <
typename T,
typename TEqualityComparer>
2059template <
typename T,
typename TEqualityComparer>
2065template <
typename T>
2068 return std::find_if(span.begin(), span.end(), [&value](
const T& item) { return System::ObjectExt::Equals(value, item); }) !=
2072template <
typename T>
2075 return std::find(span.begin(), span.end(), value) != span.end();
2078template <
typename T>
2084template <
typename T>
2090template <
typename T>
2096template <
typename T>
2102template <
typename T>
2105 for (
const auto& value : values)
2115template <
typename T>
2121template <
typename T>
2124 for (
auto& member : span)
2135template <
typename T>
2141template <
typename T>
2144 for (
auto& member : span)
2154template <
typename T>
2160template <
typename T>
2163 for (
auto& member : span)
2173template <
typename T>
2179template <
typename T>
2182 switch (values.get_Length())
2185 return span.get_IsEmpty() ? false :
true;
2197 for (
auto& member : span)
2208template <
typename T>
2214template <
typename T>
2217 for (
const auto& value : span)
2219 if (value < lowInclusive || value > highInclusive)
2227template <
typename T>
2230 for (
const auto& value : span)
2232 if (value < lowInclusive || value > highInclusive)
2240template <
typename T>
2243 for (
const auto& value : span)
2245 if (value >= lowInclusive && value <= highInclusive)
2253template <
typename T>
2256 for (
const auto& value : span)
2258 if (value >= lowInclusive && value <= highInclusive)
2266template <
typename T>
2272template <
typename T>
2276 for (
const auto& item : span)
2286template <
typename T>
2289 switch (value.get_Length())
2295 return Count(span, value.get(0));
2301 while ((pos =
IndexOf(currentSpan, value)) >= 0)
2304 currentSpan = currentSpan.Slice(pos + value.get_Length());
2310template <
typename T>
2316template <
typename T>
2322template <
typename T>
2325 if (span.get_Length() == 0)
2332template <
typename T>
2335 int32_t spanLength = span.get_Length();
2336 int32_t valueLength = value.get_Length();
2338 if (valueLength > spanLength)
2343 if (valueLength == spanLength)
2348 return SequenceEqual(span.Slice(spanLength - valueLength), value);
2351template <
typename T>
2357template <
typename T>
2363template <
typename T>
2369template <
typename T>
2372 if (value.get_Length() == 0)
2377 const T& valueHead = value.get(0);
2378 int32_t valueTailLength = value.get_Length() - 1;
2383 if (index + valueTailLength > span.get_Length())
2389 int32_t remainingSearchSpaceLength = span.get_Length() - index - valueTailLength;
2390 int32_t relativeIndex = -1;
2392 for (int32_t i = 0; i < remainingSearchSpaceLength; ++i)
2401 if (relativeIndex == -1)
2406 index += relativeIndex;
2409 bool tailMatches =
true;
2410 for (int32_t i = 0; i < valueTailLength; ++i)
2412 if (span.get(index + 1 + i) != value.get(1 + i))
2414 tailMatches =
false;
2430template <
typename T>
2433 for (int32_t i = 0; i < span.get_Length(); ++i)
2443template <
typename T>
2449template <
typename T>
2455template <
typename T>
2458 for (int32_t i = 0; i < span.get_Length(); ++i)
2468template <
typename T>
2471 for (int32_t i = 0; i < span.get_Length(); ++i)
2482template <
typename T>
2488template <
typename T>
2494template <
typename T>
2497 for (int32_t i = 0; i < span.get_Length(); ++i)
2499 for (int32_t j = 0; j < values.get_Length(); ++j)
2510template <
typename T>
2516template <
typename T>
2519 for (int32_t i = 0; i < span.get_Length(); ++i)
2529template <
typename T>
2532 for (int32_t i = 0; i < span.get_Length(); ++i)
2542template <
typename T>
2545 for (int32_t i = 0; i < span.get_Length(); ++i)
2556template <
typename T>
2562template <
typename T>
2568template <
typename T>
2574template <
typename T>
2577 for (int32_t i = 0; i < span.get_Length(); ++i)
2580 for (int32_t j = 0; j < values.get_Length(); ++j)
2596template <
typename T>
2602template <
typename T>
2605 for (int32_t i = 0; i < span.get_Length(); ++i)
2615template <
typename T>
2621template <
typename T>
2624 for (int32_t i = 0; i < span.get_Length(); ++i)
2635template <
typename T>
2641template <
typename T>
2644 if (value.get_Length() == 0)
2645 return span.get_Length();
2647 int32_t valueTailLength = value.get_Length() - 1;
2648 if (valueTailLength == 0)
2650 return LastIndexOf<T>(span, value.get(0));
2655 T valueHead = value.get(0);
2660 int32_t remainingSearchSpaceLength = span.get_Length() - index - valueTail.get_Length();
2661 if (remainingSearchSpaceLength <= 0)
2665 int32_t relativeIndex = Details::LastIndexOfImpl<T>(span, remainingSearchSpaceLength, valueHead);
2666 if (relativeIndex < 0)
2670 if (Details::SequenceEqualImpl<T>(span, relativeIndex + 1, valueTail.get_Length(), valueTail))
2671 return relativeIndex;
2673 index += remainingSearchSpaceLength - relativeIndex;
2678template <
typename T>
2681 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2691template <
typename T>
2697template <
typename T>
2703template <
typename T>
2706 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2717template <
typename T>
2723template <
typename T>
2726 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2736template <
typename T>
2742template <
typename T>
2745 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2747 for (int32_t j = 0; j < values.get_Length(); ++j)
2758template <
typename T>
2764template <
typename T>
2770template <
typename T>
2773 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2775 const T& current = span.get(i);
2785template <
typename T>
2791template <
typename T>
2794 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2796 const T& current = span.get(i);
2805template <
typename T>
2811template <
typename T>
2814 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2816 T current = span.get(i);
2825template <
typename T>
2831template <
typename T>
2834 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2836 const T& current = span.get(i);
2838 for (
auto& value : values)
2854template <
typename T>
2860template <
typename T>
2866template <
typename T>
2869 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2879template <
typename T>
2885template <
typename T>
2888 for (int32_t i = span.get_Length() - 1; i >= 0; --i)
2898template <
typename T>
2904template <
typename T>
2908 return Overlaps(span, other, offset);
2911template <
typename T>
2917template <
typename T>
2920 if (span.get_IsEmpty() || other.get_IsEmpty())
2925 ptrdiff_t Offset = other.begin() - span.begin();
2926 bool isOverlap = (Offset >= 0 && Offset < span.get_Length()) || (Offset < 0 && -Offset < other.get_Length());
2930 elementOffset =
static_cast<int32_t
>(Offset);
2939template <
typename T>
2945template <
typename T>
2948 for (int32_t i = 0; i < span.get_Length(); ++i)
2952 span.get(i) = newValue;
2957template <
typename T>
2960 if (destination.get_Length() < source.get_Length())
2962 throw ArgumentException(u
"Destination span is smaller than source span.");
2965 for (int32_t i = 0; i < source.get_Length(); ++i)
2969 destination.get(i) = newValue;
2973 destination.get(i) = source.get(i);
2978template <
typename T>
2982 int32_t right = span.get_Length() - 1;
2983 while (left < right)
2985 std::swap(span.get(left), span.get(right));
2991template <
typename T>
2994 auto spanIt = span.begin();
2995 auto otherIt = other.begin();
2996 auto spanEnd = span.end();
2997 auto otherEnd = other.end();
2999 while (spanIt != spanEnd && otherIt != otherEnd)
3001 if (*spanIt < *otherIt)
3005 if (*spanIt > *otherIt)
3015 if (span.get_Length() < other.get_Length())
3019 if (span.get_Length() > other.get_Length())
3027template <
typename T>
3033template <
typename T>
3039template <
typename T>
3042 if (first == second)
3045 if (first.get_Length() != second.get_Length())
3050 int32_t length = second.get_Length();
3055template <
typename T>
3061template <
typename T,
typename TComparer>
3064 if (comparer ==
nullptr)
3069 if (span.get_Length() != other.get_Length())
3074 for (int32_t i = 0; i < span.get_Length(); ++i)
3076 if (!comparer->Equals(span.get(i), other.get(i)))
3084template <
typename T,
typename TComparer>
3090template <
typename T,
typename TComparer>
3093 std::sort(span.begin(), span.end(), [&comparer](
const T& a,
const T& b) ->
bool { return comparer->Compare(a, b) < 0; });
3096template <
typename T>
3099 std::sort(span.begin(), span.end());
3102template <
typename TKey,
typename TValue,
typename TComparer>
3105 if (keys.get_Length() != values.get_Length())
3107 throw ArgumentException(u
"Keys and items must have the same length.");
3109 if (keys.get_Length() > 1)
3111 int32_t depthLimit = 2 * (
static_cast<int32_t
>(std::log2(keys.get_Length())) + 1);
3112 Details::IntroSort<TKey, TValue>(keys, values, depthLimit,
3113 [&comparer](TKey a, TKey b) ->
bool {
return comparer->Compare(a, b) > 0; });
3117template <
typename TKey,
typename TValue>
3120 if (keys.get_Length() != values.get_Length())
3122 throw ArgumentException(u
"Keys and items must have the same length.");
3124 if (keys.get_Length() > 1)
3126 int32_t depthLimit = 2 * (
static_cast<int32_t
>(std::log2(keys.get_Length())) + 1);
3127 Details::IntroSort<TKey, TValue>(keys, values, depthLimit,
3128 [&](
const TKey& a,
const TKey& b) {
return !comparer(a, b); });
3132template <
typename TKey,
typename TValue>
3135 if (keys.get_Length() != values.get_Length())
3137 throw ArgumentException(u
"Keys and items must have the same length.");
3139 if (keys.get_Length() > 1)
3141 int32_t depthLimit = 2 * (
static_cast<int32_t
>(std::log2(keys.get_Length())) + 1);
3142 Details::IntroSort<TKey, TValue>(keys, values, depthLimit, [&](
const TKey& a,
const TKey& b) {
return a > b; });
3146template <
typename T>
3149 if (span.get_Length() == 0)
3153 return System::ObjectExt::Equals<T>(span.get(0), value);
3156template <
typename T>
3159 if (value.get_Length() > span.get_Length())
3164 for (int32_t i = 0; i < value.get_Length(); ++i)
3175template <
typename T>
3181template <
typename T>
3187template <
typename T>
3193template <
typename T>
3199template <
typename T>
3202 if (span.get_IsEmpty())
3208 int32_t end = span.get_Length() - 1;
3211 while (start <= end &&
Contains(trimElements, span.get(start)))
3217 while (end >= start &&
Contains(trimElements, span.get(end)))
3222 return span.Slice(start, end - start + 1);
3225template <
typename T>
3228 if (span.get_IsEmpty())
3234 int32_t end = span.get_Length() - 1;
3237 while (start <= end &&
Contains(trimElements, span.get(start)))
3243 while (end >= start &&
Contains(trimElements, span.get(end)))
3248 return span.Slice(start, end - start + 1);
3251template <
typename T>
3254 int32_t endIndex = span.get_Length() - 1;
3259 return span.Slice(0, endIndex + 1);
3262template <
typename T>
3265 int32_t endIndex = span.get_Length() - 1;
3270 return span.Slice(0, endIndex + 1);
3273template <
typename T>
3276 int32_t endIndex = span.get_Length() - 1;
3277 while (endIndex >= 0 &&
Contains(trimElements, span.get(endIndex)))
3281 return span.Slice(0, endIndex + 1);
3284template <
typename T>
3287 int32_t endIndex = span.get_Length() - 1;
3288 while (endIndex >= 0 &&
Contains(trimElements, span.get(endIndex)))
3292 return span.Slice(0, endIndex + 1);
3295template <
typename T>
3298 int32_t startIndex = 0;
3303 return span.Slice(startIndex);
3306template <
typename T>
3309 int32_t startIndex = 0;
3314 return span.Slice(startIndex);
3317template <
typename T>
3320 int32_t startIndex = 0;
3321 while (startIndex < span.get_Length() &&
Contains(trimElements, span.get(startIndex)))
3325 return span.Slice(startIndex);
3328template <
typename T>
3331 int32_t startIndex = 0;
3332 while (startIndex < span.get_Length() &&
Contains(trimElements, span.get(startIndex)))
3336 return span.Slice(startIndex);
Represents a pointer to the method that compares two objects of the same type. This type should be al...
Definition: comparison.h:93
static std::enable_if< IsExceptionWrapper< T >::value, bool >::type Equals(const T &obj, const T2 &another)
Definition: object_ext.h:34
Forward to use within Span class.
Definition: span.h:411
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:371
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
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:223
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:308
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:385
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:340
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:319
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:183
int32_t Compare(const SharedPtr< T > &a, const SharedPtr< U > &b)
Compares two smart pointers.
Definition: memory_extensions.h:150
int32_t BinarySearchImpl(const ReadOnlySpan< T > &span, const TValue &value, TCompareFunc compareFunc)
Common binary search implementation.
Definition: memory_extensions.h:432
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:359
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:260
int32_t BinarySearch(const ReadOnlySpan< T > &span, const TComparable &comparable)
Performs binary search on a sorted span.
Definition: memory_extensions.h:1965
int32_t SequenceCompareTo(const ReadOnlySpan< T > &span, const ReadOnlySpan< T > &other)
Compares two ReadOnlySpans lexicographically.
Definition: memory_extensions.h:2992
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:2456
bool Overlaps(const ReadOnlySpan< T > &span, const ReadOnlySpan< T > &other)
Determines if two ReadOnlySpans overlap in memory without calculating offset.
Definition: memory_extensions.h:2905
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:2867
ReadOnlySpan< T > TrimEnd(const ReadOnlySpan< T > &span, const T &trimElement)
Trims specified element from the end of a typed span.
Definition: memory_extensions.h:3252
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:2886
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:1946
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:2370
void Reverse(Span< T > &span)
Reverses the order of elements in a Span in-place.
Definition: memory_extensions.h:2979
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:2241
void CopyTo(const ArrayPtr< T > &source, Span< T > &destination)
Copies elements from an array to a span.
Definition: memory_extensions.h:2267
bool StartsWith(const ReadOnlySpan< T > &span, const T &value)
Checks if the span starts with the specified value.
Definition: memory_extensions.h:3147
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:2946
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:2215
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:2771
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:2517
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:1995
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:3040
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:2704
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:2603
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:2079
bool EndsWith(const ReadOnlySpan< T > &span, const T &value)
Determines if a ReadOnlySpan<T> ends with a single value.
Definition: memory_extensions.h:2323
ReadOnlySpan< T > Trim(const ReadOnlySpan< T > &span, T trimElement)
Trims specified element from both ends of a typed span.
Definition: memory_extensions.h:3188
void Sort(const Span< T > &span, const SharedPtr< TComparer > &comparer)
Sorts a Span using a custom comparer.
Definition: memory_extensions.h:3091
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:2122
int32_t Count(const ReadOnlySpan< T > &span, const T &value)
Counts occurrences of a value in a read-only span.
Definition: memory_extensions.h:2273
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:2642
ReadOnlySpan< T > TrimStart(const ReadOnlySpan< T > &span, const T &trimElement)
Trims specified element from the start of a typed span.
Definition: memory_extensions.h:3296
bool Contains(const ReadOnlySpan< T > &span, const T &value)
Checks if a read-only span contains a specific value.
Definition: memory_extensions.h:2066
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:2622
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