From: adam Date: Tue, 4 Mar 2008 04:06:40 +0000 (-0500) Subject: add FastSet.first() for quick access to the first element of a FastSet X-Git-Url: http://git.megacz.com/?p=sbp.git;a=commitdiff_plain;h=476b0f25eb4554febad2bbed314bb48a888400c5 add FastSet.first() for quick access to the first element of a FastSet darcs-hash:20080304040640-5007d-bb4ef3dcf9eba44ce411de64a2f5fb565787e660.gz --- diff --git a/src/edu/berkeley/sbp/util/FastSet.java b/src/edu/berkeley/sbp/util/FastSet.java index 4e289cd..581886e 100644 --- a/src/edu/berkeley/sbp/util/FastSet.java +++ b/src/edu/berkeley/sbp/util/FastSet.java @@ -22,6 +22,12 @@ public /*final*/ class FastSet implements Iterator, Iterable, Visitable return (T)array[i]; } + public T first() { + if (only != null) return only; + if (array != null) return (T)(array[0]); + return null; + } + public FastSet() { } public FastSet(T t) { only = t; } public FastSet(Set s) {