<commit_before>//
//  DefaultValueRegistry.swift
//  Cuckoo
//
//  Created by <NAME> on 20/09/16.
//  Copyright © 2016 Brightify. All rights reserved.
//

public class DefaultValueRegistry {

    private static var registeredTypes: [ObjectIdentifier: Any] = [
        ObjectIdentifier(Void): Void(),
        ObjectIdentifier(Int): Int(),
        ObjectIdentifier(String): String(),
        ObjectIdentifier(Bool): Bool(),
        ObjectIdentifier(Double): Double(),
        ObjectIdentifier(Float): Float(),
    ]

    public static func register<T>(value: T, forType type: T.Type) {
        registeredTypes[ObjectIdentifier(type)] = value
    }

    public static func defaultValue<T>(type: Set<T>.Type) -> Set<T> {
        return []
    }

    public static func defaultValue<T>(type: Array<T>.Type) -> Array<T> {
        return []
    }

    public static func defaultValue<K, V>(type: Dictionary<K, V>.Type) -> Dictionary<K, V> {
        return [:]
    }

    public static func defaultValue<T>(type: Optional<T>.Type) -> Optional<T> {
        return nil
    }

    public static func defaultValue<T>(type: T.Type) -> T {
        if let registeredDefault: T = defaultValueOrNil(type) {
            return registeredDefault
        }
        fatalError("Type \(T.self) does not have default return value registered.")
    }

    public static func defaultValueOrNil<T>(type: T.Type) -> T? {
        return registeredTypes[ObjectIdentifier(type)] as? T
    }
}
<commit_msg>Allow overiding of the return for `Set`, `Array`, `Dictionary` and `Optional` using the `register` method.<commit_after>//
//  DefaultValueRegistry.swift
//  Cuckoo
//
//  Created by <NAME> on 20/09/16.
//  Copyright © 2016 Brightify. All rights reserved.
//

public class DefaultValueRegistry {

    private static var registeredTypes: [ObjectIdentifier: Any] = [
        ObjectIdentifier(Void): Void(),
        ObjectIdentifier(Int): Int(),
        ObjectIdentifier(String): String(),
        ObjectIdentifier(Bool): Bool(),
        ObjectIdentifier(Double): Double(),
        ObjectIdentifier(Float): Float(),
    ]

    public static func register<T>(value: T, forType type: T.Type) {
        registeredTypes[ObjectIdentifier(type)] = value
    }

    public static func defaultValue<T>(type: Set<T>.Type) -> Set<T> {
        return defaultValueOrNil(type) ?? []
    }

    public static func defaultValue<T>(type: Array<T>.Type) -> Array<T> {
        return defaultValueOrNil(type) ?? []
    }

    public static func defaultValue<K, V>(type: Dictionary<K, V>.Type) -> Dictionary<K, V> {
        return defaultValueOrNil(type) ?? [:]
    }

    public static func defaultValue<T>(type: Optional<T>.Type) -> Optional<T> {
        return defaultValueOrNil(type) ?? nil
    }

    public static func defaultValue<T>(type: T.Type) -> T {
        if let registeredDefault: T = defaultValueOrNil(type) {
            return registeredDefault
        }
        fatalError("Type \(T.self) does not have default return value registered.")
    }

    public static func defaultValueOrNil<T>(type: T.Type) -> T? {
        return registeredTypes[ObjectIdentifier(type)] as? T
    }
}

{'fraction_non_alphanumeric': 0.1317042208822596, 'fraction_numerical': 0.006347191367819739, 'mean_word_length': 2.891358024691358, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 47, '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': '5374483', 'n_tokens_mistral': 922, 'n_tokens_neox': 883, 'n_words': 238}