<commit_before>#include <algorithm>
#include <iostream>
#include <random>

#include "game.hpp"

using namespace std;

int
rng(int low, int high)
{
    static random_device rand_dev;
    static mt19937 generator(rand_dev());
    return uniform_int_distribution<int>(low, high)(generator);
}

int*
find(int *arr, int len, int val)
{
    for (;;) {
        if (len <= 0) return NULL;
        int mid = len/2;
        int v = arr[mid];
        if (v == val) {
            return arr + mid;
        } else if (v < val) {
            arr += (mid + 1);
            len -= (mid + 1);
        } else {
            len = mid;
        }
    }
}

int
main(int argc, char** argv)
{
    if (argc != 5 && argc != 6) {
        cout << "Syntax: " << argv[0] << " nNodes minOutDeg maxOutDeg minInDeg maxInDeg" << endl;
        return -1;
    }

    // parse arguments
    int n = stoi(argv[1]);
    int minD = stoi(argv[2]);
    int maxD = stoi(argv[3]);
    int minI = stoi(argv[4]);
    int maxI = stoi(argv[5]);

    // check bad arguments
    if (minD < 1) {
        cerr << "min degree < 1?!" << endl;
        return -1;
    }
    if (minD > n) {
        cerr << "min degree > num nodes?!" << endl;
        return -1;
    }
    if (minD > maxD) {
        cerr << "min degree > max degree?!" << endl;
        return -1;
    }
    if (minI < 1) {
        cerr << "min degree < 1?!" << endl;
        return -1;
    }
    if (minI > n) {
        cerr << "min degree > num nodes?!" << endl;
        return -1;
    }
    if (minI > maxI) {
        cerr << "min degree > max degree?!" << endl;
        return -1;
    }
 
    // allocate edge target array
    int *src = new int[n];
    int *tgt = new int[n];
    for (int j=0; j<n; j++) src[j] = j;
    for (int j=0; j<n; j++) tgt[j] = j;
    int src_count = n, tgt_count = n;
    int intodo = n, outtodo = n;

    // array for temporarily removing unwanted target nodes
    int **ptrs = new int*[maxD+1];

    // generate game
    pg::Game game(n);

    // initialize <n> nodes
    for (int i=0; i<n; i++) game.initNode(n, n, rng(0, 1));

    while ((outtodo > 0 and tgt_count > 0) or (intodo > 0 and src_count > 0)) {
        // obtain source node
        int from = src[rng(0, src_count-1)];

        // (temporarily) remove target nodes and <from> from tgt array
        int removed = 0;
        ptrs[0] = find(tgt, tgt_count, from);
        const int of_size = game.out[from].size();
        for (int i=0; i<of_size; i++) ptrs[i+1] = find(tgt, tgt_count, game.out[from][i]);
        std::sort(ptrs, ptrs+of_size+1, [] (int* a, int* b) { return a > b; });

        for (int i=0; i<=of_size and ptrs[i] != NULL; i++) {<commit_msg>Fixed bug in stgame generator that produced trivial games<commit_after>#include <algorithm>
#include <iostream>
#include <random>

#include "game.hpp"

using namespace std;

int
rng(int low, int high)
{
    static random_device rand_dev;
    static mt19937 generator(rand_dev());
    return uniform_int_distribution<int>(low, high)(generator);
}

int*
find(int *arr, int len, int val)
{
    for (;;) {
        if (len <= 0) return NULL;
        int mid = len/2;
        int v = arr[mid];
        if (v == val) {
            return arr + mid;
        } else if (v < val) {
            arr += (mid + 1);
            len -= (mid + 1);
        } else {
            len = mid;
        }
    }
}

int
main(int argc, char** argv)
{
    if (argc != 5 && argc != 6) {
        cout << "Syntax: " << argv[0] << " nNodes minOutDeg maxOutDeg minInDeg maxInDeg" << endl;
        return -1;
    }

    // parse arguments
    int n = stoi(argv[1]);
    int minD = stoi(argv[2]);
    int maxD = stoi(argv[3]);
    int minI = stoi(argv[4]);
    int maxI = stoi(argv[5]);

    // check bad arguments
    if (minD < 1) {
        cerr << "min degree < 1?!" << endl;
        return -1;
    }
    if (minD > n) {
        cerr << "min degree > num nodes?!" << endl;
        return -1;
    }
    if (minD > maxD) {
        cerr << "min degree > max degree?!" << endl;
        return -1;
    }
    if (minI < 1) {
        cerr << "min degree < 1?!" << endl;
        return -1;
    }
    if (minI > n) {
        cerr << "min degree > num nodes?!" << endl;
        return -1;
    }
    if (minI > maxI) {
        cerr << "min degree > max degree?!" << endl;
        return -1;
    }
 
    // allocate edge target array
    int *src = new int[n];
    int *tgt = new int[n];
    for (int j=0; j<n; j++) src[j] = j;
    for (int j=0; j<n; j++) tgt[j] = j;
    int src_count = n, tgt_count = n;
    int intodo = n, outtodo = n;

    // array for temporarily removing unwanted target nodes
    int **ptrs = new int*[maxD+1];

    // generate game
    pg::Game game(n);

    // initialize <n> nodes
    for (int i=0; i<n; i++) game.initNode(i, i, rng(0, 1));

    while ((outtodo > 0 and tgt_count > 0) or (intodo > 0 and src_count > 0)) {
        // obtain source node
        int from = src[rng(0, src_count-1)];

        // (temporarily) remove target nodes and <from> from tgt array
        int removed = 0;
        ptrs[0] = find(tgt, tgt_count, from);
        const int of_size = game.out[from].size();
        for (int i=0; i<of_size; i++) ptrs[i+1] = find(tgt, tgt_count, game.out[from][i]);
        std::sort(ptrs, ptrs+of_size+1, [] (int* a, int* b) { return a > b; });

        for (int i=0; i<=of_size and ptrs[i] != NULL; i++) {
{'fraction_non_alphanumeric': 0.1653631284916201, 'fraction_numerical': 0.01713221601489758, 'mean_word_length': 1.9723298284449364, 'pattern_counts': {'":': 0, '<': 101, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4471932', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1963, 'n_words': 600}