<commit_before>/**
 * precise_time.h
 * @author wherewindblow
 * @date   Oct 12, 2018
 */

#pragma once

#include <cstdint>
#include <cmath>

#include "format.h"


namespace lights {

/**
 * PreciseTime use to record hight resolution time point.
 */
struct PreciseTime
{
	static const int NANOSECONDS_OF_SECOND = 1000000000;

	PreciseTime() :
		PreciseTime(0, 0)
	{}

	PreciseTime(std::int64_t seconds):
		PreciseTime(seconds, 0)
	{}

	PreciseTime(std::int64_t seconds, std::int64_t nanoseconds):
		seconds(seconds), nanoseconds(nanoseconds)
	{}

	std::int64_t seconds;
	std::int64_t nanoseconds;
};


inline bool is_over_flow(std::int64_t a, std::int64_t b)
{
	std::int64_t x = a + b;
	return ((x^a) < 0 && (x^b) < 0);
}


inline PreciseTime operator+(const PreciseTime& left, const PreciseTime& right)
{
	PreciseTime result(left.seconds + right.seconds, left.nanoseconds + right.nanoseconds);
	if (result.nanoseconds >= PreciseTime::NANOSECONDS_OF_SECOND)
	{
		result.nanoseconds -= PreciseTime::NANOSECONDS_OF_SECOND;
		++result.seconds;
	}
	return result;
}


inline PreciseTime operator-(const PreciseTime& left, const PreciseTime& right)
{
	PreciseTime result(left.seconds - right.seconds, left.nanoseconds - right.nanoseconds);
	if (left.nanoseconds < right.nanoseconds)
	{
		--result.seconds;
		result.nanoseconds = std::abs(result.nanoseconds);
	}
	return result;
}


inline bool operator<(const PreciseTime& left, const PreciseTime& right)
{
	if (left.seconds != right.seconds)
	{
		return left.seconds < right.seconds;
	}
	return left.nanoseconds < right.nanoseconds;
}


inline bool operator>(const PreciseTime& left, const PreciseTime& right)
{
	if (left.seconds != right.seconds)
	{
		return left.seconds > right.seconds;
	}
	return left.nanoseconds > right.nanoseconds;
}
<commit_msg>feat: support multiply and divide of PreciseTime<commit_after>/**
 * precise_time.h
 * @author wherewindblow
 * @date   Oct 12, 2018
 */

#pragma once

#include <cstdint>
#include <cmath>

#include "format.h"


namespace lights {

/**
 * PreciseTime use to record hight resolution time point.
 */
struct PreciseTime
{
	static const int NANOSECONDS_OF_SECOND = 1000000000;

	PreciseTime() :
		PreciseTime(0, 0)
	{}

	PreciseTime(std::int64_t seconds):
		PreciseTime(seconds, 0)
	{}

	PreciseTime(std::int64_t seconds, std::int64_t nanoseconds):
		seconds(seconds), nanoseconds(nanoseconds)
	{}

	std::int64_t seconds;
	std::int64_t nanoseconds;
};


inline bool is_over_flow(std::int64_t a, std::int64_t b)
{
	std::int64_t x = a + b;
	return ((x^a) < 0 && (x^b) < 0);
}


inline PreciseTime operator+(const PreciseTime& left, const PreciseTime& right)
{
	PreciseTime result(left.seconds + right.seconds, left.nanoseconds + right.nanoseconds);
	if (result.nanoseconds >= PreciseTime::NANOSECONDS_OF_SECOND)
	{
		result.nanoseconds -= PreciseTime::NANOSECONDS_OF_SECOND;
		++result.seconds;
	}
	return result;
}


inline PreciseTime operator-(const PreciseTime& left, const PreciseTime& right)
{
	PreciseTime result(left.seconds - right.seconds, left.nanoseconds - right.nanoseconds);
	if (left.nanoseconds < right.nanoseconds)
	{
		--result.seconds;
		result.nanoseconds = std::abs(result.nanoseconds);
	}
	return result;
}


inline PreciseTime operator*(const PreciseTime& time, int n)
{
	PreciseTime result(time.seconds * n, time.nanoseconds * n);
	if (result.nanoseconds >= PreciseTime::NANOSECONDS_OF_SECOND)
	{
		result.seconds += result.nanoseconds / PreciseTime::NANOSECONDS_OF_SECOND;
		result.nanoseconds %= PreciseTime::NANOSECONDS_OF_SECOND;
	}
	return result;
}


inline PreciseTime operator/(const PreciseTime& time, int n)
{
	PreciseTime result(time.seconds / n, time.nanoseconds / n);
	double sec = time.seconds / static_cast<double>(n);
	double nansecond = (sec - result.seconds) * PreciseTime::NANOSECONDS_OF_SECOND;
	result.nanoseconds += static_cast<std::int64_t>(nansecond);
	return result;
}


inline bool operator<(const PreciseTime& left, const PreciseTime& right)
{
	if (left.seconds != right.seconds)
	{
		return left.seconds < right.seconds;
	}
	return left.nanoseconds < right.nanoseconds;
}


inline bool operator>(const PreciseTime& left, const PreciseTime& right)
{
	if (left.seconds != right.seconds)
	{
		return left.seconds > right.seconds;
	}
	return left.nanoseconds > right.nanoseconds;
}

{'fraction_non_alphanumeric': 0.12517353077279036, 'fraction_numerical': 0.017584451642757983, 'mean_word_length': 4.946354883081155, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4188018', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1567, 'n_words': 335}