<commit_before>/*--------------------------------------------------------------------------
 * File:  sys_xtuml.c
 *
 * Description:
 * your copyright statement can go here (from te_copyright.body)
 *--------------------------------------------------------------------------*/

#include "sys_sys_types.h"
#include "ooaofooa_classes.h"

/*
 * Allocate the storage for the pool of container nodes.
 */
static Escher_ObjectSet_s node1_FreeList;
static Escher_SetElement_s node1s[ SYS_MAX_CONTAINERS ];

/*
 * Supply a unique integer ID.
 */
Escher_UniqueID_t
Escher_ID_factory( void )
{
  static Escher_UniqueID_t Escher_ID_factory = 1;
  return Escher_ID_factory++;
}

/*
 * Deserialize a UUID into a unique integer ID.
 */
Escher_UniqueID_t Escher_uuidtou128( const c_t * s )
{
  u1_t b, isuuid = 0;
  s4_t n = 0; /* decimal answer */
  Escher_UniqueID_t v = 0; /* 128-bit hex answer */

  while(*s) {
    b = *s++;

    switch(b) {
    case '0'...'9':
      b -= '0';
      n = n * 10 + b;
      break;

    case 'a'...'f':
      b -= 'a';
      b += 10;
      break;

    case 'A'...'F':
      b -= 'A';
      b += 10;
      break;

    case '-':
      isuuid++;
    default:
      continue;
    }
    v = (v << 4) | (b & 0xF);
  }

  if ( 4 == isuuid )
    return v;
  else
    return n;
}


#define ESCHER_GET_BITS(v,b,m) (b < sizeof(v)*8 ? (m & (v >> b)) : 0)
/*
 * Serialize an unsigned 128-bit integer into a string format UUID.
 */
c_t * Escher_u128touuid( c_t * s, Escher_UniqueID_t i )
{
  u4_t uuid1 = (u4_t) ESCHER_GET_BITS( i, 96, 0xffffffff );
  u2_t uuid2 = (u2_t) ESCHER_GET_BITS( i, 80, 0xffff );
  u2_t uuid3 = (u2_t) ESCHER_GET_BITS( i, 64, 0xffff );
  u2_t uuid4 = (u2_t) ESCHER_GET_BITS( i, 48, 0xffff );
  u2_t uuid5 = (u2_t) ESCHER_GET_BITS( i, 32, 0xffff );
  u4_t uuid6 = (u4_t) ESCHER_GET_BITS( i, 0, 0xffffffff );
  snprintf( s, 40, "\"%08lx-%04x-%04x-%04x-%04x%08lx\"", uuid1, uuid2, uuid3, uuid4, uuid5, uuid6 );
  return s;
}


/*
 * Detect empty handles in expressions.
 */
void * xtUML_detect_empty_handle( void * h, const char * s1, const char * s2 )
{
  if ( 0 == h ) {
    XTUML_EMPTY_HANDLE_TRACE( s1, s2 );
  }
  return h;
}

/*
 * Initialize the node1 instances by linking them into a collection.
 * These containoids will be collected into a null-terminated,
 * singly linked list (slist).
 * This needs to be called during architecture initialization.
 */
void
Escher_SetFactoryInit( const i_t n1_size )
{
  Escher_size_t i;
  node1_FreeList.head = &node1s[ 0 ];
  /* Build the collection (linked list) of node1 instances.  */
  for ( i = 0; ( i + 1 ) < n1_size; i++ ) {
    node1s[ i ].next = &node1s[ i + 1 ];
    node1s[ i ].object = 0;
  }
  node1s[ n1_size - 1 ].next = 0;
}

/*
 * This will copy all of the elements from one set into another
 * set.  If the target set is not empty, it will be cleared
 * before the copy operation occurs freeing any nodes in that set.
 * The new set will use containoids from the free list.
 */
void 
Escher_CopySet( Escher_ObjectSet_s * to_set,
                Escher_ObjectSet_s * const from_set )
{
  const Escher_SetElement_s * slot;

  /* May be copying into an existing set, release target collection nodes.  */
  Escher_ClearSet( to_set );

  for ( slot = from_set->head; ( slot != 0 ); slot = slot->next ) {
    Escher_SetInsertElement( to_set, slot->object ); 
  }
}

/*
 * Release all nodes in the given set back to the free pool.
 */
void
Escher_ClearSet( Escher_ObjectSet_s * set )
{
  if ( set->head != 0 ) {                                    /* empty set  */
    Escher_SetElement_s * slot;
    for ( slot = set->head; ( slot->next != 0 ); slot = slot->next ); /* Find end.  */
    slot->next = node1_FreeList.head;     /* Tie string to free list.      */
    node1_FreeList.head = set->head;      /* Point free list to head.      */
    Escher_InitSet( set );                /* Zero set out.  */
  }
}

/*<commit_msg>job #5007 changed gen/sys_xtuml.c to match generated header<commit_after>/*--------------------------------------------------------------------------
 * File:  sys_xtuml.c
 *
 * Description:
 * your copyright statement can go here (from te_copyright.body)
 *--------------------------------------------------------------------------*/

