<commit_before>
require 'ffi'

module LibMemcachedFFI
  module Lib
    extend FFI::Library

    #
    # find lib

    paths = Array(ENV['LIBMEMCACHED_LIB'] || %w{
      /opt/local/lib/libmemcached.dylib
      /usr/local/lib/libmemcached.dylib
      /usr/local/lib/libmemcached.so
    })

    paths.each do |path|
      begin
        ffi_lib(paths.find { |path| File.exist?(path) })
      rescue LoadError => ex
        ffi_lib("memcached")
      end
    end

  end
end

require 'libmemcached-ffi/types'
require 'libmemcached-ffi/structs'

module LibMemcachedFFI
  module Lib

    # BASIC

    # const char * memcached_lib_version(void)
    attach_function :memcached_lib_version, [ ], :string

    # memcached_return_t memcached_version(memcached_st *ptr)
    attach_function :memcached_version, [ :pointer ], MemcachedReturnT

    # memcached_st *memcached(const char *string, size_t string_length)
    attach_function :memcached, [ :string, :size_t ], :pointer

    # void memcached_free(memcached_st *ptr)
    attach_function :memcached_free, [ :pointer ], :void

    # const char *memcached_last_error_message(memcached_st *)
    attach_function :memcached_last_error_message, [ :pointer ], :string


    # RETRIEVAL

    # char * memcached_get(memcached_st *ptr, const char *key, size_t key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error)
    attach_function :memcached_get, [ :pointer, :string, :size_t, :pointer, :pointer, :pointer ], :string

    # memcached_return_t memcached_mget(memcached_st *ptr, const char * const *keys, const size_t *key_length, size_t number_of_keys)
    attach_function :memcached_mget, [ :pointer, :pointer, :pointer, :size_t ], MemcachedReturnT

    # memcached_result_st * memcached_fetch_result(memcached_st *ptr, memcached_result_st *result, memcached_return_t *error)
    attach_function :memcached_fetch_result, [ :pointer, :pointer, :pointer ], :pointer # MemcachedResultSt

    # const char * memcached_result_key_value(memcached_result_st *result)
    attach_function :memcached_result_key_value, [ :pointer ], :string

    # const char *memcached_result_value(memcached_result_st *ptr)
    attach_function :memcached_result_value, [ :pointer ], :string

    # uint32_t memcached_result_flags(const memcached_result_st *result)
    attach_function :memcached_result_flags, [ :pointer ], :uint32


    # STORAGE

    # memcached_return_t memcached_set(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
    attach_function :memcached_set, [ :pointer, :string, :size_t, :string, :size_t, :time_t, :uint32 ], MemcachedReturnT

    # memcached_return_t memcached_add(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
    attach_function :memcached_add, [ :pointer, :string, :size_t, :string, :size_t, :time_t, :uint32 ], MemcachedReturnT

    # memcached_return_t memcached_replace(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
    attach_function :memcached_replace, [ :pointer, :string, :size_t, :string, :size_t, :time_t, :uint32 ], MemcachedReturnT


    # COUNTERS

    # memcached_return_t memcached_increment(memcached_st *ptr, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
    attach_function :memcached_increment, [ :pointer, :string, :size_t, :uint32, :pointer ], MemcachedReturnT

    # memcached_return_t memcached_decrement(memcached_st *ptr, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
    attach_function :memcached_decrement, [ :pointer, :string, :size_t, :uint32, :pointer ], MemcachedReturnT


    # MISC

    # memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration)
    attach_function :memcached_flush, [ :pointer, :time_t ], MemcachedReturnT

    # memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length, time_t expiration)
    attach_function :memcached_delete, [ :pointer, :string, :size_t, :time_t ], MemcachedReturnT

    # memcached_return_t memcached_exist(memcached_st *ptr, char *key, size_t *key_length)
    attach_function :memcached_exist, [ :pointer, :string, :size_t ], MemcachedReturnT

  end

end
<commit_msg>added cas method<commit_after>
require 'ffi'

