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
 Splits a slice and iterates over the split portions. More...
 
struct  SplitIter< T, Slice< T > >
 
struct  SplitOneOfIter
 

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_right (Slice< T > slice, size_t amt)
 Shifts elements to the right by a certain number of places Does not loop around.
 
template<typename T>
void shift_left (Slice< T > slice, size_t amt)
 Shifts elements to the left by a certain number of places Does not loop around.
 
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_one_of (const Slice< T > &needles, const Slice< T > &haystack)
 Gets the first index that one of the provided needles 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.
 
template<typename T>
SplitOneOfIter< T > split_one_of (const Slice< std::add_const_t< T > > &needles, 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_left()

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

Shifts elements to the left by a certain number of places Does not loop around.

Template Parameters
TSlice element type
Parameters
sliceSlice to shift
amtAmount to shift by

Definition at line 85 of file slice_algo.hpp.

85 {
86 for (size_t i = slice.size(); i > 0; --i) {
87 auto destIndex = i - amt;
88 if (destIndex < amt) {
89 break;
90 }
91 auto srcIndex = destIndex - amt;
92 slice[destIndex] = slice[srcIndex];
93 }
94 }
constexpr size_t size() const noexcept
Gets the size of a Slice.
Here is the call graph for this function:

◆ shift_right()

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

Shifts elements to the right by a certain number of places Does not loop around.

Template Parameters
TSlice element type
Parameters
sliceSlice to shift
amtAmount to shift by

Definition at line 66 of file slice_algo.hpp.

66 {
67 for (size_t i = 0; i < slice.size() - amt; ++i) {
68 auto destIndex = i + amt;
69 if (destIndex < amt) {
70 break;
71 }
72 auto srcIndex = destIndex - amt;
73 slice[destIndex] = slice[srcIndex];
74 }
75 }
Here is the call graph for this function: