<commit_before>require 'stringio'
require 'rstruct/registry'
require 'rstruct/types'
require 'rstruct/structure'
require 'rstruct/struct_builder'

module Rstruct
  module ClassMethods

    # Take the following C struct for example:
    #
    #   struct mach_header {
    #     uint32_t      magic;      /* mach magic number identifier */
    #     cpu_type_t    cputype;    /* cpu specifier */
    #     cpu_subtype_t cpusubtype; /* machine specifier */
    #     uint32_t      filetype;   /* type of file */
    #     uint32_t      ncmds;      /* number of load commands */
    #     uint32_t      sizeofcmds; /* the size of all the load commands */
    #     uint32_t      flags;      /* flags */
    #   }
    #
    # Which might be defined with rstruct as follows:
    #
    #   extend(Rstruct::ClassMethods)
    #
    #   typedef :uint32_t, :cpu_type_t
    #   typedef :uint32_t, :cpu_subtype_t
    #
    #   struct(:mach_header) {
    #     uint32_t      :magic      # mach magic number identifier
    #     cpu_type_t    :cputype    # cpu specifier
    #     cpu_subtype_t :cpusubtype # machine specifier
    #     uint32_t      :filetype   # type of file
    #     uint32_t      :ncmds      # number of load commands
    #     uint32_t      :sizeofcmds # the size of all the load commands
    #     uint32_t      :flags      # flags
    #   }
    #
    def struct(name, opts={},&block)
      Rstruct::Structure.new(name, opts, &block)
    end

    def typedef(p, t, opts={})
      reg = opts[:registry] || default_registry
      reg.typedef(p,t,opts)
    end

    def sizeof(typ, reg=nil)
      reg ||= default_registry
      if t=reg[typ]
        t.sizeof
      else
        raise(InvalidTypeError, "unknown type: #{typ}")
      end
    end

    # Returns the default Rstruct registry
    def default_registry
      Registry::DEFAULT_REGISTRY
    end

    def get_type(typ, reg=Registry::DEFAULT_REGISTRY)<commit_msg>use consistent register name<commit_after>require 'stringio'
require 'rstruct/registry'
require 'rstruct/types'
require 'rstruct/structure'
require 'rstruct/struct_builder'

module Rstruct
  module ClassMethods

    # Take the following C struct for example:
    #
    #   struct mach_header {
    #     uint32_t      magic;      /* mach magic number identifier */
    #     cpu_type_t    cputype;    /* cpu specifier */
    #     cpu_subtype_t cpusubtype; /* machine specifier */
    #     uint32_t      filetype;   /* type of file */
    #     uint32_t      ncmds;      /* number of load commands */
    #     uint32_t      sizeofcmds; /* the size of all the load commands */
    #     uint32_t      flags;      /* flags */
    #   }
    #
    # Which might be defined with rstruct as follows:
    #
    #   extend(Rstruct::ClassMethods)
    #
    #   typedef :uint32_t, :cpu_type_t
    #   typedef :uint32_t, :cpu_subtype_t
    #
    #   struct(:mach_header) {
    #     uint32_t      :magic      # mach magic number identifier
    #     cpu_type_t    :cputype    # cpu specifier
    #     cpu_subtype_t :cpusubtype # machine specifier
    #     uint32_t      :filetype   # type of file
    #     uint32_t      :ncmds      # number of load commands
    #     uint32_t      :sizeofcmds # the size of all the load commands
    #     uint32_t      :flags      # flags
    #   }
    #
    def struct(name, opts={},&block)
      Rstruct::Structure.new(name, opts, &block)
    end

    def typedef(p, t, opts={})
      reg = opts[:register] || default_registry
      reg.typedef(p,t,opts)
    end

    def sizeof(typ, reg=nil)
      reg ||= default_registry
      if t=reg[typ]
        t.sizeof
      else
        raise(InvalidTypeError, "unknown type: #{typ}")
      end
    end

    # Returns the default Rstruct registry
    def default_registry
      Registry::DEFAULT_REGISTRY
    end

    def get_type(typ, reg=Registry::DEFAULT_REGISTRY)
{'fraction_non_alphanumeric': 0.09154383242823895, 'fraction_numerical': 0.012412723041117145, 'mean_word_length': 2.06984126984127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7098985', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1224, 'n_words': 314}