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

  This file is distributed under the MIT License.
  See https://github.com/morzhovets/momo/blob/master/LICENSE
  for details.

  momo/MapUtility.h

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

#pragma once

#include "ObjectManager.h"
#include "IteratorUtility.h"

namespace momo
{

namespace internal
{
	template<typename TSetReference,
		bool tIsConst = false>
	class MapReference
	{
	protected:
		typedef TSetReference SetReference;
		typedef typename std::decay<SetReference>::type KeyValuePair;

		static const bool isConst = tIsConst;

	public:
		typedef typename KeyValuePair::Key Key;
		typedef typename std::conditional<isConst, const typename KeyValuePair::Value,
			typename KeyValuePair::Value>::type Value;

		typedef MapReference<SetReference, true> ConstReference;

	public:
		explicit MapReference(const Key& key, Value& value) noexcept
			: key(key),
			value(value)
		{
		}

		operator ConstReference() const noexcept
		{
			return ConstReference(key, value);
		}

	protected:
		explicit MapReference(SetReference setRef) noexcept
			: key(*setRef.GetKeyPtr()),
			value(*setRef.GetValuePtr())
		{
		}

	public:
		const Key& key;
		Value& value;
	};

	template<typename TMapReference>
	class MapReferenceStd
		: public std::pair<const typename TMapReference::Key&, typename TMapReference::Value&>
	{
	protected:
		typedef TMapReference MapReference;

	public:
		typedef typename MapReference::Key Key;
		typedef typename MapReference::Value Value;

		typedef MapReferenceStd<typename MapReference::ConstReference> ConstReference;

	private:
		typedef std::pair<const Key&, Value&> RefPair;

	public:
		explicit MapReferenceStd(const Key& key, Value& value) noexcept
			: RefPair(key, value)
		{
		}

		operator ConstReference() noexcept
		{
			return ConstReference(RefPair::first, RefPair::second);
		}

		bool operator==(const MapReferenceStd& ref) const
		{
			return RefPair::first == ref.first && RefPair::second == ref.second;
		}

		bool operator!=(const MapReferenceStd& ref) const
		{
			return !(*this == ref);
		}

		bool operator==(const std::pair<const Key, Value>& pair) const
		{
			return RefPair::first == pair.first && RefPair::second == pair.second;
		}

		bool operator!=(const std::pair<const Key, Value>& pair) const
		{
			return !(*this == pair);
		}

		friend bool operator==(const std::pair<const Key, Value>& pair, const MapReferenceStd& ref)
		{
			return ref == pair;
		}

		friend bool operator!=(const std::pair<const Key, Value>& pair, const MapReferenceStd& ref)
		{
			return !(ref == pair);
		}

		//? <, >, <=, >=

	protected:
		explicit MapReferenceStd(MapReference mapRef) noexcept
			: RefPair(mapRef.key, mapRef.value)
		{
		}
	};

	template<typename TSetIterator>
	class MapKeyIterator
	{
	public:
		typedef TSetIterator SetIterator;

	private:
		typedef typename std::iterator_traits<SetIterator>::reference SetReference;
		typedef typename std::decay<SetReference>::type KeyValuePair;

	public:
		typedef typename KeyValuePair::Key Key;

		typedef Key& Reference;
		typedef Key* Pointer;

	public:
		explicit MapKeyIterator(SetIterator setIterator) noexcept
			: mSetIterator(setIterator)
		{
		}

		MapKeyIterator& operator++() noexcept
		{
			++mSetIterator;
			return *this;
		}

		Pointer operator->() const noexcept
		{
			return mSetIterator->GetKeyPtr();
		}

		Reference operator*() const noexcept
		{
			return *operator->();
		}

	private:
		SetIterator mSetIterator;
	};

	template<typename TSetIterator>
	class MapValueIterator
	{
	public:
		typedef TSetIterator SetIterator;

	private:
		typedef typename std::iterator_traits<SetIterator>::reference SetReference;
		typedef typename std::decay<SetReference>::type KeyValuePair;

	public:
		typedef typename KeyValuePair::Value Value;

		typedef Value& Reference;
		typedef Value* Pointer;

	public:
		explicit MapValueIterator(SetIterator setIterator) noexcept
			: mSetIterator(setIterator)
		{
		}

		MapValueIterator& operator++() noexcept
		{
			++mSetIterator;
			return *this;
		}

