<commit_before>/*
 * GameKeeper Framework
 *
 * Copyright (C) 2013 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef GAMEKEEPER_UTILS_CONTAINERUTILS_H
#define GAMEKEEPER_UTILS_CONTAINERUTILS_H 1

#include <gamekeeper/core/common.h>

#include <vector>

GAMEKEEPER_NAMESPACE_START(utils)

namespace Containers
{
	/**
	 * returns a list of keys not found in @a container
	 *
	 * @author <NAME>
	 * @since 0
	 *
	 * @param[in] container the container to be searched through
	 * @param[in] keys a list of keys to be searched
	 */
	template <class Container>
	std::vector<typename Container::key_type> checkMissing(const Container & container, const std::vector<typename Container::key_type> & keys);

	/**
	 * returns a list of keys not found in @a container
	 *
	 * @author <NAME>
	 * @since 0
	 *
	 * @param[in] container the container to be searched through
	 * @param[in] keys a list of keys to be searched
	 * @param[in] endIt the end iterator to use if container.end() is not usable
	 */
	template <class Container, class Iterator>
	std::vector<typename Container::key_type> checkMissing(const Container & container, const std::vector<typename Container::key_type> & keys, const Iterator & endIt);
}

template <class Container>
std::vector<typename Container::key_type>
Containers::checkMissing(const Container & container, const std::vector<typename Container::key_type> & keys)
{
	return checkMissing(container, keys, container.end());
}

template <class Container, class Iterator>
std::vector<typename Container::key_type>
Containers::checkMissing(const Container & container, const std::vector<typename Container::key_type> & keys, const Iterator & endIt)
{
	std::vector<typename Container::key_type> missing;
	for(const typename Container::key_type & key : keys)
	{
		if(container.find(key) == endIt)
		{
			missing.push_back(key);
		}
	}
	return missing;
}

GAMEKEEPER_NAMESPACE_END(utils)
<commit_msg>utils/containerutils: use copy_if in checkMissing<commit_after>/*
 * GameKeeper Framework
 *
 * Copyright (C) 2013 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef GAMEKEEPER_UTILS_CONTAINERUTILS_H
#define GAMEKEEPER_UTILS_CONTAINERUTILS_H 1

#include <gamekeeper/core/common.h>

#include <algorithm>
#include <iterator>
#include <vector>

GAMEKEEPER_NAMESPACE_START(utils)

namespace Containers
{
	/**
	 * returns a list of keys not found in @a container
	 *
	 * @author <NAME>
	 * @since 0
	 *
	 * @param[in] container the container to be searched through
	 * @param[in] keys a list of keys to be searched
	 */
	template <class Container>
	std::vector<typename Container::key_type> checkMissing(const Container & container, const std::vector<typename Container::key_type> & keys);

	/**
	 * returns a list of keys not found in @a container
	 *
	 * @author <NAME>
	 * @since 0
	 *
	 * @param[in] container the container to be searched through
	 * @param[in] keys a list of keys to be searched
	 * @param[in] endIt the end iterator to use if container.end() is not usable
	 */
	template <class Container, class Iterator>
	std::vector<typename Container::key_type> checkMissing(const Container & container, const std::vector<typename Container::key_type> & keys, const Iterator & endIt);
}

template <class Container>
std::vector<typename Container::key_type>
Containers::checkMissing(const Container & container, const std::vector<typename Container::key_type> & keys)
{
	return checkMissing(container, keys, container.end());
}

template <class Container, class Iterator>
std::vector<typename Container::key_type>
Containers::checkMissing(const Container & container, const std::vector<typename Container::key_type> & keys, const Iterator & endIt)
{
	std::vector<typename Container::key_type> missing;
	std::copy_if(keys.begin(), keys.end(), std::inserter(missing, missing.begin()), [&](const typename Container::key_type & key)
	{
		return container.find(key) == endIt;
	});
	return missing;
}

GAMEKEEPER_NAMESPACE_END(utils)

{'fraction_non_alphanumeric': 0.09819936885093744, 'fraction_numerical': 0.007425283088917765, 'mean_word_length': 4.940463065049614, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '964303', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1537, 'n_words': 583}