<commit_before>/* scatter the data to the windssssss */
//#define DEBUG_TOOL
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "runtime.h"
#include "debug.h"
#include "type_info.h"
#include "bitmap.h"
#include "scan.h"
#include "log.h"
#include "choice.h"
#include "writepkt.h"

/* OK, these relname things are getting out of hand,
 * we need some abstraction to let the user / program
 * control it. */
#define RELNAME_RELOC	"reloc"

struct scatterscan_info { unsigned int	rel_c; };

static struct choice_cache	*ccache = NULL;
static int			refresh_count = 0;
#define MAX_REFRESH		10

/*
 * get a random free block to replace
 */
uint64_t choice_find(struct type_info* ti, const struct fsl_rtt_reloc* rel)
{
	int	i;
	for (i = 0; i <= 10; i++) {
		uint64_t	rand_choice;
		int		k;

		rand_choice = rand() % (choice_max(ccache) - choice_min(ccache));
		k = choice_find_avail(ccache, rand_choice, 1);
		if (k == -1) continue;
		/* check cache first. not set => not available */
		if (!choice_is_set(ccache, k-choice_min(ccache))) continue;
		return k;
	}

	if (refresh_count == MAX_REFRESH) return ~0;

	choice_free(ccache);
	ccache = choice_alloc(ti, rel);
	refresh_count++;

	return ~0;
}

/* compare location of selected with reloc locations */
/* if reloc location needs to be set, try to swap in */
/* if rel_sel location is on empty reloc location, try to swap out */
void swap_rel_sel(
	struct type_info* ti, const struct fsl_rtt_reloc* rel,
	struct type_info* rel_sel_ti, unsigned int sel_v)
{
	uint64_t		replace_choice_idx;

	/* already in an OK place, don't do anything<commit_msg>minor silliness with choice offsetting<commit_after>/* scatter the data to the windssssss */
//#define DEBUG_TOOL
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "runtime.h"
#include "debug.h"
#include "type_info.h"
#include "bitmap.h"
#include "scan.h"
#include "log.h"
#include "choice.h"
#include "writepkt.h"

/* OK, these relname things are getting out of hand,
 * we need some abstraction to let the user / program
 * control it. */
#define RELNAME_RELOC	"reloc"

struct scatterscan_info { unsigned int	rel_c; };

static struct choice_cache	*ccache = NULL;
static int			refresh_count = 0;
#define MAX_REFRESH		10

/*
 * get a random free block to replace
 */
uint64_t choice_find(struct type_info* ti, const struct fsl_rtt_reloc* rel)
{
	int	i;
	for (i = 0; i <= 10; i++) {
		uint64_t	rand_choice;
		int		k;

		rand_choice = rand() % (choice_max(ccache) - choice_min(ccache));
		k = choice_find_avail(ccache, rand_choice+choice_min(ccache), 1);
		if (k == -1) continue;
		/* check cache first. not set => not available */
		if (!choice_is_set(ccache, k-choice_min(ccache))) continue;
		return k;
	}

	if (refresh_count == MAX_REFRESH) return ~0;

	choice_free(ccache);
	ccache = choice_alloc(ti, rel);
	refresh_count++;

	return ~0;
}

/* compare location of selected with reloc locations */
/* if reloc location needs to be set, try to swap in */
/* if rel_sel location is on empty reloc location, try to swap out */
void swap_rel_sel(
	struct type_info* ti, const struct fsl_rtt_reloc* rel,
	struct type_info* rel_sel_ti, unsigned int sel_v)
{
	uint64_t		replace_choice_idx;

	/* already in an OK place, don't do anything
{'fraction_non_alphanumeric': 0.1216696269982238, 'fraction_numerical': 0.009473060982830076, 'mean_word_length': 4.304552590266876, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '2728643', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1227, 'n_words': 395}