<commit_before>/*
 * Copyright 2010-2011 DIMA Research Group, TU Berlin
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * @author: <NAME> <<EMAIL>>
 */

#ifndef RANDOMSEED_H_
#define RANDOMSEED_H_

#include <Poco/Exception.h>
#include <cstdlib>
#include <string>
#include <sstream>

using namespace std;
using namespace Poco;

// forward declarations;
template<class T> T readComponent(const string& s);
template<> int readComponent(const string& s);
template<> unsigned int readComponent(const string& s);
template<> unsigned long int readComponent(const string& s);

namespace Myriad {

/**
 * A random seed template. Basically, a random seed is a wrapper around a
 * fixed length vector of some integer type. The number of integers and the
 * length of the vector are RNG implemtation dependant.
 */
template<class T, unsigned int x> class RandomSeed
{
public:

	RandomSeed()
	{
		for (unsigned int i = 0; i < x; i++)
		{
			v[i] = 0;
		}
	}

	RandomSeed(T s[])
	{
		for (unsigned int i = 0; i < x; i++)
		{
			v[i] = s[i];
		}
	}

	RandomSeed(string seed)
	{
		seed.append(",");

		for (unsigned int i = 0; i < x; i++)
		{
			v[i] = 0;
		}

		unsigned int i = 0;
		size_t l = 0, r;
		while (i < x && string::npos != (r = seed.find(',', l)))
		{
			v[i] = readComponent<T> (seed.substr(l, r - l));

			l = r + 1;
			i++;
		}

		if (i < x)
		{
			throw RuntimeException("Not enough random seed components found");
		}
	}

	RandomSeed(const RandomSeed<T, x>& other)
	{
		for (unsigned int i = 0; i < x; i++)
		{
			v[i] = 0;
			v[i] = other.v[i];
		}
	}

	RandomSeed<T, x>& operator =(const RandomSeed<T, x>& other)
	{
		if (this != &other) // protect against invalid self-assignment
		{
			for (unsigned int i = 0; i < x; i++)
			{
				v[i] = other.v[i];
			}
		}

		return *this;
	}

	bool operator ==(const RandomSeed<T, x>& other) const
	{
		for (unsigned int i = 0; i < x; i++)
		{
			if (v[i] != other.v[i])
			{
				return false;
			}
		}

		return true;
	}

	void reset()
	{
		for (unsigned int i = 0; i < x; i++)
		{
			v[i] = 0;
		}
	}

	const std::string toString() const
	{
		std::stringstream ss;

		for (unsigned int i = 0; i < x-1; i++)
		{
			ss << v[i] << ",";
		}
		ss << v[x-1];

		return ss.str();
	}

	T v[x];

private:

};

} // namespace Myriad

template<class T> inline T readComponent(const string& s)
{
	throw RuntimeException("Read component not supported");
}

template<> inline int readComponent(const string& s)
{
	return atoi(s.c_str());
}

template<> inline unsigned int readComponent(const string& s)
{
	return strtoul(s.c_str(), 0, 0);
}

template<> inline unsigned long int readComponent(const string& s)
{
	return strtoul(s.c_str(), 0, 0);
}

#endif /* RANDOMSEED_H_ */<commit_msg>Fixed bad template function specialization syntax in RandomSeed.h.<commit_after>/*
 * Copyright 2010-2011 DIMA Research Group, TU Berlin
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * @author: <NAME> <<EMAIL>>
 */

#ifndef RANDOMSEED_H_
#define RANDOMSEED_H_

#include <Poco/Exception.h>
#include <cstdlib>
#include <string>
#include <sstream>

using namespace std;
using namespace Poco;

namespace Myriad {

// forward declarations;
template<class T> T readComponent(const string& s);
template<> int readComponent<int>(const string& s);
template<> unsigned int readComponent<unsigned int>(const string& s);
template<> unsigned long int readComponent<unsigned long int>(const string& s);

/**
 * A random seed template. Basically, a random seed is a wrapper around a
 * fixed length vector of some integer type. The number of integers and the
 * length of the vector are RNG implemtation dependant.
 */
template<class T, unsigned int x> class RandomSeed
{
public:

	RandomSeed()
	{
		for (unsigned int i = 0; i < x; i++)
		{
			v[i] = 0;
		}
	}

	RandomSeed(T s[])
	{
		for (unsigned int i = 0; i < x; i++)
		{
			v[i] = s[i];
		}
	}

	RandomSeed(string seed)
	{
		seed.append(",");

		for (unsigned int i = 0; i < x; i++)
		{
			v[i] = 0;
		}

		unsigned int i = 0;
		size_t l = 0, r;
		while (i < x && string::npos != (r = seed.find(',', l)))
		{
			v[i] = readComponent<T> (seed.substr(l, r - l));

			l = r + 1;
			i++;
		}

		if (i < x)
		{
			throw RuntimeException("Not enough random seed components found");
		}
	}

	RandomSeed(const RandomSeed<T, x>& other)
	{
		for (unsigned int i = 0; i < x; i++)
		{
			v[i] = 0;
			v[i] = other.v[i];
		}
	}

	RandomSeed<T, x>& operator =(const RandomSeed<T, x>& other)
	{
		if (this != &other) // protect against invalid self-assignment
		{
			for (unsigned int i = 0; i < x; i++)
			{
				v[i] = other.v[i];
			}
		}

		return *this;
	}

	bool operator ==(const RandomSeed<T, x>& other) const
	{
		for (unsigned int i = 0; i < x; i++)
		{
			if (v[i] != other.v[i])
			{
				return false;
			}
		}

		return true;
	}

	void reset()
	{
		for (unsigned int i = 0; i < x; i++)
		{
			v[i] = 0;
		}
	}

	const std::string toString() const
	{
		std::stringstream ss;

		for (unsigned int i = 0; i < x-1; i++)
		{
			ss << v[i] << ",";
		}
		ss << v[x-1];

		return ss.str();
	}

	T v[x];

private:

};

template<class T> inline T readComponent(const string& s)
{
	throw RuntimeException("Read component not supported");
}

template<> inline int readComponent<int>(const string& s)
{
	return atoi(s.c_str());
}

template<> inline unsigned int readComponent<unsigned int>(const string& s)
{
	return strtoul(s.c_str(), 0, 0);
}

template<> inline unsigned long int readComponent<unsigned long int>(const string& s)
{
	return strtoul(s.c_str(), 0, 0);
}

} // namespace Myriad

#endif /* RANDOMSEED_H_ */
{'fraction_non_alphanumeric': 0.1445235570368126, 'fraction_numerical': 0.009998485078018482, 'mean_word_length': 3.205095541401274, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3607062', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2347, 'n_words': 799}