MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mtcore::slices Namespace Reference

Additional algorithms that can be performed on slices, such as comparisons, searching, etc. More...

Classes

struct  SearchIndexes
 
struct  SplitIter
 
struct  SplitIter< T, Slice< T > >
 

Functions

template<typename T>
bool starts_with (const Slice< T > &needle, const Slice< T > &haystack)
 Checks whether a slice (the haystack) starts with elements in another slice in the same order (the needle) - \(O(N)\) Uses the equality operator of the underlying type E.g.
 
template<typename T>
void shift (Slice< T > slice, size_t amt)
 
template<typename T>
bool starts_with (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Checks whether a slice (the haystack) starts with a specific element (the needle) - \(O(N)\) Uses the equality operator of the underlying type E.g.
 
template<typename T>
bool contains (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Checks whether a slice (the haystack) contains an element (the needle) Uses the equality operator of the underlying type E.g.
 
template<typename T>
bool contains (const Slice< T > &needle, const Slice< T > &haystack)
 Checks whether a slice (the haystack) contains elements in another slice in the same order (the needle) - \(O(N^2)\) Uses the equality operator of the underlying type E.g.
 
template<typename T>
mtcore::Optional< size_t > first_index_not_proceeded_by (const std::remove_const_t< T > &prefix, const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > first_index_not_proceeded_by (const std::remove_const_t< T > &prefix, const Slice< T > &needle, const Slice< T > &haystack)
 Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > first_index (const Slice< T > &needle, const Slice< T > &haystack)
 Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > first_index_not (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > first_index (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > last_index (const Slice< T > &needle, const Slice< T > &haystack)
 Gets the last index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > last_index (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Gets the last index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
SearchIndexes< T, Slice< T > > indexes_of (const Slice< T > &needle, const Slice< T > &haystack)
 Returns an iterator of all indexes of occurrences of a needle in a haystack If the needle isn't present, will return an empty iterator.
 
template<typename T>
SearchIndexes< T, std::remove_const_t< T > > indexes_of (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Returns an iterator of all indexes of occurrences of a needle in a haystack If the needle isn't present, will return an empty iterator.
 
template<typename T>
SplitIter< T, Slice< T > > split (const Slice< T > &needle, const Slice< T > &haystack)
 Splits a slice into smaller sub slices.
 
template<typename T>
SplitIter< T, std::remove_const_t< T > > split (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Splits a slice into smaller sub slices.
 

Detailed Description

Additional algorithms that can be performed on slices, such as comparisons, searching, etc.

Function Documentation

◆ shift()

template<typename T>
void mtcore::slices::shift ( Slice< T > slice,
size_t amt )

Definition at line 58 of file slice_algo.hpp.

58 {
59 for (size_t i = slice.size(); i > 0; --i) {
60 auto destIndex = i - 1;
61 if (destIndex < amt) {
62 break;
63 }
64 auto srcIndex = destIndex - amt;
65 slice[destIndex] = slice[srcIndex];
66 }
67 }
constexpr size_t size() const noexcept
Gets the size of a Slice.
Here is the call graph for this function: