<commit_before>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   deserialize_workunit.c                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: ssmith <<EMAIL>>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2017/05/17 17:22:04 by ssmith            #+#    #+#             */
/*   Updated: 2017/05/17 17:22:54 by ssmith           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "dispatcher.h"

int			btoi(char *str)
{
	int		ret;

	for (unsigned int i = 0; i < sizeof(int); i++)
		((char *)(&ret))[i] = str[i];
	return (ret);
}

float		btof(char *str)
{
	float	ret;

	for (unsigned int i = 0; i < sizeof(float); i++)
		((char *)(&ret))[i] = str[i];
	return (ret);
}

cl_float4	btoclf(char *str)
{
	cl_float4	ret;

	for (unsigned int i = 0; i < sizeof(cl_float4); i++)
		((char *)(&ret))[i] = str[i];
	return (ret);
}

t_workunit	*deserialize_workunit(t_msg msg)
{
	int			i;
	t_workunit	*workunit;

	i = 0;
	workunit = malloc(sizeof(t_workunit));
	workunit->id = btoi(msg.data);
	workunit->localcount = btoi(msg.data += 4);
	workunit->local_bodies = (t_body *)malloc(sizeof(t_body) * workunit->localcount);
	for (int i = 0; i < workunit->localcount; i++)
	{
		workunit->local_bodies[i].position.x = btof(msg.data += 4);
		workunit->local_bodies[i].position.y = btof(msg.data += 4);
		workunit->local_bodies[i].position.z = btof(msg.data += 4);
		workunit->local_bodies[i].velocity.x = btof(msg.data += 4);
		workunit->local_bodies[i].velocity.y = btof(msg.data += 4);
		workunit->local_bodies[i].velocity.z = btof(msg.data += 4);
	}
	workunit->neighborcount = btoi(msg.data += 4);
	workunit->neighborhood = (t_body *)malloc(sizeof(t_body) * workunit->neighborcount);
	for (int i = 0; i < workunit->neighborcount; i++)
	{
		workunit->neighborhood[i].position.x = btof(msg.data += 4);
		workunit->neighborhood[i].position.y = btof(msg.data += 4);
		workunit->neighborhood[i].position.z = btof(msg.data += 4);
		workunit->neighborhood[i].velocity.x = btof(msg.data += 4);
		workunit->neighborhood[i].velocity.y = btof(msg.data += 4);
		workunit->neighborhood[i].velocity.z = btof(msg.data += 4);
	}<commit_msg>converted position and velocity to cl_float4<commit_after>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   deserialize_workunit.c                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: ssmith <<EMAIL>>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2017/05/17 17:22:04 by ssmith            #+#    #+#             */
/*   Updated: 2017/05/17 17:22:54 by ssmith           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "dispatcher.h"

int			btoi(char *str)
{
	int		ret;

	for (unsigned int i = 0; i < sizeof(int); i++)
		((char *)(&ret))[i] = str[i];
	return (ret);
}

cl_float4	btoclf(char *str)
{
	cl_float4	ret;

	for (unsigned int i = 0; i < sizeof(cl_float4); i++)
		((char *)(&ret))[i] = str[i];
	return (ret);
}

t_workunit	*deserialize_workunit(t_msg msg)
{
	int			i;
	t_workunit	*workunit;

	i = 0;
	workunit = malloc(sizeof(t_workunit));
	workunit->id = btoi(msg.data);
	workunit->localcount = btoi(msg.data += 4);
	workunit->local_bodies = (t_body *)malloc(sizeof(t_body) * workunit->localcount);
	for (int i = 0; i < workunit->localcount; i++)
	{
		workunit->local_bodies[i].position = btoclf(msg.data += 16);
		workunit->local_bodies[i].velocity = btoclf(msg.data += 16);
	}
	workunit->neighborcount = btoi(msg.data += 4);
	workunit->neighborhood = (t_body *)malloc(sizeof(t_body) * workunit->neighborcount);
	for (int i = 0; i < workunit->neighborcount; i++)
	{
		workunit->neighborhood[i].position = btoclf(msg.data += 16);
		workunit->neighborhood[i].velocity = btoclf(msg.data += 16);
	}
{'fraction_non_alphanumeric': 0.2401111823818687, 'fraction_numerical': 0.020953602736797094, 'mean_word_length': 1.9073958980733374, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6332023', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1542, 'n_words': 261}