<commit_before>//
//  Private.swift
//  SwiftGraphics
//
//  Created by <NAME> on 9/17/14.
//  Copyright (c) 2014 schwa.io. All rights reserved.
//

import Foundation
import CoreGraphics

// Utility code that is used by SwiftGraphics but isn't intended to be used outside of this project

/**
 :example:
    let (a,b) = ordered(("B", "A"))
 */
func ordered <T:Comparable> (tuple:(T, T)) -> (T, T) {
    let (lhs, rhs) = tuple
    if lhs <= rhs {
        return (lhs, rhs)
    }
    else {
        return (rhs, lhs)
    }
}


extension Array {
    init(count:Int, block:(Void) -> T) {
        self.init()
        for N in 0..<count {
            self.append(block())
        }
    }

    mutating func push(o:T) {
        append(o)
    }
    mutating func pop() -> T? {
        if let first = first {
            removeAtIndex(0)
            return first
        }
        return nil
    }
}



/**
 *  Generator that "walks" through another generator two elements at a time.
 */
struct SlidingWindow <T> : GeneratorType {
    typealias Element = (T, T?)

    var g : Array<T>.Generator
    var e : T?

    init(_ a:Array <T>) {
        g = a.generate()
        e = g.next()
    }

    mutating func next() -> Element? {
        if e == nil {
            return nil
        }

    let next = g.next()
    let result = (e!, next)
    e = next

    return result
    }
}

// MARK: Comparing

func compare <T:Comparable> (lhs:T, rhs:T) -> Int {
    return lhs == rhs ? 0 : (lhs > rhs ? 1 : -1)
}

// MARK: Associated Objects

public func getAssociatedObject(object:AnyObject, key: UnsafePointer<Void>) -> AnyObject? {
    return objc_getAssociatedObject(object, key)
}

public func setAssociatedObject(object:AnyObject, key: UnsafePointer<Void>, value:AnyObject) {
    objc_setAssociatedObject(object, key, value, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC))
}

@objc class StructWrapper {
    var wrapped:Any
    init(wrapped:Any) {
        self.wrapped = wrapped
    }
}

public func getAssociatedObject(object:AnyObject, key: UnsafePointer<Void>) -> Any? {
    let wrapper = objc_getAssociatedObject(object, key) as StructWrapper?
    if let wrapper = wrapper {
        return wrapper.wrapped
    }
    else {
        return nil
    }
}

public func setAssociatedObject(object:AnyObject, key: UnsafePointer<Void>, value:Any) {
    let wrapper = StructWrapper(wrapped:value)
    objc_setAssociatedObject(object, key, wrapper, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC))
}
<commit_msg>Adding TODO. Like a boss.<commit_after>//
//  Private.swift
//  SwiftGraphics
//
//  Created by <NAME> on 9/17/14.
//  Copyright (c) 2014 schwa.io. All rights reserved.
//

import Foundation
import CoreGraphics

// Utility code that is used by SwiftGraphics but isn't intended to be used outside of this project

/**
 :example:
    let (a,b) = ordered(("B", "A"))
 */
func ordered <T:Comparable> (tuple:(T, T)) -> (T, T) {
    let (lhs, rhs) = tuple
    if lhs <= rhs {
        return (lhs, rhs)
    }
    else {
        return (rhs, lhs)
    }
}


extension Array {
    init(count:Int, block:(Void) -> T) {
        self.init()
        for N in 0..<count {
            self.append(block())
        }
    }

    mutating func push(o:T) {
        append(o)
    }
    mutating func pop() -> T? {
        if let first = first {
            removeAtIndex(0)
            return first
        }
        return nil
    }
}



/**
 *  Generator that "walks" through another generator two elements at a time.
 */
struct SlidingWindow <T> : GeneratorType {
    typealias Element = (T, T?)

    var g : Array<T>.Generator
    var e : T?

    init(_ a:Array <T>) {
        g = a.generate()
        e = g.next()
    }

    mutating func next() -> Element? {
        if e == nil {
            return nil
        }

    let next = g.next()
    let result = (e!, next)
    e = next

    return result
    }
}

// MARK: Comparing

func compare <T:Comparable> (lhs:T, rhs:T) -> Int {
    return lhs == rhs ? 0 : (lhs > rhs ? 1 : -1)
}

// MARK: Associated Objects

public func getAssociatedObject(object:AnyObject, key: UnsafePointer<Void>) -> AnyObject? {
    return objc_getAssociatedObject(object, key)
}

public func setAssociatedObject(object:AnyObject, key: UnsafePointer<Void>, value:AnyObject) {
    objc_setAssociatedObject(object, key, value, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC))
}

// TODO: Rename ObjCBox?
@objc class StructWrapper {
    var wrapped:Any
    init(wrapped:Any) {
        self.wrapped = wrapped
    }
}

public func getAssociatedObject(object:AnyObject, key: UnsafePointer<Void>) -> Any? {
    let wrapper = objc_getAssociatedObject(object, key) as StructWrapper?
    if let wrapper = wrapper {
        return wrapper.wrapped
    }
    else {
        return nil
    }
}

public func setAssociatedObject(object:AnyObject, key: UnsafePointer<Void>, value:Any) {
    let wrapper = StructWrapper(wrapped:value)
    objc_setAssociatedObject(object, key, wrapper, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC))
}

{'fraction_non_alphanumeric': 0.12392219771405655, 'fraction_numerical': 0.005614597954682173, 'mean_word_length': 2.4711203897007654, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 39, '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': '7431145', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1650, 'n_words': 451}