<commit_before>require_relative '../libkyotocabinet_ffi'

module KyotoCabinet

  # in-memory (or prototype) database types
  MEMORY_HASH       = :-
  MEMORY_TREE       = :+
  MEMORY_STASH      = :':'
  MEMORY_CACHE_HASH = :*
  MEMORY_CACHE_TREE = :%

  # on-disk database types
  FILE_HASH         = :".kch"
  FILE_TREE         = :".kct"
  FILE_PLAIN_TEXT   = :".kcx"
  DIR_HASH          = :".kcd"
  DIR_TREE          = :".kcf"

  MEMORY_DB_TYPE = [
    MEMORY_HASH,
    MEMORY_TREE,
    MEMORY_STASH,
    MEMORY_CACHE_HASH,
    MEMORY_CACHE_TREE
  ]

  FILE_DB_TYPE = [
    FILE_HASH,
    FILE_TREE,
    FILE_PLAIN_TEXT,
    DIR_HASH,
    DIR_TREE
  ]

  DEFAULT_TEMP_PREFIX = 'kyoto-db-'

  def self.match_memorydb_type? value
    return false unless value
    value_s = value.to_s
    MEMORY_DB_TYPE.any? { |ext| value_s == ext.to_s }
  end

  def self.match_filedb_type? value
    return false unless value
    value_s = value.to_s
    FILE_DB_TYPE.any? { |ext| value_s.end_with? ext.to_s }
  end

  module Db

    def new
      @kc_db_pointer = LibKyotoCabinet::kcdbnew
    end

    def last_error_code
      LibKyotoCabinet::kcdbecode(@kc_db_pointer)
    end

    def last_error_message
      LibKyotoCabinet::kcdbemsg(@kc_db_pointer)
    end

    def last_error
      SystemCallError.new(last_error_message, last_error_code)<commit_msg>rename prefix without trailing hyphen<commit_after>require_relative '../libkyotocabinet_ffi'

module KyotoCabinet

  # in-memory (or prototype) database types
  MEMORY_HASH       = :-
  MEMORY_TREE       = :+
  MEMORY_STASH      = :':'
  MEMORY_CACHE_HASH = :*
  MEMORY_CACHE_TREE = :%

  # on-disk database types
  FILE_HASH         = :".kch"
  FILE_TREE         = :".kct"
  FILE_PLAIN_TEXT   = :".kcx"
  DIR_HASH          = :".kcd"
  DIR_TREE          = :".kcf"

  MEMORY_DB_TYPE = [
    MEMORY_HASH,
    MEMORY_TREE,
    MEMORY_STASH,
    MEMORY_CACHE_HASH,
    MEMORY_CACHE_TREE
  ]

  FILE_DB_TYPE = [
    FILE_HASH,
    FILE_TREE,
    FILE_PLAIN_TEXT,
    DIR_HASH,
    DIR_TREE
  ]

  DEFAULT_TEMP_PREFIX = 'kyoto-db'

  def self.match_memorydb_type? value
    return false unless value
    value_s = value.to_s
    MEMORY_DB_TYPE.any? { |ext| value_s == ext.to_s }
  end

  def self.match_filedb_type? value
    return false unless value
    value_s = value.to_s
    FILE_DB_TYPE.any? { |ext| value_s.end_with? ext.to_s }
  end

  module Db

    def new
      @kc_db_pointer = LibKyotoCabinet::kcdbnew
    end

    def last_error_code
      LibKyotoCabinet::kcdbecode(@kc_db_pointer)
    end

    def last_error_message
      LibKyotoCabinet::kcdbemsg(@kc_db_pointer)
    end

    def last_error
      SystemCallError.new(last_error_message, last_error_code)
{'fraction_non_alphanumeric': 0.08748615725359911, 'fraction_numerical': 0.0, 'mean_word_length': 2.6621621621621623, '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': '5233129', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1065, 'n_words': 179}