From dd812a2b2b391da41b82d533175b00152513d666 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 12 Nov 2015 15:20:51 -0500 Subject: [PATCH] =?UTF-8?q?Test=20that=20we=20aren=E2=80=99t=20at=20the=20?= =?UTF-8?q?`endIndex`=20instead=20of=20testing=20containment.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should be O(1) for all index types. --- prototype/Doubt/Matrix.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype/Doubt/Matrix.swift b/prototype/Doubt/Matrix.swift index 5537729bd..0f87ac294 100644 --- a/prototype/Doubt/Matrix.swift +++ b/prototype/Doubt/Matrix.swift @@ -14,7 +14,7 @@ public struct Matrix { private let values: [Memo] public subscript (i: I, j: I) -> Memo? { - guard across.contains(i) && down.contains(j) else { return nil } + guard i != across.endIndex && j != down.endIndex else { return nil } let i = across.startIndex.distanceTo(i) let j = down.startIndex.distanceTo(j) return values[Int((i + j * across.count).toIntMax())]