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 Foundation | |
| func measure<T>(_ block: () -> T) -> T { | |
| let start = Date() | |
| let result = block() | |
| print("elapsed time: \(-start.timeIntervalSinceNow)") | |
| return result | |
| } | |
| extension Sequence { |
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
| struct RotatedCollection<Base: Collection> { | |
| let base: Base | |
| let index: Base.Index | |
| init(base: Base, shiftingToStart index: Base.Index) { | |
| self.base = base | |
| self.index = index | |
| } | |
| } |
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
| extension Collection { | |
| func split(between predicate: (Element, Element) throws -> Bool) rethrows -> [SubSequence] { | |
| guard !isEmpty else { return [] } | |
| var remainder = self[...] | |
| var slices: [SubSequence] = [] | |
| for ((_, left), (index, right)) in indexed().pairs() { | |
| if try predicate(left, right) { | |
| slices.append(remainder.remove(upTo: index)) |
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::cmp::Ordering; | |
| pub trait VecExt { | |
| type T; | |
| fn find_entry<F>(&mut self, f: F) -> Entry<'_, Self::T> | |
| where | |
| F: FnMut(&Self::T) -> bool; | |
| fn first_entry_where<F>(&mut self, f: F) -> Entry<'_, Self::T> |
OlderNewer