This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{convert::TryFrom, process::Command}; | |
use kube::{config::Kubeconfig, Client, Config}; | |
#[derive(Debug, Default)] | |
pub struct TestEnv { | |
// Unique name. | |
name: String, | |
// Kubeconfig of the temporary cluster. | |
kubeconfig: Kubeconfig, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An implementation of [Smoothsort] algorithm invented by Edsger Dijkstra, | |
// which I didn't get until reading [Smoothsort Demystified] by Keith Schwarz. | |
// | |
// Some optimizations like the chained swaps and corner case elimination were | |
// derived from [smoothsort.c] by Martin Knoblauch Revuelta. | |
public func smoothsort<T : Comparable>(inout a: [T]) { | |
smoothsort(&a) { $0 < $1 } | |
} | |
public func smoothsort<T : Comparable>(inout a: [T], range: Range<Int>) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Vladimir Yaroslavskiy's Dual-pivot quick sort. | |
// Optimization based on [Dart implementation]. | |
public func dualPivotQuickSort<T : Comparable>(inout a: [T]) { | |
dualPivotQuickSort(&a) { $0 < $1 } | |
} | |
public func dualPivotQuickSort<T>(inout a: [T], isOrderedBefore: (T, T)->Bool) { | |
dualPivotQuickSort(&a, indices(a), isOrderedBefore) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Sorts 5 inputs by 7 comparisons. | |
/// Uses Minimum-Comparison Sorting Algorithm (H. B. Demuth, 1956). | |
func sort5<T : Comparable> | |
(inout a: T, inout b: T, inout c: T, inout d: T, inout e: T) | |
{ | |
// 1. Setup conditions. (3 comparisons) | |
// b → d | |
// ↑ ↑ a < b < d, c < d | |
// a c e | |
if b < a { (a, b) = (b, a) } // a < b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Darwin | |
// import Darwin.Mach.mach_time // (mach_timebase_info, mach_absolute_time) | |
// import Darwin.Mach.clock_types // (NSEC_PER_*) | |
public func timeBlockNSec(block: ()->()) -> Double { // in nanoseconds | |
var info = mach_timebase_info(numer: 0, denom: 0) | |
let kr = mach_timebase_info(&info) | |
if kr != KERN_SUCCESS { | |
fatalError("Initialization of `mach_timebase_info` failed with code \(kr).") | |
} | |
if info.denom == 0 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Flip | |
/// Flips the order of function arguments. | |
/// | |
/// :param: fn Function (A,B)→R | |
/// :returns: Function (B,A)→R | |
public func flip<A,B,R>(fn:(A,B)->R) -> (B,A)->R { | |
return {(b,a) in fn(a,b)} | |
} | |
/// Flips the order of function arguments. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
public func pipe<A,B,R>(a:(A)->B, b:(B)->R) -> (A)->R { | |
return {(x) in b(a(x))} | |
} | |
/// | |
public func pipe<A,B,C,R>(a:(A)->B, b:(B)->C, c:(C)->R) -> (A)->R { | |
return {(x) in c(b(a(x)))} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Compose | |
public func compose<T,A,B>(a:(B)->A, b:(T)->B) -> (T)->A { | |
return {(x) in a(b(x))} | |
} | |
public func compose<T,A,B,C>(a:(B)->A, b:(C)->B, c:(T)->C) -> (T)->A { | |
return {(x) in a(b(c(x)))} | |
} | |
public func compose<T,A,B,C,D>(a:(B)->A, b:(C)->B, c:(D)->C, d:(T)->D) -> (T)->A { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Adjoin | |
public func adjoin<T,A,B>(a:(T)->A, b:(T)->B) -> (T)->(A,B) { | |
return {(x) in (a(x), b(x))} | |
} | |
public func adjoin<T,A,B,C>(a:(T)->A, b:(T)->B, c:(T)->C) -> (T)->(A,B,C) { | |
return {(x) in (a(x), b(x), c(x))} | |
} | |
public func adjoin<T,A,B,C,D>(a:(T)->A, b:(T)->B, c:(T)->C, d:(T)->D) -> (T)->(A,B,C,D) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Curry | |
/// Currying for functions with 2 arguments. | |
/// | |
/// :param: fn A function with 2 arguments, (A,B)→R | |
/// :returns: A curried function (A)→(B)→R | |
public func curry<A,B,R>(fn:(A,B)->R) -> (A)->(B)->R { | |
return {a in {b in fn(a,b)}} | |
} | |
/// Currying for functions with 3 arguments. |
NewerOlder