summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-03-26 08:30:02 +0000
committerburaq <buraq@epfl.ch>2004-03-26 08:30:02 +0000
commit3657ec24dfe65480a62b693853a75e7565633f67 (patch)
treed061a07933d972b02d6533b539fca5a0fcfd235c
parentcf4fd3eeea95ed3e1021d2f4819e4a55efaa9ba5 (diff)
downloadscala-3657ec24dfe65480a62b693853a75e7565633f67.tar.gz
scala-3657ec24dfe65480a62b693853a75e7565633f67.tar.bz2
scala-3657ec24dfe65480a62b693853a75e7565633f67.zip
bugfix
-rw-r--r--sources/scala/collection/mutable/AppendBuffer.scala57
-rw-r--r--test/files/run/xmlParsing_servlet.check6
-rw-r--r--test/files/run/xmlParsing_servlet.scala2
3 files changed, 38 insertions, 27 deletions
diff --git a/sources/scala/collection/mutable/AppendBuffer.scala b/sources/scala/collection/mutable/AppendBuffer.scala
index 9d83cf5bb3..937a151f16 100644
--- a/sources/scala/collection/mutable/AppendBuffer.scala
+++ b/sources/scala/collection/mutable/AppendBuffer.scala
@@ -9,16 +9,16 @@
package scala.collection.mutable;
-/** This class allows appending of elements and sequences in O(1), in contrast
- * to buffer, which adds sequences in O(k) where k is the length of the sequence.
- * However, random access costs O(n), so this data structure should only be used
- * if no modifications and no access is required, i.e. construction of sequences
- * out of subsequences.
- *
- * @author Burak Emir
- */
+/** This class allows appending of elements and sequences in O(1), provided
+* that the length method is O(1). This is in contrast to buffer, which adds
+* sequences in O(k) where k is the length of the sequence. However, random
+* access to AppendBuffer costs O(k), so this data structure
+* should only be used if no modifications and no access is required, i.e.
+* construction of sequences out of subsequences.
+*
+* @author Burak Emir
+*/
final class AppendBuffer[ A ] with Seq[ A ] {
-
private var len = 0;
class MyElemList extends MutableList[ Option[A] ] {
@@ -56,23 +56,30 @@ final class AppendBuffer[ A ] with Seq[ A ] {
el.next
}
- def elements = new Iterator[A] {
- val itEl = AppendBuffer.this.elemList.elements;
- val itSeq = AppendBuffer.this.seqList.elements;
- var curIt:Option[Iterator[A]] = None;
- def hasNext = itEl.hasNext || itSeq.hasNext;
- def next:A = curIt match {
- case None => itEl.next match {
- case Some( x ) => x
- case None => curIt = Some(itSeq.next.elements); next
- }
- case Some( z ) =>
- if( z.hasNext ) {
- z.next
- } else {
- curIt = None;
- next
+ def elements = {
+ new Iterator[A] {
+ val itEl = AppendBuffer.this.elemList.elements;
+ val itSeq = AppendBuffer.this.seqList.elements;
+ var curIt:Option[Iterator[A]] = None;
+ def hasNext = itEl.hasNext || itSeq.hasNext || curIt.match {
+ case Some( z ) => z.hasNext
+ case None => false
+ };
+ def next:A = {
+ curIt match {
+ case None => itEl.next match {
+ case Some( x ) => x
+ case None => curIt = Some(itSeq.next.elements); next
+ }
+ case Some( z ) =>
+ if( z.hasNext ) {
+ z.next
+ } else {
+ curIt = None;
+ next
+ }
}
+ }
}
}
}
diff --git a/test/files/run/xmlParsing_servlet.check b/test/files/run/xmlParsing_servlet.check
index f716534829..ef35a97716 100644
--- a/test/files/run/xmlParsing_servlet.check
+++ b/test/files/run/xmlParsing_servlet.check
@@ -8,7 +8,11 @@
What follows is an example of modular formatting.
</p>
<p>
- <table align="center"><b>hallo</b></table>
+ <table align="center">
+ <tr>
+ <td color="#222255" bgcolor="#AAAAFF"><h1> message </h1></td>
+ </tr>
+ </table>
</p>
<hr></hr>
<p>
diff --git a/test/files/run/xmlParsing_servlet.scala b/test/files/run/xmlParsing_servlet.scala
index 50b641d394..d7416c824b 100644
--- a/test/files/run/xmlParsing_servlet.scala
+++ b/test/files/run/xmlParsing_servlet.scala
@@ -31,7 +31,7 @@ object Test {
/** applies beautify to every element in a sequence
*/
- def beautify( xs:Seq[Node] ):Seq[Node] = <b>hallo</b><i>Hwlt</i>;//xs.toList.map { beautify }
+ def beautify( xs:Seq[Node] ):Seq[Node] = xs.toList.map { beautify }
/** this is a recursive procedure that adds some attributes to the tree
*/