<commit_before>import Foundation

/// Joins bytes to form an integer.
///
/// - parameter data: The input data to unpack.
/// - parameter size: The size of the integer.
///
/// - returns: An integer representation of `size` bytes of data.
func unpackInteger(_ data: Data, count: Int) throws -> (value: UInt64, remainder: Data) {
    guard count > 0 else {
        throw MessagePackError.invalidArgument
    }

    guard data.count >= count else {
        throw MessagePackError.insufficientData
    }

    var value: UInt64 = 0
    for i in 0 ..< count {
        let byte = data[i]
        value = value << 8 | UInt64(byte)
    }

    return (value, data.subdata(in: count ..< data.count))
}

/// Joins bytes to form a string.
///
/// - parameter data: The input data to unpack.
/// - parameter length: The length of the string.
///
/// - returns: A string representation of `size` bytes of data.
func unpackString(_ data: Data, count: Int) throws -> (value: String, remainder: Data) {
    guard count > 0 else {
        return ("", data)
    }

    guard data.count >= count else {
        throw MessagePackError.insufficientData
    }


    let subdata = data.subdata(in: 0 ..< count)
    guard let result = String(data: subdata, encoding: .utf8) else {
        throw MessagePackError.invalidData
    }

    return (result, data.subdata(in: count ..< data.count))
}

/// Joins bytes to form a data object.
///
/// - parameter data: The input data to unpack.
/// - parameter length: The length of the data.
///
/// - returns: A subsection of data representing `size` bytes.
func unpackData(_ data: Data, count: Int) throws -> (value: Data, remainder: Data) {
    guard count > 0 else {
        throw MessagePackError.invalidArgument
    }

    guard data.count >= count else {
        throw MessagePackError.insufficientData
    }

    return (data.subdata(in: 0 ..< count), data.subdata(in: count ..< data.count))
}

/// Joins bytes to form an array of `MessagePackValue` values.
///
/// - parameter data: The input data to unpack.
/// - parameter count: The number of elements to unpack.
///
/// - returns: An array of `count` elements.
func unpackArray(_ data: Data, count: Int, compatibility: Bool) throws -> (value: [MessagePackValue], remainder: Data) {
    var values:[MessagePackValue] = []
    var newValue:MessagePackValue
    var remainder:Data = data
    for _ in 0 ..< count {
        (newValue, remainder) = try unpack(remainder, compatibility: compatibility)
        values.append(newValue)
    }
    return (values, remainder)
}

/// Joins bytes to form a dictionary with `MessagePackValue` key/value entries.
///
/// - parameter data: The input data to unpack.
/// - parameter count: The number of elements to unpack.
///
/// - returns: An dictionary of `count` entries.
func unpackMap(_ data: Data, count: Int, compatibility: Bool) throws -> (value: [MessagePackValue: MessagePackValue], remainder: Data) {
    var dict = [MessagePackValue: MessagePackValue](minimumCapacity: count)<commit_msg>Fix spacing<commit_after>import Foundation

/// Joins bytes to form an integer.
///
/// - parameter data: The input data to unpack.
/// - parameter size: The size of the integer.
///
/// - returns: An integer representation of `size` bytes of data.
func unpackInteger(_ data: Data, count: Int) throws -> (value: UInt64, remainder: Data) {
    guard count > 0 else {
        throw MessagePackError.invalidArgument
    }

    guard data.count >= count else {
        throw MessagePackError.insufficientData
    }

    var value: UInt64 = 0
    for i in 0 ..< count {
        let byte = data[i]
        value = value << 8 | UInt64(byte)
    }

    return (value, data.subdata(in: count ..< data.count))
}

/// Joins bytes to form a string.
///
/// - parameter data: The input data to unpack.
/// - parameter length: The length of the string.
///
/// - returns: A string representation of `size` bytes of data.
func unpackString(_ data: Data, count: Int) throws -> (value: String, remainder: Data) {
    guard count > 0 else {
        return ("", data)
    }

    guard data.count >= count else {
        throw MessagePackError.insufficientData
    }


    let subdata = data.subdata(in: 0 ..< count)
    guard let result = String(data: subdata, encoding: .utf8) else {
        throw MessagePackError.invalidData
    }

    return (result, data.subdata(in: count ..< data.count))
}

/// Joins bytes to form a data object.
///
/// - parameter data: The input data to unpack.
/// - parameter length: The length of the data.
///
/// - returns: A subsection of data representing `size` bytes.
func unpackData(_ data: Data, count: Int) throws -> (value: Data, remainder: Data) {
    guard count > 0 else {
        throw MessagePackError.invalidArgument
    }

    guard data.count >= count else {
        throw MessagePackError.insufficientData
    }

    return (data.subdata(in: 0 ..< count), data.subdata(in: count ..< data.count))
}

/// Joins bytes to form an array of `MessagePackValue` values.
///
/// - parameter data: The input data to unpack.
/// - parameter count: The number of elements to unpack.
///
/// - returns: An array of `count` elements.
func unpackArray(_ data: Data, count: Int, compatibility: Bool) throws -> (value: [MessagePackValue], remainder: Data) {
    var values = [MessagePackValue]())
    var remainder = data
    var newValue: MessagePackValue

    for _ in 0 ..< count {
        (newValue, remainder) = try unpack(remainder, compatibility: compatibility)
        values.append(newValue)
    }

    return (values, remainder)
}

/// Joins bytes to form a dictionary with `MessagePackValue` key/value entries.
///
/// - parameter data: The input data to unpack.
/// - parameter count: The number of elements to unpack.
///
/// - returns: An dictionary of `count` entries.
func unpackMap(_ data: Data, count: Int, compatibility: Bool) throws -> (value: [MessagePackValue: MessagePackValue], remainder: Data) {
    var dict = [MessagePackValue: MessagePackValue](minimumCapacity: count)
{'fraction_non_alphanumeric': 0.12570574559946862, 'fraction_numerical': 0.005313849219528396, 'mean_word_length': 2.747977598008712, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, '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': '4205669', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1688, 'n_words': 642}