<commit_before>#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "plumber.h"

typedef struct {
    sp_ftbl *ft;
    SPFLOAT val;
    unsigned int index;
} sporth_tbl_d;

int sporth_tget(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    sporth_tbl_d *td;
    char *ftname;

    switch(pd->mode){
        case PLUMBER_CREATE:
            td = malloc(sizeof(sporth_tbl_d));
            plumber_add_ugen(pd, SPORTH_TGET, td);
            if(sporth_check_args(stack, "fs") != SPORTH_OK) {
               fprintf(stderr,"Init: not enough arguments for tget\n");
                return PLUMBER_NOTOK;
            }
            td = pd->last->ud;
            ftname = sporth_stack_pop_string(stack);
            td->index = floor(sporth_stack_pop_float(stack));
            if(plumber_ftmap_search(pd, ftname, &td->ft) == PLUMBER_NOTOK) {
                fprintf(stderr, "tget: could not find table '%s'\n", ftname);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            free(ftname);
            sporth_stack_push_float(stack, 0.0);
            break;

        case PLUMBER_INIT:
            td = pd->last->ud;
            ftname = sporth_stack_pop_string(stack);
            td->index = floor(sporth_stack_pop_float(stack));
            free(ftname);
            sporth_stack_push_float(stack, 0.0);
            break;

        case PLUMBER_COMPUTE:
            td = pd->last->ud;
            td->index = (unsigned int) floor(sporth_stack_pop_float(stack)) % td->ft->size;
            sporth_stack_push_float(stack, td->ft->tbl[td->index]);
            break;

        case PLUMBER_DESTROY:
            td = pd->last->ud;
            free(td);
            break;

        default:
            fprintf(stderr,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}

int sporth_tset(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    sporth_tbl_d *td;
    char *ftname;

    switch(pd->mode){
        case PLUMBER_CREATE:
            td = malloc(sizeof(sporth_tbl_d));
            plumber_add_ugen(pd, SPORTH_TSET, td);
            if(sporth_check_args(stack, "ffs") != SPORTH_OK) {
               fprintf(stderr,"Init: not enough arguments for tset\n");
                return PLUMBER_NOTOK;
            }
            td = pd->last->ud;
            ftname = sporth_stack_pop_string(stack);
            td->index = floor(sporth_stack_pop_float(stack));
            td->val = sporth_stack_pop_float(stack);
            if(plumber_ftmap_search(pd, ftname, &td->ft) == PLUMBER_NOTOK) {
                fprintf(stderr, "tset: could not find table '%s'\n", ftname);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            free(ftname);
            break;

        case PLUMBER_INIT:
            td = pd->last->ud;
            ftname = sporth_stack_pop_string(stack);
            td->index = floor(sporth_stack_pop_float(stack));
            td->val = sporth_stack_pop_float(stack);
            free(ftname);
            break;

        case PLUMBER_COMPUTE:
            td = pd->last->ud;
            td->index = (unsigned int) floor(sporth_stack_pop_float(stack)) % td->ft->size;
            td->val = sporth_stack_pop_float(stack);
            td->ft->tbl[td->index] = td->val;
            break;

        case PLUMBER_DESTROY:
            td = pd->last->ud;
            free(td);
            break;<commit_msg>fixed tget/tset<commit_after>#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "plumber.h"

typedef struct {
    sp_ftbl *ft;
    SPFLOAT val;
    unsigned int index;
} sporth_tbl_d;

int sporth_tget(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    sporth_tbl_d *td;
    char *ftname;

    switch(pd->mode){
        case PLUMBER_CREATE:
            td = malloc(sizeof(sporth_tbl_d));
            plumber_add_ugen(pd, SPORTH_TGET, td);
            if(sporth_check_args(stack, "fs") != SPORTH_OK) {
               fprintf(stderr,"Init: not enough arguments for tget\n");
                return PLUMBER_NOTOK;
            }
            ftname = sporth_stack_pop_string(stack);
            td->index = floor(sporth_stack_pop_float(stack));
            if(plumber_ftmap_search(pd, ftname, &td->ft) == PLUMBER_NOTOK) {
                fprintf(stderr, "tget: could not find table '%s'\n", ftname);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            free(ftname);
            sporth_stack_push_float(stack, 0.0);
            break;

        case PLUMBER_INIT:
            td = pd->last->ud;
            ftname = sporth_stack_pop_string(stack);
            td->index = floor(sporth_stack_pop_float(stack));
            free(ftname);
            sporth_stack_push_float(stack, 0.0);
            break;

        case PLUMBER_COMPUTE:
            td = pd->last->ud;
            td->index = (unsigned int) floor(sporth_stack_pop_float(stack)) % td->ft->size;
            sporth_stack_push_float(stack, td->ft->tbl[td->index]);
            break;

        case PLUMBER_DESTROY:
            td = pd->last->ud;
            free(td);
            break;

        default:
            fprintf(stderr,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}

int sporth_tset(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    sporth_tbl_d *td;
    char *ftname;

    switch(pd->mode){
        case PLUMBER_CREATE:
            td = malloc(sizeof(sporth_tbl_d));
            plumber_add_ugen(pd, SPORTH_TSET, td);
            if(sporth_check_args(stack, "ffs") != SPORTH_OK) {
               fprintf(stderr,"Init: not enough arguments for tset\n");
                return PLUMBER_NOTOK;
            }
            ftname = sporth_stack_pop_string(stack);
            td->index = floor(sporth_stack_pop_float(stack));
            td->val = sporth_stack_pop_float(stack);
            if(plumber_ftmap_search(pd, ftname, &td->ft) == PLUMBER_NOTOK) {
                fprintf(stderr, "tset: could not find table '%s'\n", ftname);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            free(ftname);
            break;

        case PLUMBER_INIT:
            td = pd->last->ud;
            ftname = sporth_stack_pop_string(stack);
            td->index = floor(sporth_stack_pop_float(stack));
            td->val = sporth_stack_pop_float(stack);
            free(ftname);
            break;

        case PLUMBER_COMPUTE:
            td = pd->last->ud;
            td->index = (unsigned int) floor(sporth_stack_pop_float(stack)) % td->ft->size;
            td->val = sporth_stack_pop_float(stack);
            td->ft->tbl[td->index] = td->val;
            break;

        case PLUMBER_DESTROY:
            td = pd->last->ud;
            free(td);
            break;
{'fraction_non_alphanumeric': 0.11914460285132383, 'fraction_numerical': 0.0011638056444573757, 'mean_word_length': 1.8257295519934238, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 91, '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': '5055397', 'n_tokens_mistral': 2280, 'n_tokens_neox': 2224, 'n_words': 398}