<commit_before>#include "iwkv.h"
#include "iwlog.h"
#include "iwutils.h"
#include "iwcfg.h"
#include "iwkv_tests.h"
#include "iwkv_internal.h"

#define KBUFSZ 1024
#define VBUFSZ 1024
char kbuf[KBUFSZ];
char vbuf[VBUFSZ];

static const IWKV_val EMPTY_VAL = {0};

uint32_t g_seed;

int init_suite(void) {
  iwrc rc = iwkv_init();
  RCRET(rc);
  g_seed = 2681089616;
  return rc;
}

int clean_suite(void) {
  return 0;
}





static void iwkv_test7_2_impl(int direction) {
  iwrc rc;
  IWKV iwkv;
  IWDB db;
  IWKV_val key = {0};
  IWKV_val val = {0};
  IWKV_cursor cur1;
  IWKV_OPTS opts = {
    .path = direction > 0 ? "iwkv_test7_2_fwd.db" : "iwkv_test7_2_back.db",
    .oflags = IWKV_TRUNC,
    .random_seed = g_seed

  };
  rc = iwkv_open(&opts, &iwkv);
  CU_ASSERT_EQUAL_FATAL(rc, 0);
  rc = iwkv_db(iwkv, 1, IWDB_COMPOUND_KEYS, &db);
  CU_ASSERT_EQUAL_FATAL(rc, 0);

  const int nrecords = 50000;

  for (int i = 0; i < nrecords; ++i) {
    snprintf(kbuf, KBUFSZ, "5368fce5-c138-4f0d-bfee-dbce07eb28e1%d", i);
    snprintf(vbuf, VBUFSZ, "%04d", i);
    key.data = kbuf;
    key.size = strlen(key.data);
    key.compound = direction > 0 ? i + 1 : nrecords - i;

    val.data = vbuf;
    val.size = strlen(val.data);
    rc = iwkv_put(db, &key, &val, 0);
    CU_ASSERT_EQUAL_FATAL(rc, 0);
  }

  for (int i = 0; i < nrecords; ++i) {
    snprintf(kbuf, KBUFSZ, "5368fce5-c138-4f0d-bfee-dbce07eb28e1%d", i);
    snprintf(vbuf, VBUFSZ, "%04d", i);
    key.data = kbuf;
    key.size = strlen(key.data);
    key.compound = direction > 0 ? i + 1 : nrecords - i;
    rc = iwkv_get(db, &key, &val);
    CU_ASSERT_EQUAL_FATAL(rc, 0);
  }
  rc = iwkv_close(&iwkv);<commit_msg>* Mem leack fix in iwkv_test7<commit_after>#include "iwkv.h"
#include "iwlog.h"
#include "iwutils.h"
#include "iwcfg.h"
#include "iwkv_tests.h"
#include "iwkv_internal.h"

#define KBUFSZ 1024
#define VBUFSZ 1024
char kbuf[KBUFSZ];
char vbuf[VBUFSZ];

static const IWKV_val EMPTY_VAL = {0};

uint32_t g_seed;

int init_suite(void) {
  iwrc rc = iwkv_init();
  RCRET(rc);
  g_seed = 2681089616;
  return rc;
}

int clean_suite(void) {
  return 0;
}





static void iwkv_test7_2_impl(int direction) {
  iwrc rc;
  IWKV iwkv;
  IWDB db;
  IWKV_val key = {0};
  IWKV_val val = {0};
  IWKV_cursor cur1;
  IWKV_OPTS opts = {
    .path = direction > 0 ? "iwkv_test7_2_fwd.db" : "iwkv_test7_2_back.db",
    .oflags = IWKV_TRUNC,
    .random_seed = g_seed

  };
  rc = iwkv_open(&opts, &iwkv);
  CU_ASSERT_EQUAL_FATAL(rc, 0);
  rc = iwkv_db(iwkv, 1, IWDB_COMPOUND_KEYS, &db);
  CU_ASSERT_EQUAL_FATAL(rc, 0);

  const int nrecords = 50000;

  for (int i = 0; i < nrecords; ++i) {
    snprintf(kbuf, KBUFSZ, "5368fce5-c138-4f0d-bfee-dbce07eb28e1%d", i);
    snprintf(vbuf, VBUFSZ, "%04d", i);
    key.data = kbuf;
    key.size = strlen(key.data);
    key.compound = direction > 0 ? i + 1 : nrecords - i;

    val.data = vbuf;
    val.size = strlen(val.data);
    rc = iwkv_put(db, &key, &val, 0);
    CU_ASSERT_EQUAL_FATAL(rc, 0);
  }

  for (int i = 0; i < nrecords; ++i) {
    snprintf(kbuf, KBUFSZ, "5368fce5-c138-4f0d-bfee-dbce07eb28e1%d", i);
    snprintf(vbuf, VBUFSZ, "%04d", i);
    key.data = kbuf;
    key.size = strlen(key.data);
    key.compound = direction > 0 ? i + 1 : nrecords - i;
    rc = iwkv_get(db, &key, &val);
    CU_ASSERT_EQUAL_FATAL(rc, 0);
    iwkv_val_dispose(&val);
  }
  rc = iwkv_close(&iwkv);
{'fraction_non_alphanumeric': 0.1534594914251922, 'fraction_numerical': 0.04937906564163217, 'mean_word_length': 3.4106910039113427, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '4791672', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1587, 'n_words': 323}