<commit_before>from __future__ import unicode_literals
import codecs

from libc.string cimport memcpy
from murmurhash.mrmr cimport hash64

from cpython cimport PyUnicode_AS_DATA
from cpython cimport PyUnicode_GET_DATA_SIZE

from libc.stdint cimport int64_t


from .typedefs cimport hash_t, attr_t

try:
    import codecs as io
except ImportError:
    import io

try:
    import ujson as json
except ImportError:
    import json


cpdef hash_t hash_string(unicode string) except 0:
    # This has to be like this for
    chars = <char*>PyUnicode_AS_DATA(string)
    size = PyUnicode_GET_DATA_SIZE(string)
    return hash64(chars, size, 1)


cdef unicode _decode(const Utf8Str* string):
    cdef int i, length
    if string.s[0] < sizeof(string.s) and string.s[0] != 0:
        return string.s[1:string.s[0]+1].decode('utf8')<commit_msg>* Enforce import of ujson in strings.pyx, because otherwise it's too slow<commit_after>from __future__ import unicode_literals
import codecs

from libc.string cimport memcpy
from murmurhash.mrmr cimport hash64

from cpython cimport PyUnicode_AS_DATA
from cpython cimport PyUnicode_GET_DATA_SIZE

from libc.stdint cimport int64_t


from .typedefs cimport hash_t, attr_t

try:
    import codecs as io
except ImportError:
    import io

import ujson as json


cpdef hash_t hash_string(unicode string) except 0:
    # This has to be like this for
    chars = <char*>PyUnicode_AS_DATA(string)
    size = PyUnicode_GET_DATA_SIZE(string)
    return hash64(chars, size, 1)


cdef unicode _decode(const Utf8Str* string):
    cdef int i, length
    if string.s[0] < sizeof(string.s) and string.s[0] != 0:
        return string.s[1:string.s[0]+1].decode('utf8')
{'fraction_non_alphanumeric': 0.07240356083086054, 'fraction_numerical': 0.018991097922848664, 'mean_word_length': 4.26875, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3901913', 'n_tokens_mistral': 600, 'n_tokens_neox': 575, 'n_words': 179}