<commit_before>import Foundation

/// A collection of values, each associated with a case of an enum
public struct EnumMap<K: RawRepresentable, V where K.RawValue: Number> {
    public private(set) var values: [V]
    
    /// Initialize an instance of this struct with a closure resolving an enum case into a value
    public init(valueResolver: K -> V) {
        self.values = EnumIterator<K>.map() {
            return valueResolver($0)
        }
    }
    
    /// Initialize an empty instance of this struct with a default value that will be set for all enum members
    public init(_ defaultValue: V) {
        self.init(valueResolver: { K in
            return defaultValue
        })
    }
    
    /// Subscript support
    public subscript(key: K) -> V {
        get {
            return self.values[Int(key.rawValue)]
        }
        set {
            self.values[Int(key.rawValue)] = newValue
        }
    }
    
    /// Run a closure on each value of this map
    public func forEach(closure: (K, V) -> Void) {
        for i in 0..<self.values.count {
            closure(K(rawValue: K.RawValue(i))!, self.values[i])
        }
    }
}<commit_msg>EnumMap: Change storage to be a dictionary, to support non-0-indexed enums<commit_after>import Foundation

/// A collection of values, each associated with a case of an enum
public struct EnumMap<K: RawRepresentable, V where K.RawValue: Number, K: Hashable> {
    public private(set) var values: [K : V]
    
    /// Initialize an instance of this struct with a closure resolving an enum case into a value
    public init(valueResolver: K -> V) {
        self.values = EnumIterator<K>.map() {
            return valueResolver($0)
        }
    }
    
    /// Initialize an empty instance of this struct with a default value that will be set for all enum members
    public init(_ defaultValue: V) {
        self.init(valueResolver: { K in
            return defaultValue
        })
    }
    
    /// Subscript support
    public subscript(key: K) -> V {
        get {
            return self.values[key]!
        }
        set {
            self.values[key] = newValue
        }
    }
    
    /// Run a closure on each value of this map
    public func forEach(closure: (K, V) -> Void) {
        EnumIterator<K>.iterate() {
            closure($0, self.values[$0]!)
        }
    }
}
{'fraction_non_alphanumeric': 0.097997443544951, 'fraction_numerical': 0.0025564550489987218, 'mean_word_length': 2.00640204865557, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, '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': '4512149', 'n_tokens_mistral': 665, 'n_tokens_neox': 654, 'n_words': 235}