<commit_before>/**********************************************************\

  momo/Utility.h

  namespace momo:
    enum class CheckMode
    enum class ExtraCheckMode
    struct IsTriviallyRelocatable

\**********************************************************/

#pragma once

#include "Settings.h"

#include <cstdint>
#include <cstddef>
#include <type_traits>
#include <cstring>
#include <memory>
#include <cassert>
#include <exception>
#include <algorithm>
#include <functional>
#include <stdexcept>

#ifdef MOMO_USE_INIT_LISTS
#include <initializer_list>
#endif

#ifdef MOMO_USE_MEM_MANAGER_WIN
#include <Windows.h>
#endif

#ifdef MOMO_USE_NOEXCEPT
#define MOMO_NOEXCEPT noexcept
#define MOMO_NOEXCEPT_IF(expr) noexcept(expr)
#else
#define MOMO_NOEXCEPT throw()
#define MOMO_NOEXCEPT_IF(expr)
#endif

#ifdef MOMO_USE_DELETE_FUNCS
#define MOMO_DISABLE_COPY_CONSTRUCTOR(Class) Class(const Class&) = delete;
#define MOMO_DISABLE_COPY_OPERATOR(Class) Class& operator=(const Class&) = delete;
#else
#define MOMO_DISABLE_COPY_CONSTRUCTOR(Class) Class(const Class&);
#define MOMO_DISABLE_COPY_OPERATOR(Class) Class& operator=(const Class&);
#endif

#if MOMO_USE_UNSAFE_MOVE_CONSTRUCTORS == 1
#define MOMO_IS_NOTHROW_MOVE_CONSTRUCTIBLE(Object) \
	std::is_nothrow_move_constructible<Object>::value \
	|| !std::is_copy_constructible<Object>::value
#elif MOMO_USE_UNSAFE_MOVE_CONSTRUCTORS == 2
#define MOMO_IS_NOTHROW_MOVE_CONSTRUCTIBLE(Object) true
#else
#define MOMO_IS_NOTHROW_MOVE_CONSTRUCTIBLE(Object) \
	std::is_nothrow_move_constructible<Object>::value
#endif

#define MOMO_FRIEND_SWAP(Container) \
	friend void swap(Container& cont1, Container& cont2) MOMO_NOEXCEPT \
	{ \
		cont1.Swap(cont2); \
	}

#define MOMO_FRIENDS_BEGIN_END(ContainerRef, Iterator) \
	friend Iterator begin(ContainerRef contRef) MOMO_NOEXCEPT \
	{ \
		return contRef.GetBegin(); \
	} \
	friend Iterator end(ContainerRef contRef) MOMO_NOEXCEPT \
	{ \
		return contRef.GetEnd(); \
	}

#define MOMO_STATIC_ASSERT(expr) static_assert((expr), #expr);

#define MOMO_CHECK_TYPE(Type, var) \
	MOMO_STATIC_ASSERT((std::is_same<Type, typename std::decay<decltype(var)>::type>::value));

