1 #ifndef _MADARA_UTILITY_INL_ 2 #define _MADARA_UTILITY_INL_ 12 if (prefix.length () <= input.length ())
14 result = input.substr (0, prefix.length ()) == prefix;
26 if (match.length () <= input.length ())
29 input.substr (input.size () - match.length (), match.length ()) == match;
48 return (mask & values) > 0;
57 return mask & ~values;
78 bool (*comparator) (
const T & left,
const T & right))
81 for (
int child = root * 2 + 1; child <= end; child = root * 2 + 1)
86 if (comparator (input[child], input[swap]))
91 if (child <= end && comparator (input[child], input[swap]))
96 std::swap (input[root], input[swap]);
104 template <
typename T>
107 bool (*comparator) (
const T & left,
const T & right))
110 for (
int start = (size - 2) / 2; start >= 0; --start)
112 sift_down (input, start, size - 1, comparator);
116 template <
typename T>
119 bool (*comparator) (
const T & left,
const T & right))
121 heapify (input, size, comparator);
123 for (
int end = size - 1; end > 0; --end)
125 std::swap (input[end], input[0]);
130 #endif // _MADARA_UTILITY_INL_ bool bitmask_check(T mask, T values)
Returns true if mask contains values.
T bitmask_add(T mask, T values)
Adds values to a bit mask.
void sift_down(T *input, int start, int end, bool(*comparator)(const T &left, const T &right)=greater_compare< T >)
Sifts elements down a heap according to a comparator.
bool greater_compare(const T &left, const T &right)
Returns true if right < left.
void heap_sort(T *input, int size, bool(*comparator)(const T &left, const T &right)=greater_compare< T >)
Sorts an array with heap sort.
void heapify(T *input, int size, bool(*comparator)(const T &left, const T &right)=greater_compare< T >)
Builds a heap out of an array of elements.
T bitmask_remove(T mask, T values)
Removes values from a bit mask.
bool less_compare(const T &left, const T &right)
Returns true if left < right.
MADARA_Export bool begins_with(const std::string &input, const std::string &prefix)
Check if input contains prefix at the beginning.
MADARA_Export bool ends_with(const std::string &input, const std::string &ending)
Check if input contains a pattern at the end.