module LibMemcachedFFI
  module Lib
    extend FFI::Library

    #
    # find lib

    paths = Array(ENV['LIBMEMCACHED_LIB'] || %w{
      /opt/local/lib/libmemcached.dylib
      /usr/local/lib/libmemcached.dylib
      /usr/local/lib/libmemcached.so
    })

    paths.each do |path|
      begin
        ffi_lib(paths.find { |path| File.exist?(path) })
      rescue LoadError => ex
        ffi_lib("memcached")
      end
    end

  end
end

require 'libmemcached-ffi/types'
require 'libmemcached-ffi/structs'

module LibMemcachedFFI
  module Lib

    # BASIC

    # const char * memcached_lib_version(void)
    attach_function :memcached_lib_version, [ ], :string

    # memcached_return_t memcached_version(memcached_st *ptr)
    attach_function :memcached_version, [ :pointer ], MemcachedReturnT

    # memcached_st *memcached(const char *string, size_t string_length)
    attach_function :memcached, [ :string, :size_t ], :pointer

    # void memcached_free(memcached_st *ptr)
    attach_function :memcached_free, [ :pointer ], :void

    # const char *memcached_last_error_message(memcached_st *)
    attach_function :memcached_last_error_message, [ :pointer ], :string


    # RETRIEVAL

    # char * memcached_get(memcached_st *ptr, const char *key, size_t key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error)
    attach_function :memcached_get, [ :pointer, :string, :size_t, :pointer, :pointer, :pointer ], :string

    # memcached_return_t memcached_mget(memcached_st *ptr, const char * const *keys, const size_t *key_length, size_t number_of_keys)
    attach_function :memcached_mget, [ :pointer, :pointer, :pointer, :size_t ], MemcachedReturnT

    # memcached_result_st * memcached_fetch_result(memcached_st *ptr, memcached_result_st *result, memcached_return_t *error)
    attach_function :memcached_fetch_result, [ :pointer, :pointer, :pointer ], :pointer # MemcachedResultSt

    # const char * memcached_result_key_value(memcached_result_st *result)
    attach_function :memcached_result_key_value, [ :pointer ], :string

    # const char *memcached_result_value(memcached_result_st *ptr)
    attach_function :memcached_result_value, [ :pointer ], :string

    # uint32_t memcached_result_flags(const memcached_result_st *result)
    attach_function :memcached_result_flags, [ :pointer ], :uint32


    # STORAGE

    # memcached_return_t memcached_set(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
    attach_function :memcached_set, [ :pointer, :string, :size_t, :string, :size_t, :time_t, :uint32 ], MemcachedReturnT

    # memcached_return_t memcached_add(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
    attach_function :memcached_add, [ :pointer, :string, :size_t, :string, :size_t, :time_t, :uint32 ], MemcachedReturnT

    # memcached_return_t memcached_replace(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
    attach_function :memcached_replace, [ :pointer, :string, :size_t, :string, :size_t, :time_t, :uint32 ], MemcachedReturnT

    # memcached_return_t memcached_cas(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags, uint64_t cas)
    attach_function :memcached_cas, [ :pointer, :string, :size_t, :string, :size_t, :time_t, :uint32, :uint32 ], MemcachedReturnT



    # COUNTERS

    # memcached_return_t memcached_increment(memcached_st *ptr, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
    attach_function :memcached_increment, [ :pointer, :string, :size_t, :uint32, :pointer ], MemcachedReturnT

    # memcached_return_t memcached_decrement(memcached_st *ptr, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
    attach_function :memcached_decrement, [ :pointer, :string, :size_t, :uint32, :pointer ], MemcachedReturnT


    # MISC

    # memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration)
    attach_function :memcached_flush, [ :pointer, :time_t ], MemcachedReturnT

    # memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length, time_t expiration)
    attach_function :memcached_delete, [ :pointer, :string, :size_t, :time_t ], MemcachedReturnT

    # memcached_return_t memcached_exist(memcached_st *ptr, char *key, size_t *key_length)
    attach_function :memcached_exist, [ :pointer, :string, :size_t ], MemcachedReturnT

  end

end

{'fraction_non_alphanumeric': 0.0977418640690724, 'fraction_numerical': 0.00752711976975869, 'mean_word_length': 5.063758389261745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '330681', 'n_tokens_mistral': 3120, 'n_tokens_neox': 3006, 'n_words': 684}