<commit_before>#include <math.h>
#include <assert.h>
#include <glib.h>
#include "boid.h"
#include "simulation.h"

static void separation(boid *boids, int this, GList *others) {
	GList *current = g_list_first(others);
	float x = 0, y = 0;
	int count = 0;
	const int weight = 50;
	do {
		int index = GPOINTER_TO_INT(current->data);
		float distance = boid_real_distance(this, index) + 0.01f;
		assert(distance > 0);
		x += (boids[this].x - boids[index].x) / distance;
		y += (boids[this].y - boids[index].y) / distance;
		++count;
	} while (current = g_list_next(current));
	boids[this].fx = x / count / weight;
	boids[this].fy = y / count / weight;
}

static void alignment(boid *boids, boid *this, GList *others) {
	GList *current = g_list_first(others);
	float vx = 0, vy = 0;
	int count = 0;
	const int weight = 10;
	do {
		int index = GPOINTER_TO_INT(current->data);
		vx += boids[index].vx;
		vy += boids[index].vy;
		++count;
	} while (current = g_list_next(current));<commit_msg>Small optimisations in separation function<commit_after>#include <math.h>
#include <assert.h>
#include <glib.h>
#include "boid.h"
#include "simulation.h"

static void separation(boid *boids, int this, GList *others) {
	float x = 0, y = 0;
	int count = 0, divisor;
	const int weight = 50;
	do {
		int index = GPOINTER_TO_INT(others->data);
		float distance = boid_real_distance(this, index) + 0.01f;
		assert(distance > 0);
		x += (boids[this].x - boids[index].x) / distance;
		y += (boids[this].y - boids[index].y) / distance;
		++count;
	} while (others = g_list_next(others));
	divisor = count * weight;
	boids[this].fx = x / divisor;
	boids[this].fy = y / divisor;
}

static void alignment(boid *boids, boid *this, GList *others) {
	GList *current = g_list_first(others);
	float vx = 0, vy = 0;
	int count = 0;
	const int weight = 10;
	do {
		int index = GPOINTER_TO_INT(current->data);
		vx += boids[index].vx;
		vy += boids[index].vy;
		++count;
	} while (current = g_list_next(current));
{'fraction_non_alphanumeric': 0.16228513650151669, 'fraction_numerical': 0.014155712841253791, 'mean_word_length': 4.035623409669212, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '715984', 'n_tokens_mistral': 827, 'n_tokens_neox': 771, 'n_words': 200}