<commit_before>#include "ruby.h"

#define L 0xFFFFFFFF
static VALUE
rb_sumbur(VALUE self, VALUE hashed_int, VALUE capacity)
{
    unsigned int h = NUM2UINT(hashed_int);
    unsigned int capa = NUM2UINT(capacity);
    unsigned int part, n, i, c;

    if (capacity == 0) {
        rb_raise(rb_eArgError, "Sumbur is not applicable to empty cluster");
    }

    part = L / capa;

    if (L - h <= part) return INT2FIX(0);

    n = 1;

    for(i = 2; i <= capa; i++) {
        c = L / (i * (i - 1));
        if (c <= h) {
            h -= c;
        }
        else {
            h += c * (i - n - 1);
            n = i;
            if (L / i - h < part) break;
        }
    }

    return INT2FIX(n - 1);
}

void
Init_native_sumbur()
{
    VALUE mod_sumbur = rb_define_module("Sumbur");
    VALUE mod_native = rb_define_module_under(mod_sumbur, "Native");

    rb_define_method(mod_native, "sumbur", rb_sumbur, 2);
    rb_extend_object(mod_native, mod_native);
}
<commit_msg>unroll first 23 loop steps<commit_after>#include "ruby.h"

#define L 0xFFFFFFFF
static VALUE
rb_sumbur(VALUE self, VALUE hashed_int, VALUE capacity)
{
    unsigned int h = NUM2UINT(hashed_int);
    unsigned int capa = NUM2UINT(capacity);
    unsigned int part, n, i, c;

    if (capacity == 0) {
        rb_raise(rb_eArgError, "Sumbur is not applicable to empty cluster");
    }

    part = L / capa;

    if (L - h <= part) return INT2FIX(0);

    n = 1;

    do {
        if (h >= L / 2) h -= L / 2;
        else {
            n = 2;
            if (L / 2 - h < part) break;
        }
        if (capa == 2) break;

#define curslice(i) (L / (i * (i - 1)))
#define unroll(i) \
        if (curslice(i) <= h) h -= curslice(i); \
        else {                                  \
            h += curslice(i) * (i - n - 1);     \
            n = i;                              \
            if (L / i - h < part) break;        \
        }                                       \
        if (capa == i) break

        unroll(3); unroll(4); unroll(5); unroll(6); unroll(7);
        unroll(8); unroll(9); unroll(10); unroll(11); unroll(12);
        unroll(13); unroll(14); unroll(15); unroll(16); unroll(17);
        unroll(18); unroll(19); unroll(20); unroll(21); unroll(22);
        unroll(23); unroll(24);

        for(i = 25; i <= capa; i++) {
            c = L / (i * (i - 1));
            if (c <= h) {
                h -= c;
            }
            else {
                h += c * (i - n - 1);
                n = i;
                if (L / i - h < part) break;
            }
        }
    } while(0);
    return INT2FIX(n - 1);
}

void
Init_native_sumbur()
{
    VALUE mod_sumbur = rb_define_module("Sumbur");
    VALUE mod_native = rb_define_module_under(mod_sumbur, "Native");

    rb_define_method(mod_native, "sumbur", rb_sumbur, 2);
    rb_extend_object(mod_native, mod_native);
}

{'fraction_non_alphanumeric': 0.14455307262569833, 'fraction_numerical': 0.025837988826815643, 'mean_word_length': 1.638121546961326, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7015305', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1018, 'n_words': 271}