#include "sys_sys_types.h"
#include "ooaofooa_classes.h"

/*
 * Allocate the storage for the pool of container nodes.
 */
static Escher_ObjectSet_s node1_FreeList;
static Escher_SetElement_s node1s[ SYS_MAX_CONTAINERS ];

/*
 * Supply a unique integer ID.
 */
Escher_UniqueID_t
Escher_ID_factory( void )
{
  static Escher_UniqueID_t Escher_ID_factory = 1;
  return Escher_ID_factory++;
}

/*
 * Deserialize a UUID into a unique integer ID.
 */
Escher_UniqueID_t Escher_uuidtou128( const c_t * s )
{
  u1_t b, isuuid = 0;
  s4_t n = 0; /* decimal answer */
  Escher_UniqueID_t v = 0; /* 128-bit hex answer */

  while(*s) {
    b = *s++;

    switch(b) {
    case '0'...'9':
      b -= '0';
      n = n * 10 + b;
      break;

    case 'a'...'f':
      b -= 'a';
      b += 10;
      break;

    case 'A'...'F':
      b -= 'A';
      b += 10;
      break;

    case '-':
      isuuid++;
    default:
      continue;
    }
    v = (v << 4) | (b & 0xF);
  }

  if ( 4 == isuuid )
    return v;
  else
    return n;
}


#define ESCHER_GET_BITS(v,b,m) (b < sizeof(v)*8 ? (m & (v >> b)) : 0)
/*
 * Serialize an unsigned 128-bit integer into a string format UUID.
 */
c_t * Escher_u128touuid( c_t * s, Escher_UniqueID_t i )
{
  u4_t uuid1 = (u4_t) ESCHER_GET_BITS( i, 96, 0xffffffff );
  u2_t uuid2 = (u2_t) ESCHER_GET_BITS( i, 80, 0xffff );
  u2_t uuid3 = (u2_t) ESCHER_GET_BITS( i, 64, 0xffff );
  u2_t uuid4 = (u2_t) ESCHER_GET_BITS( i, 48, 0xffff );
  u2_t uuid5 = (u2_t) ESCHER_GET_BITS( i, 32, 0xffff );
  u4_t uuid6 = (u4_t) ESCHER_GET_BITS( i, 0, 0xffffffff );
  snprintf( s, 40, "\"%08lx-%04x-%04x-%04x-%04x%08lx\"", uuid1, uuid2, uuid3, uuid4, uuid5, uuid6 );
  return s;
}


/*
 * Detect empty handles in expressions.
 */
void * xtUML_detect_empty_handle( void * h, const char * s1, const char * s2 )
{
  if ( 0 == h ) {
    XTUML_EMPTY_HANDLE_TRACE( s1, s2 );
  }
  return h;
}

/*
 * Initialize the node1 instances by linking them into a collection.
 * These containoids will be collected into a null-terminated,
 * singly linked list (slist).
 * This needs to be called during architecture initialization.
 */
void
Escher_SetFactoryInit( const i_t n1_size )
{
  Escher_size_t i;
  node1_FreeList.head = &node1s[ 0 ];
  /* Build the collection (linked list) of node1 instances.  */
  for ( i = 0; ( i + 1 ) < n1_size; i++ ) {
    node1s[ i ].next = &node1s[ i + 1 ];
    node1s[ i ].object = 0;
  }
  node1s[ n1_size - 1 ].next = 0;
}

/*
 * This will copy all of the elements from one set into another
 * set.  If the target set is not empty, it will be cleared
 * before the copy operation occurs freeing any nodes in that set.
 * The new set will use containoids from the free list.
 */
void 
Escher_CopySet( Escher_ObjectSet_s * to_set,
                const Escher_ObjectSet_s * const from_set )
{
  const Escher_SetElement_s * slot;

  /* May be copying into an existing set, release target collection nodes.  */
  Escher_ClearSet( to_set );

  for ( slot = from_set->head; ( slot != 0 ); slot = slot->next ) {
    Escher_SetInsertElement( to_set, slot->object ); 
  }
}

/*
 * Release all nodes in the given set back to the free pool.
 */
void
Escher_ClearSet( Escher_ObjectSet_s * set )
{
  if ( set->head != 0 ) {                                    /* empty set  */
    Escher_SetElement_s * slot;
    for ( slot = set->head; ( slot->next != 0 ); slot = slot->next ); /* Find end.  */
    slot->next = node1_FreeList.head;     /* Tie string to free list.      */
    node1_FreeList.head = set->head;      /* Point free list to head.      */
    Escher_InitSet( set );                /* Zero set out.  */
  }
}

/*
{'fraction_non_alphanumeric': 0.16518537328593194, 'fraction_numerical': 0.03021838496698832, 'mean_word_length': 2.280716368179925, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2947199', 'n_tokens_mistral': 3089, 'n_tokens_neox': 2896, 'n_words': 844}