<commit_before>//
//  Stack.swift
//  Stack GetMin()
//
//  Created by <NAME> on 16/08/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public struct Stack<T> {
	
	public var isEmpty: Bool { return array.isEmpty }
	public var count: Int { return array.count }
	public var top: T? { return array.last }
	public var min: T? { return minimums.last }
	
	public mutating func push(_ value: T) {
		array.append(value)
		minimums.append(Swift.min(value, min ?? value))
	}
	
	public mutating func pop() -> T? {
		minimums.popLast()
		return array.popLast()
	}
	
	// MARK: - Private
	
	private var array = [T]()
	private var minimums = [T]()
	
}<commit_msg>Update comments for stack with getMin().<commit_after>//
//  Stack.swift
//  Stack based on two arrays.
//
//  Created by <NAME> on 16/08/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

// Stack based on two arrays.
public struct Stack<Element: Comparable> {
	// Returns true if stack is empty.
	// Complexity: O(1)
	public var isEmpty: Bool { return a.isEmpty }
	
	// Returns the count of elements.
	// Complexity: O(1)
	public var count: Int { return a.count }
	
	// Returns the top element of stack.
	// Complexity: O(1)
	public var top: Element? { return a.last }
	
	// Returns the minimum element.
	// CompComplexity: O(1)
	public var min: Element? { return mins.last }
	
	// Appends a new element to the top.
	// Complexity: O(1)
	public mutating func push(_ element: Element) {
		a.append(element)
		mins.append(Swift.min(element, min ?? element))
	}
	
	// Removes and returns the top element.
	// Complexity: O(1)
	public mutating func pop() -> Element? {
		mins.popLast()
		return a.popLast()
	}
	
	// This stack based on array.
	// Memory: O(n)
	private var a: [Element] = []
	
	// Additional array for minimums.
	// Memory: O(n)
	private var mins: [Element] = []
}
{'fraction_non_alphanumeric': 0.13800424628450106, 'fraction_numerical': 0.01592356687898089, 'mean_word_length': 2.894628099173554, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '5985808', 'n_tokens_mistral': 686, 'n_tokens_neox': 620, 'n_words': 217}