summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-05-11 14:52:06 +0000
committerburaq <buraq@epfl.ch>2004-05-11 14:52:06 +0000
commitb85cbeed4fb09e151d1ae330a9d21173eef0193b (patch)
tree053ab0effba4ee17320aa9c3cae7c18e0d63b810 /sources
parent1bca8c5072f77b344d94ac70e93e65af84136af2 (diff)
downloadscala-b85cbeed4fb09e151d1ae330a9d21173eef0193b.tar.gz
scala-b85cbeed4fb09e151d1ae330a9d21173eef0193b.tar.bz2
scala-b85cbeed4fb09e151d1ae330a9d21173eef0193b.zip
obsol
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/collection/mutable/AppendBuffer.scala85
1 files changed, 0 insertions, 85 deletions
diff --git a/sources/scala/collection/mutable/AppendBuffer.scala b/sources/scala/collection/mutable/AppendBuffer.scala
deleted file mode 100644
index 937a151f16..0000000000
--- a/sources/scala/collection/mutable/AppendBuffer.scala
+++ /dev/null
@@ -1,85 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2004, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-** $Id$
-\* */
-
-package scala.collection.mutable;
-
-/** 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] ] {
- def append( e: Option[A] ) = appendElem( e );
- }
- private val elemList = new MyElemList();
-
- class MySeqList extends MutableList[ Seq[A] ] {
- def append( seq:Seq[A] ) = appendElem( seq );
- }
- private val seqList = new MySeqList();
-
- def append( as:Seq[A] ) = {
- if( as.length > 0 ) {
- elemList.append( None );
- seqList.append( as );
- this.len = this.len + as.length;
- }
- }
-
- def append( a:A ) = {
- elemList.append( Some( a ) );
- this.len = this.len + 1;
- }
-
- def length = this.len;
-
- def apply( i:int ) = {
- val el = this.elements;
- var j = 0;
- while( j < i ) {
- j = j + 1;
- el.next;
- }
- 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 || 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
- }
- }
- }
- }
- }
-}