diff options
author | Martin Odersky <odersky@gmail.com> | 2009-09-25 16:20:13 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-09-25 16:20:13 +0000 |
commit | 4a727f3b01d0fa27ef51f7dba472116e021e3445 (patch) | |
tree | c9ab55ea7fe6051455271b23e9fbfc2f313015c0 /src/library/scala/collection/mutable/DoubleLinkedListLike.scala | |
parent | e31f18094dfba97c80871869a037172ff2c9c1c2 (diff) | |
download | scala-4a727f3b01d0fa27ef51f7dba472116e021e3445.tar.gz scala-4a727f3b01d0fa27ef51f7dba472116e021e3445.tar.bz2 scala-4a727f3b01d0fa27ef51f7dba472116e021e3445.zip |
Collections refactoring.
Diffstat (limited to 'src/library/scala/collection/mutable/DoubleLinkedListLike.scala')
-rw-r--r-- | src/library/scala/collection/mutable/DoubleLinkedListLike.scala | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/library/scala/collection/mutable/DoubleLinkedListLike.scala b/src/library/scala/collection/mutable/DoubleLinkedListLike.scala new file mode 100644 index 0000000000..637d67396b --- /dev/null +++ b/src/library/scala/collection/mutable/DoubleLinkedListLike.scala @@ -0,0 +1,48 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + +package scala.collection +package mutable + +/** This extensible class may be used as a basis for implementing double + * linked lists. Type variable <code>A</code> refers to the element type + * of the list, type variable <code>This</code> is used to model self + * types of linked lists. + * + * @author Matthias Zenger + * @version 1.0, 08/07/2003 + */ +trait DoubleLinkedListLike[A, This >: Null <: LinearSequence[A] with DoubleLinkedListLike[A, This]] extends LinkedListLike[A, This] { self => + + var prev: This = _ + + override def append(that: This): Unit = + if (next eq null) { + next = that + if (that ne null) that.prev = repr + } else + next.append(that) + + override def insert(that: This): Unit = if (that ne null) { + that.append(next) + next = that + that.prev = repr + } + + def remove() { + if (next ne null) + next.prev = prev + if (prev ne null) + prev.next = next + prev = null + next = null + } +} |