<commit_before>/* f/nash.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "f/nash.h"
#include <bitmapped_patricia_tree.h>

/* structures
*/
  /* u2_nair: bucket node.
  */
  struct u2_nair {
    u2_noun key;
    void*   val;
  };

  /* u2_buck: realloced bucket.
  */
  struct u2_buck {
    c3_w            con_w;
    struct u2_nair* sto_u;
  };

  /* u2_nash: wrapper around Patricia trie.
  */
  struct u2_nash {
    bpt_t sto;
  };

void u2_na_dump(struct u2_nash* nas_u);

/* u2_na_make(): create a new nounhash-table.
**
** nashtables live in C memory and do not take refs.
*/
struct u2_nash*
u2_na_make()
{
  struct u2_nash* nas_u = calloc(1, sizeof(*nas_u));
  //  fprintf(stderr, "[%%nash-make %p]\r\n", nas_u);
  return nas_u;
}

/* u2_na_put(): put into nash, replacing.
*/
void
u2_na_put(struct u2_nash* nas_u, u2_noun key, void* val)
{
  struct u2_buck* buc_u = 0;
  struct u2_nair* nuu_u = 0;
  c3_w     sot_w = 0;
  c3_w     i = 0;

  u2_noun tom = u2_mug(key);
  
  if ( !bpt_has_key(nas_u->sto, tom)) {
    bpt_t ots;

    buc_u = calloc(1, sizeof(*buc_u));
    ots = bpt_assoc(nas_u->sto, tom, buc_u);
    bpt_release(nas_u->sto);
    nas_u->sto = ots;
#if 0
    fprintf(stderr, "[%%nash-sto %p %p]\r\n", nas_u->sto, tom);
    if (!bpt_has_key(nas_u->sto, tom)) {
      u2_na_dump(nas_u);
      assert(0);
    }
#endif
  }
<commit_msg>check allocations<commit_after>/* f/nash.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "f/nash.h"
#include <bitmapped_patricia_tree.h>

/* structures
*/
  /* u2_nair: bucket node.
  */
  struct u2_nair {
    u2_noun key;
    void*   val;
  };

  /* u2_buck: realloced bucket.
  */
  struct u2_buck {
    c3_w            con_w;
    struct u2_nair* sto_u;
  };

  /* u2_nash: wrapper around Patricia trie.
  */
  struct u2_nash {
    bpt_t sto;
  };

void u2_na_dump(struct u2_nash* nas_u);

/* u2_na_make(): create a new nounhash-table.
**
** nashtables live in C memory and do not take refs.
*/
struct u2_nash*
u2_na_make()
{
  struct u2_nash* nas_u = calloc(1, sizeof(*nas_u));
  c3_assert(nas_u);
  //  fprintf(stderr, "[%%nash-make %p]\r\n", nas_u);
  return nas_u;
}

/* u2_na_put(): put into nash, replacing.
*/
void
u2_na_put(struct u2_nash* nas_u, u2_noun key, void* val)
{
  struct u2_buck* buc_u = 0;
  struct u2_nair* nuu_u = 0;
  c3_w     sot_w = 0;
  c3_w     i = 0;

  u2_noun tom = u2_mug(key);
  
  if ( !bpt_has_key(nas_u->sto, tom)) {
    bpt_t ots;

    buc_u = calloc(1, sizeof(*buc_u));
    c3_assert(buc_u);
    ots = bpt_assoc(nas_u->sto, tom, buc_u);
    bpt_release(nas_u->sto);
    nas_u->sto = ots;
#if 0
    fprintf(stderr, "[%%nash-sto %p %p]\r\n", nas_u->sto, tom);
    if (!bpt_has_key(nas_u->sto, tom)) {
      u2_na_dump(nas_u);
      assert(0);
    }
#endif
  }

{'fraction_non_alphanumeric': 0.15808297567954221, 'fraction_numerical': 0.02503576537911302, 'mean_word_length': 2.8315068493150686, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '5570798', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1313, 'n_words': 275}