#define MOMO_CHECK(expr) assert(Settings::checkMode != CheckMode::assertion || (expr)); \
	if (Settings::checkMode != CheckMode::exception || (expr)) ; else throw std::invalid_argument(#expr);

#define MOMO_EXTRA_CHECK(expr) assert(Settings::extraCheckMode != ExtraCheckMode::assertion || (expr));

namespace momo
{

enum class CheckMode
{
	assertion = 1,
	exception = 2,
};

enum class ExtraCheckMode
{
	nothing = 0,
	assertion = 1,
};

template<typename Object>
struct IsTriviallyRelocatable : public MOMO_IS_TRIVIALLY_COPYABLE<Object>
{
};

namespace internal
{
	template<typename Iterator>
	struct IsForwardIterator : public std::is_base_of<std::forward_iterator_tag,
		typename std::iterator_traits<Iterator>::iterator_category>
	{
	};

	template<bool value>
	struct BoolConstant : public std::integral_constant<bool, value>
	{
	};

#ifdef MOMO_USE_VARIADIC_TEMPLATES
	template<size_t... sequence>
	struct Sequence
	{
	};

	template<size_t count, size_t... sequence>
	struct MakeSequence : public MakeSequence<count - 1, count - 1, sequence...>
	{
	};

	template<size_t... sequence>
	struct MakeSequence<0, sequence...>
	{
		typedef Sequence<sequence...> Sequence;
	};
#endif

	template<typename TValue>
	struct Log2;

	template<>
	struct Log2<uint32_t>
	{
		typedef uint32_t Value;

		static size_t Calc(uint32_t value) MOMO_NOEXCEPT
		{
			static const size_t tab32[32] =
			{
				 0,  9,  1, 10, 13, 21,  2, 29,
				11, 14, 16, 18, 22, 25,  3, 30,
				 8, 12, 20, 28, 15, 17, 24,  7,
				19, 27, 23,  6, 26,  5,  4, 31,
			};
			value |= value >> 1;
			value |= value >> 2;
			value |= value >> 4;
			value |= value >> 8;<commit_msg>Refactoring<commit_after>/**********************************************************\

  momo/Utility.h

  namespace momo:
    enum class CheckMode
    enum class ExtraCheckMode
    struct IsTriviallyRelocatable

\**********************************************************/

#pragma once

#include "Settings.h"

#include <cstdint>
#include <cstddef>
#include <type_traits>
#include <cstring>
#include <memory>
#include <cassert>
#include <exception>
#include <algorithm>
#include <functional>
#include <stdexcept>

#ifdef MOMO_USE_INIT_LISTS
#include <initializer_list>
#endif

#ifdef MOMO_USE_MEM_MANAGER_WIN
#include <Windows.h>
#endif

#ifdef MOMO_USE_NOEXCEPT
#define MOMO_NOEXCEPT noexcept
#define MOMO_NOEXCEPT_IF(expr) noexcept(expr)
#else
#define MOMO_NOEXCEPT throw()
#define MOMO_NOEXCEPT_IF(expr)
#endif

#ifdef MOMO_USE_DELETE_FUNCS
#define MOMO_DISABLE_COPY_CONSTRUCTOR(Class) Class(const Class&) = delete;
#define MOMO_DISABLE_COPY_OPERATOR(Class) Class& operator=(const Class&) = delete;
#else
#define MOMO_DISABLE_COPY_CONSTRUCTOR(Class) Class(const Class&);
#define MOMO_DISABLE_COPY_OPERATOR(Class) Class& operator=(const Class&);
#endif

#if MOMO_USE_UNSAFE_MOVE_CONSTRUCTORS == 1
#define MOMO_IS_NOTHROW_MOVE_CONSTRUCTIBLE(Object) \
	std::is_nothrow_move_constructible<Object>::value \
	|| !std::is_copy_constructible<Object>::value
#elif MOMO_USE_UNSAFE_MOVE_CONSTRUCTORS == 2
#define MOMO_IS_NOTHROW_MOVE_CONSTRUCTIBLE(Object) true
#else
#define MOMO_IS_NOTHROW_MOVE_CONSTRUCTIBLE(Object) \
	std::is_nothrow_move_constructible<Object>::value
#endif

#define MOMO_FRIEND_SWAP(Container) \
	friend void swap(Container& cont1, Container& cont2) MOMO_NOEXCEPT \
	{ \
		cont1.Swap(cont2); \
	}

#define MOMO_FRIENDS_BEGIN_END(ContainerRef, Iterator) \
	friend Iterator begin(ContainerRef contRef) MOMO_NOEXCEPT \
	{ \
		return contRef.GetBegin(); \
	} \
	friend Iterator end(ContainerRef contRef) MOMO_NOEXCEPT \
	{ \
		return contRef.GetEnd(); \
	}

#define MOMO_STATIC_ASSERT(expr) static_assert((expr), #expr);

#define MOMO_CHECK_TYPE(Type, var) \
	MOMO_STATIC_ASSERT((std::is_same<Type, typename std::decay<decltype(var)>::type>::value));

#define MOMO_CHECK(expr) assert(Settings::checkMode != CheckMode::assertion || (expr)); \
	if (Settings::checkMode != CheckMode::exception || (expr)) ; else throw std::invalid_argument(#expr);

#define MOMO_EXTRA_CHECK(expr) assert(Settings::extraCheckMode != ExtraCheckMode::assertion || (expr));

namespace momo
{

enum class CheckMode
{
	assertion = 1,
	exception = 2,
};

enum class ExtraCheckMode
{
	nothing = 0,
	assertion = 1,
};

template<typename Object>
struct IsTriviallyRelocatable : public MOMO_IS_TRIVIALLY_COPYABLE<Object>
{
};

namespace internal
{
	template<typename Iterator>
	struct IsForwardIterator : public std::is_base_of<std::forward_iterator_tag,
		typename std::iterator_traits<Iterator>::iterator_category>
	{
	};

	template<bool value>
	struct BoolConstant : public std::integral_constant<bool, value>
	{
	};

#ifdef MOMO_USE_VARIADIC_TEMPLATES
	template<size_t... sequence>
	struct Sequence
	{
	};

	template<size_t count, size_t... sequence>
	struct MakeSequence : public MakeSequence<count - 1, count - 1, sequence...>
	{
	};

	template<size_t... sequence>
	struct MakeSequence<0, sequence...>
	{
		typedef internal::Sequence<sequence...> Sequence;
	};
#endif

	template<typename TValue>
	struct Log2;

	template<>
	struct Log2<uint32_t>
	{
		typedef uint32_t Value;

		static size_t Calc(uint32_t value) MOMO_NOEXCEPT
		{
			static const size_t tab32[32] =
			{
				 0,  9,  1, 10, 13, 21,  2, 29,
				11, 14, 16, 18, 22, 25,  3, 30,
				 8, 12, 20, 28, 15, 17, 24,  7,
				19, 27, 23,  6, 26,  5,  4, 31,
			};
			value |= value >> 1;
			value |= value >> 2;
			value |= value >> 4;
			value |= value >> 8;
{'fraction_non_alphanumeric': 0.15064524624703712, 'fraction_numerical': 0.021859362654727415, 'mean_word_length': 5.76313446126447, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1946589', 'n_tokens_mistral': 2974, 'n_tokens_neox': 2771, 'n_words': 571}