<commit_before>#include <assert.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "uv.h"

#include "utils.h"

#define N_BACKLOG 64

#define SENDBUF_SIZE 1024

typedef struct {
  uint64_t number;
  uv_tcp_t* client;
  char sendbuf[SENDBUF_SIZE];
  int sendbuf_end;
} peer_state_t;

// Sets sendbuf/sendbuf_end in the given state to the contents of the
// NULL-terminated string passed as 'str'.
void set_peer_sendbuf(peer_state_t* state, const char* str) {
  int i = 0;
  for (; str[i]; ++i) {
    assert(i < SENDBUF_SIZE);
    state->sendbuf[i] = str[i];
  }
  state->sendbuf_end = i;
}

void on_alloc_buffer(uv_handle_t* handle, size_t suggested_size,
                     uv_buf_t* buf) {
  buf->base = (char*)xmalloc(suggested_size);
  buf->len = suggested_size;
}

void on_client_closed(uv_handle_t* handle) {
  uv_tcp_t* client = (uv_tcp_t*)handle;
  // The client handle owns the peer state storing its address in the data
  // field, so we free it here.
  if (client->data) {
    free(client->data);
  }
  free(client);
}

bool isprime(uint64_t n) {
  if (n % 2 == 0) {
    return n == 2 ? true : false;
  }

  for (uint64_t r = 3; r * r <= n; r += 2) {<commit_msg>Adding some comments to the isprime server<commit_after>// Primality testing server. Accepts a number and sends back "prime" or
// "composite" after testing the number for primality (in the naive, slow way).
//
// Can be configured via an environment variable to do this in a blocking way,
// without using libuv's work queue (MODE=BLOCK).
//
// <NAME> [http://eli.thegreenplace.net]
// This code is in the public domain.
#include <assert.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "uv.h"

#include "utils.h"

#define N_BACKLOG 64

#define SENDBUF_SIZE 1024

// State maintained for each connected client.
typedef struct {
  uint64_t number;
  uv_tcp_t* client;
  char sendbuf[SENDBUF_SIZE];
  int sendbuf_end;
} peer_state_t;

// Sets sendbuf/sendbuf_end in the given state to the contents of the
// NULL-terminated string passed as 'str'.
void set_peer_sendbuf(peer_state_t* state, const char* str) {
  int i = 0;
  for (; str[i]; ++i) {
    assert(i < SENDBUF_SIZE);
    state->sendbuf[i] = str[i];
  }
  state->sendbuf_end = i;
}

void on_alloc_buffer(uv_handle_t* handle, size_t suggested_size,
                     uv_buf_t* buf) {
  buf->base = (char*)xmalloc(suggested_size);
  buf->len = suggested_size;
}

void on_client_closed(uv_handle_t* handle) {
  uv_tcp_t* client = (uv_tcp_t*)handle;
  // The client handle owns the peer state storing its address in the data
  // field, so we free it here.
  if (client->data) {
    free(client->data);
  }
  free(client);
}

// Naive primality test, iterating all the way to sqrt(n) to find numbers that
// divide n.
bool isprime(uint64_t n) {
  if (n % 2 == 0) {
    return n == 2 ? true : false;
  }

  for (uint64_t r = 3; r * r <= n; r += 2) {
{'fraction_non_alphanumeric': 0.13164721141374838, 'fraction_numerical': 0.011673151750972763, 'mean_word_length': 3.5168374816983894, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 32, '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': '6709647', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1135, 'n_words': 344}