		Pointer operator->() const noexcept
		{
			return mSetIterator->GetValuePtr();
		}
<commit_msg>MapKeyIterator, MapValueIterator<commit_after>/**********************************************************\

  This file is distributed under the MIT License.
  See https://github.com/morzhovets/momo/blob/master/LICENSE
  for details.

  momo/MapUtility.h

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

#pragma once

#include "ObjectManager.h"
#include "IteratorUtility.h"

namespace momo
{

namespace internal
{
	template<typename TSetReference,
		bool tIsConst = false>
	class MapReference
	{
	protected:
		typedef TSetReference SetReference;
		typedef typename std::decay<SetReference>::type KeyValuePair;

		static const bool isConst = tIsConst;

	public:
		typedef typename KeyValuePair::Key Key;
		typedef typename std::conditional<isConst, const typename KeyValuePair::Value,
			typename KeyValuePair::Value>::type Value;

		typedef MapReference<SetReference, true> ConstReference;

	public:
		explicit MapReference(const Key& key, Value& value) noexcept
			: key(key),
			value(value)
		{
		}

		operator ConstReference() const noexcept
		{
			return ConstReference(key, value);
		}

	protected:
		explicit MapReference(SetReference setRef) noexcept
			: key(*setRef.GetKeyPtr()),
			value(*setRef.GetValuePtr())
		{
		}

	public:
		const Key& key;
		Value& value;
	};

	template<typename TMapReference>
	class MapReferenceStd
		: public std::pair<const typename TMapReference::Key&, typename TMapReference::Value&>
	{
	protected:
		typedef TMapReference MapReference;

	public:
		typedef typename MapReference::Key Key;
		typedef typename MapReference::Value Value;

		typedef MapReferenceStd<typename MapReference::ConstReference> ConstReference;

	private:
		typedef std::pair<const Key&, Value&> RefPair;

	public:
		explicit MapReferenceStd(const Key& key, Value& value) noexcept
			: RefPair(key, value)
		{
		}

		operator ConstReference() noexcept
		{
			return ConstReference(RefPair::first, RefPair::second);
		}

		bool operator==(const MapReferenceStd& ref) const
		{
			return RefPair::first == ref.first && RefPair::second == ref.second;
		}

		bool operator!=(const MapReferenceStd& ref) const
		{
			return !(*this == ref);
		}

		bool operator==(const std::pair<const Key, Value>& pair) const
		{
			return RefPair::first == pair.first && RefPair::second == pair.second;
		}

		bool operator!=(const std::pair<const Key, Value>& pair) const
		{
			return !(*this == pair);
		}

		friend bool operator==(const std::pair<const Key, Value>& pair, const MapReferenceStd& ref)
		{
			return ref == pair;
		}

		friend bool operator!=(const std::pair<const Key, Value>& pair, const MapReferenceStd& ref)
		{
			return !(ref == pair);
		}

		//? <, >, <=, >=

	protected:
		explicit MapReferenceStd(MapReference mapRef) noexcept
			: RefPair(mapRef.key, mapRef.value)
		{
		}
	};

	template<typename TSetIterator>
	class MapKeyIterator
	{
	public:
		typedef TSetIterator SetIterator;

		typedef decltype(std::declval<SetIterator>()->GetKeyPtr()) Pointer;
		typedef decltype(*Pointer()) Reference;

	public:
		explicit MapKeyIterator(SetIterator setIterator) noexcept
			: mSetIterator(setIterator)
		{
		}

		MapKeyIterator& operator++() noexcept
		{
			++mSetIterator;
			return *this;
		}

		Pointer operator->() const noexcept
		{
			return mSetIterator->GetKeyPtr();
		}

		Reference operator*() const noexcept
		{
			return *operator->();
		}

	private:
		SetIterator mSetIterator;
	};

	template<typename TSetIterator>
	class MapValueIterator
	{
	public:
		typedef TSetIterator SetIterator;

		typedef decltype(std::declval<SetIterator>()->GetValuePtr()) Pointer;
		typedef decltype(*Pointer()) Reference;

	public:
		explicit MapValueIterator(SetIterator setIterator) noexcept
			: mSetIterator(setIterator)
		{
		}

		MapValueIterator& operator++() noexcept
		{
			++mSetIterator;
			return *this;
		}

		Pointer operator->() const noexcept
		{
			return mSetIterator->GetValuePtr();
		}

{'fraction_non_alphanumeric': 0.13860533759685156, 'fraction_numerical': 0.0, 'mean_word_length': 4.585164835164835, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 53, 'https://': 2, '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': '5663497', 'n_tokens_mistral': 2881, 'n_tokens_neox': 2440, 'n_words': 603}