<commit_before>#ifndef _MMH_SORT_H_
#define _MMH_SORT_H_

#ifndef uT
#define uT(x) (pfc::stringcvt::string_os_from_utf8(x).get_ptr())
#define uTS(x,s) (pfc::stringcvt::string_os_from_utf8(x,s).get_ptr())
#endif


namespace mmh
{
	typedef pfc::list_t<t_size> permutation_base_t;

	//template <template<typename> class t_alloc = pfc::alloc_fast>
	class permutation_t : public permutation_base_t
	{
	public:
		void reset()
		{
			t_size j, count=get_size();
			t_size * ptr = get_ptr();
			for (j=0; j<count; j++)
				ptr[j] = j;
		}
		void reset_reverse()
		{
			t_size j, count=get_size();
			t_size * ptr = get_ptr();
			for (j=0; j<count; j++)
				ptr[j] = count-j-1;
		}
		void set_size (t_size size)
		{
			pfc::list_t<t_size>::set_size(size);
			reset();
		}
		void set_count (t_size size)
		{
			set_size(size);
		};
		permutation_t(t_size size)
		{
			set_size(size);
			reset();
		};
		permutation_t() {};

		using pfc::list_t<t_size>::operator[];
	};

	class permutation_inverse_t : public permutation_t
	{
	public:
		permutation_inverse_t(const permutation_t & p_source)
		{
			t_size i, count = p_source.get_count();
			permutation_base_t::set_size (count);
			for(i=0;i<count;i++)
				(*this)[p_source[i]] = i;
		}
	};

	class permutation_reverse_t : public permutation_t
	{
	public:
		permutation_reverse_t(const permutation_t & p_source)
		{
			t_size i, count = p_source.get_count();
			permutation_base_t::set_size (count);
			for(i=0;i<count;i++)
				(*this)[i] = p_source[count-i-1];
		}
	};

	class sort_base
	{
	public:
		virtual int compare (const void * item1, const void* item2)=0;
	};

	template <typename t_list, typename t_compare>
	class sort_base_impl : public sort_base
	{
		t_compare m_compare;
		permutation_t & m_perm;
		t_list & m_list;
		bool m_stabilise;
	public:
		int compare (const void * item1, const void* item2) override
		{
			int ret = m_compare(m_list[*(t_size*)(item1)], m_list[*(t_size*)(item2)]);
			if (!ret && m_stabilise) ret = pfc::compare_t(*(t_size*)(item1), *(t_size*)(item2));
			return ret;
		}
		sort_base_impl(t_list & p_list, permutation_t & p_perm, t_compare p_compare, bool p_stabilise)
			: m_compare(p_compare), m_perm(p_perm), m_list(p_list), m_stabilise(p_stabilise)
		{
		};
	};

	__forceinline int g_compare_context(void* context, const void * item1, const void* item2);

	template <typename context_t>
	__forceinline int g_compare_context_v2(context_t & context, const void * item1, const void* item2)
	{
		return context.compare(item1, item2);
	}

	template <typename context_t>
	__forceinline int g_compare_context_v3(context_t & context, const t_size * item1, const t_size* item2)
	{<commit_msg>Correct g_compare_context() declaration<commit_after>#ifndef _MMH_SORT_H_
#define _MMH_SORT_H_

#ifndef uT
#define uT(x) (pfc::stringcvt::string_os_from_utf8(x).get_ptr())
#define uTS(x,s) (pfc::stringcvt::string_os_from_utf8(x,s).get_ptr())
#endif

namespace mmh
{
	typedef pfc::list_t<t_size> permutation_base_t;

	//template <template<typename> class t_alloc = pfc::alloc_fast>
	class permutation_t : public permutation_base_t
	{
	public:
		void reset()
		{
			t_size j, count=get_size();
			t_size * ptr = get_ptr();
			for (j=0; j<count; j++)
				ptr[j] = j;
		}
		void reset_reverse()
		{
			t_size j, count=get_size();
			t_size * ptr = get_ptr();
			for (j=0; j<count; j++)
				ptr[j] = count-j-1;
		}
		void set_size (t_size size)
		{
			pfc::list_t<t_size>::set_size(size);
			reset();
		}
		void set_count (t_size size)
		{
			set_size(size);
		};
		permutation_t(t_size size)
		{
			set_size(size);
			reset();
		};
		permutation_t() {};

		using pfc::list_t<t_size>::operator[];
	};

	class permutation_inverse_t : public permutation_t
	{
	public:
		permutation_inverse_t(const permutation_t & p_source)
		{
			t_size i, count = p_source.get_count();
			permutation_base_t::set_size (count);
			for(i=0;i<count;i++)
				(*this)[p_source[i]] = i;
		}
	};

	class permutation_reverse_t : public permutation_t
	{
	public:
		permutation_reverse_t(const permutation_t & p_source)
		{
			t_size i, count = p_source.get_count();
			permutation_base_t::set_size (count);
			for(i=0;i<count;i++)
				(*this)[i] = p_source[count-i-1];
		}
	};

	class sort_base
	{
	public:
		virtual int compare (const void * item1, const void* item2)=0;
	};

	template <typename t_list, typename t_compare>
	class sort_base_impl : public sort_base
	{
		t_compare m_compare;
		permutation_t & m_perm;
		t_list & m_list;
		bool m_stabilise;
	public:
		int compare (const void * item1, const void* item2) override
		{
			int ret = m_compare(m_list[*(t_size*)(item1)], m_list[*(t_size*)(item2)]);
			if (!ret && m_stabilise) ret = pfc::compare_t(*(t_size*)(item1), *(t_size*)(item2));
			return ret;
		}
		sort_base_impl(t_list & p_list, permutation_t & p_perm, t_compare p_compare, bool p_stabilise)
			: m_compare(p_compare), m_perm(p_perm), m_list(p_list), m_stabilise(p_stabilise)
		{
		};
	};

	int g_compare_context(void* context, const void * item1, const void* item2);

	template <typename context_t>
	__forceinline int g_compare_context_v2(context_t & context, const void * item1, const void* item2)
	{
		return context.compare(item1, item2);
	}

	template <typename context_t>
	__forceinline int g_compare_context_v3(context_t & context, const t_size * item1, const t_size* item2)
	{
{'fraction_non_alphanumeric': 0.13967421831117768, 'fraction_numerical': 0.010110466204830556, 'mean_word_length': 4.593717277486911, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '990389', 'n_tokens_mistral': 2423, 'n_tokens_neox': 2174, 'n_words': 421}