<commit_before>#include <sys/types.h>

#include "flowstat.h"

void 
stat_container_init (stat_container_t * q)
{
	q->next = 0;
	q->full = 0;
}

flowstat_t *
stat_container_next (stat_container_t * q)
{
	if (q->full < STAT_COUNT) {
		++(q->full);
	}
	
	if (q->next == STAT_COUNT) {
		q->next = 1;
		return &(q->items[0]);
	}
	
	return &(q->items[q->next++]);
}

stat_number_t
stat_container_reduce (stat_container_t * q, key_fnc_t key, reduce_fnc_t fnc)
{
	size_t i = 0;
	stat_number_t result = key(&(q->items[0]));
	
	for (i = 1; i < q->full; ++i) {
		result = fnc(result, key(&(q->items[i])));
	}
	
	return result;
}

void
stat_container_interval (stat_container_t *s, struct timespec *res)
{
	if (s->full == 0) {
		res->tv_sec = 0;
		res->tv_nsec = 0;
		return;
	}
	
	size_t low = s->full < STAT_COUNT ? 0 : s->next;
	size_t high = s->next == 0 ? STAT_COUNT - 1 : s->next - 1;
	
	if ((s->items[high].time.tv_nsec - s->items[low].time.tv_nsec) < 0) {
		res->tv_sec = s->items[high].time.tv_sec - s->items[low].time.tv_sec-1;
		res->tv_nsec = 1000000000 + s->items[high].time.tv_nsec - s->items[low].time.tv_nsec;
	} else {
		res->tv_sec = s->items[high].time.tv_sec - s->items[low].time.tv_sec;
		res->tv_nsec = s->items[high].time.tv_nsec - s->items[low].time.tv_nsec;
	}
}<commit_msg>stat_container_reduce returns 0 if empty<commit_after>#include <sys/types.h>

#include "flowstat.h"

void 
stat_container_init (stat_container_t * q)
{
	q->next = 0;
	q->full = 0;
}

flowstat_t *
stat_container_next (stat_container_t * q)
{
	if (q->full < STAT_COUNT) {
		++(q->full);
	}
	
	if (q->next == STAT_COUNT) {
		q->next = 1;
		return &(q->items[0]);
	}
	
	return &(q->items[q->next++]);
}

stat_number_t
stat_container_reduce (stat_container_t * q, key_fnc_t key, reduce_fnc_t fnc)
{
	if (q->full == 0) {
		return 0;
	}
	
	size_t i = 0;
	stat_number_t result = key(&(q->items[0]));
	
	for (i = 1; i < q->full; ++i) {
		result = fnc(result, key(&(q->items[i])));
	}
	
	return result;
}

void
stat_container_interval (stat_container_t *s, struct timespec *res)
{
	if (s->full == 0) {
		res->tv_sec = 0;
		res->tv_nsec = 0;
		return;
	}
	
	size_t low = s->full < STAT_COUNT ? 0 : s->next;
	size_t high = s->next == 0 ? STAT_COUNT - 1 : s->next - 1;
	
	if ((s->items[high].time.tv_nsec - s->items[low].time.tv_nsec) < 0) {
		res->tv_sec = s->items[high].time.tv_sec - s->items[low].time.tv_sec-1;
		res->tv_nsec = 1000000000 + s->items[high].time.tv_nsec - s->items[low].time.tv_nsec;
	} else {
		res->tv_sec = s->items[high].time.tv_sec - s->items[low].time.tv_sec;
		res->tv_nsec = s->items[high].time.tv_nsec - s->items[low].time.tv_nsec;
	}
}
{'fraction_non_alphanumeric': 0.20121258052292534, 'fraction_numerical': 0.020841227737779463, 'mean_word_length': 3.536082474226804, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 72, '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': '1493975', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1174, 'n_words': 211}