Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FindSequence.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Algo/Impl/RangePointerType.h"
6
7namespace AlgoImpl
8{
9 template<typename WhereType, typename WhatType>
10 constexpr WhereType* FindSequence(WhereType* First, WhereType* Last, WhatType* WhatFirst, WhatType* WhatLast)
11 {
12 for (; ; ++First)
13 {
14 WhereType* It = First;
15 for (WhatType* WhatIt = WhatFirst; ; ++It, ++WhatIt)
16 {
17 if (WhatIt == WhatLast)
18 {
19 return First;
20 }
21 if (It == Last)
22 {
23 return nullptr;
24 }
25 if (!(*It == *WhatIt))
26 {
27 break;
28 }
29 }
30 }
31 }
32}
33
34namespace Algo
35{
36
37 /*
38 * Searches for the first occurrence of a sequence of elements in another sequence.
39 *
40 * @param Where The range to search
41 * @param What The sequence to search for.
42 *
43 * @return A pointer to the first occurrence of the "What" sequence in "Where" sequence, or nullptr if not found.
44 */
45 template<typename RangeWhereType, typename RangeWhatType>
46 FORCEINLINE auto FindSequence(const RangeWhereType& Where, const RangeWhatType& What)
47 -> decltype( AlgoImpl::FindSequence( GetData(Where), GetData(Where) + GetNum(Where), GetData(What), GetData(What) + GetNum(What)) )
48 {
49 if (GetNum(What) > GetNum(Where))
50 {
51 return nullptr;
52 }
53 else
54 {
55 return AlgoImpl::FindSequence(
58 }
59 }
60
61}
#define FORCEINLINE
Definition Platform.h:644
Definition Heapify.h:12
FORCEINLINE auto FindSequence(const RangeWhereType &Where, const RangeWhatType &What) -> decltype(AlgoImpl::FindSequence(GetData(Where), GetData(Where)+GetNum(Where), GetData(What), GetData(What)+GetNum(What)))
constexpr WhereType * FindSequence(WhereType *First, WhereType *Last, WhatType *WhatFirst, WhatType *WhatLast)