elements with start entry;
authorwenzelm
Sun, 10 Jan 2010 23:43:25 +0100
changeset 34304 b32c68328d24
parent 34303 98425e77cfeb
child 34310 a3d66403f9c9
elements with start entry;
src/Pure/General/linear_set.scala
--- a/src/Pure/General/linear_set.scala	Sun Jan 10 23:16:26 2010 +0100
+++ b/src/Pure/General/linear_set.scala	Sun Jan 10 23:43:25 2010 +0100
@@ -118,8 +118,11 @@
   override def isEmpty: Boolean = !rep.first.isDefined
   def size: Int = if (isEmpty) 0 else rep.nexts.size + 1
 
-  def elements: Iterator[A] = new Iterator[A] {
-    private var next_elem = rep.first
+  def contains(elem: A): Boolean =
+    !isEmpty && (rep.last.get == elem || rep.nexts.isDefinedAt(elem))
+
+  private def elements_from(start: Option[A]): Iterator[A] = new Iterator[A] {
+    private var next_elem = start
     def hasNext = next_elem.isDefined
     def next =
       next_elem match {
@@ -130,8 +133,11 @@
       }
   }
 
-  def contains(elem: A): Boolean =
-    !isEmpty && (rep.last.get == elem || rep.nexts.isDefinedAt(elem))
+  def elements: Iterator[A] = elements_from(rep.first)
+
+  def elements(elem: A): Iterator[A] =
+    if (contains(elem)) elements_from(Some(elem))
+    else throw new Linear_Set.Undefined(elem.toString)
 
   def + (elem: A): Linear_Set[A] = insert_after(rep.last, elem)