From 45da711de31e53f4b9a6cb232a4f37bfd0352a87 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 2 May 2011 22:27:26 +0400 Subject: [PATCH] Test fixed --- .../examples/priorityqueues/BinaryHeap.jet | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/idea/testData/psi/examples/priorityqueues/BinaryHeap.jet b/idea/testData/psi/examples/priorityqueues/BinaryHeap.jet index 78e074cebdc..d7e5aaf8285 100644 --- a/idea/testData/psi/examples/priorityqueues/BinaryHeap.jet +++ b/idea/testData/psi/examples/priorityqueues/BinaryHeap.jet @@ -1,15 +1,32 @@ -class BinaryHeap(_data : IIterable, compare : Comparison = naturalOrder) : IPriorityQueue { - private val data : IMutableList = new ArrayList(_data) +class BinaryHeap : IPriorityQueue { + private val data : IMutableList + private val compare : Comparison + + this(data : IIterable, compare : Comparison = naturalOrder) { + this.compare = compare + this.data = ArrayList(data) +// siftDown(* this.data.size / 2 .. 0) - { for (val i in data.size / 2 .. 0) { siftDown(i) } + + } + + this(compare : Comparison) { + this.compare = compare + this.data = ArrayList() + } + + this() { + this.data = ArrayList() + Assert(T is IComparable) + this.comparator = naturalOrder } override fun extract() : T { if (this.isEmpty) - throw new UnderflowException() + throw UnderflowException() data.swap(0, data.lastIndex) data.remove(data.lastIndex) siftDown(0) @@ -73,17 +90,17 @@ class BinaryHeap(_data : IIterable, compare : Comparison = naturalOrder } private extension for T { - fun compareTo(other : T) : Int = compare(this, other) + [operator] fun compareTo(other : T) : Int = compare(this, other) } } -fun IMutableList.swap(a : Int, b : Int) { +fun IMutableList.swap(a : Int, b : Int) { val t = this[a] this[a] = this[b] this[b] = t } -val IList.lastIndex : Int +val IList.lastIndex : Int get() = this.size - 1