Skip to content
Browse files

minor

  • Loading branch information...
1 parent 5ee4f68 commit 43c0e98a10651d2b50e23543983103fe0f579f74 @polygonal committed Jul 8, 2013
Showing with 169 additions and 170 deletions.
  1. +55 −55 src/de/polygonal/ds/BST.hx
  2. +56 −56 src/de/polygonal/ds/Heap.hx
  3. +57 −57 src/de/polygonal/ds/PriorityQueue.hx
  4. +1 −2 src/de/polygonal/ds/error/Assert.hx
View
110 src/de/polygonal/ds/BST.hx
@@ -31,61 +31,6 @@ package de.polygonal.ds;
import de.polygonal.ds.error.Assert.assert;
-#if generic
-@:generic
-#end
-#if doc
-private
-#end
-class BSTIterator<T> implements de.polygonal.ds.Itr<T>
-{
- var _node:BinaryTreeNode<T>;
- var _stack:Array<BinaryTreeNode<T>>;
- var _top:Int;
- var _c:Int;
-
- public function new(node:BinaryTreeNode<T>)
- {
- _node = node;
- _stack = new Array<BinaryTreeNode<T>>();
- reset();
- }
-
- inline public function reset():Itr<T>
- {
- _stack[0] = _node;
- _top = 1;
- _c = 0;
- return this;
- }
-
- inline public function hasNext():Bool
- {
- return _top > 0;
- }
-
- inline public function next():T
- {
- var node = _stack[--_top];
- if (node.hasL())
- {
- _c++;
- _stack[_top++] = node.l;
- }
- if (node.hasR())
- {
- _c++;
- _stack[_top++] = node.r;
- }
- return node.val;
- }
-
- inline public function remove()
- {
- _top -= _c;
- }
-}
-
/**
* <p>A binary search tree (BST).</p>
* <p>A BST automatically arranges <em>BinaryTreeNode</em> objects so the resulting tree is a valid BST.</p>
@@ -483,4 +428,59 @@ class BST<T:Comparable<T>> implements Collection<T>
copy._size = _size;
return copy;
}
+}
+
+#if generic
+@:generic
+#end
+#if doc
+private
+#end
+class BSTIterator<T> implements de.polygonal.ds.Itr<T>
+{
+ var _node:BinaryTreeNode<T>;
+ var _stack:Array<BinaryTreeNode<T>>;
+ var _top:Int;
+ var _c:Int;
+
+ public function new(node:BinaryTreeNode<T>)
+ {
+ _node = node;
+ _stack = new Array<BinaryTreeNode<T>>();
+ reset();
+ }
+
+ inline public function reset():Itr<T>
+ {
+ _stack[0] = _node;
+ _top = 1;
+ _c = 0;
+ return this;
+ }
+
+ inline public function hasNext():Bool
+ {
+ return _top > 0;
+ }
+
+ inline public function next():T
+ {
+ var node = _stack[--_top];
+ if (node.hasL())
+ {
+ _c++;
+ _stack[_top++] = node.l;
+ }
+ if (node.hasR())
+ {
+ _c++;
+ _stack[_top++] = node.r;
+ }
+ return node.val;
+ }
+
+ inline public function remove()
+ {
+ _top -= _c;
+ }
}
View
112 src/de/polygonal/ds/Heap.hx
@@ -37,62 +37,6 @@ private typedef HeapFriend<T> =
private var _size:Int;
}
-#if doc
-private
-#end
-class HeapIterator<T:(Heapable<T>)> implements de.polygonal.ds.Itr<T>
-{
- var _f:Heap<T>;
- var _a:Array<T>;
- var _i:Int;
- var _s:Int;
-
- public function new(f:Heap<T>)
- {
- _f = f;
- _a = new Array<T>();
- _a[0] = null;
- reset();
- }
-
- public function free()
- {
- _a = null;
- }
-
- inline public function reset():Itr<T>
- {
- _s = _f.size() + 1;
- _i = 1;
- var a = __a(_f);
- for (i in 1..._s) _a[i] = a[i];
- return this;
- }
-
- inline public function hasNext():Bool
- {
- return _i < _s;
- }
-
- inline public function next():T
- {
- return _a[_i++];
- }
-
- inline public function remove()
- {
- #if debug
- assert(_i > 0, "call next() before removing an element");
- #end
- _f.remove(_a[_i - 1]);
- }
-
- inline function __a(f:HeapFriend<T>)
- {
- return f._a;
- }
-}
-
/**
* <p>A heap is a special kind of binary tree in which every node is greater than all of its children.</p>
* <p>The implementation is based on an arrayed binary tree.</p>
@@ -765,6 +709,62 @@ class Heap<T:(Heapable<T>)> implements Collection<T>
}
}
+#if doc
+private
+#end
+class HeapIterator<T:(Heapable<T>)> implements de.polygonal.ds.Itr<T>
+{
+ var _f:Heap<T>;
+ var _a:Array<T>;
+ var _i:Int;
+ var _s:Int;
+
+ public function new(f:Heap<T>)
+ {
+ _f = f;
+ _a = new Array<T>();
+ _a[0] = null;
+ reset();
+ }
+
+ public function free()
+ {
+ _a = null;
+ }
+
+ inline public function reset():Itr<T>
+ {
+ _s = _f.size() + 1;
+ _i = 1;
+ var a = __a(_f);
+ for (i in 1..._s) _a[i] = a[i];
+ return this;
+ }
+
+ inline public function hasNext():Bool
+ {
+ return _i < _s;
+ }
+
+ inline public function next():T
+ {
+ return _a[_i++];
+ }
+
+ inline public function remove()
+ {
+ #if debug
+ assert(_i > 0, "call next() before removing an element");
+ #end
+ _f.remove(_a[_i - 1]);
+ }
+
+ inline function __a(f:HeapFriend<T>)
+ {
+ return f._a;
+ }
+}
+
private class HeapElementWrapper<T:(Heapable<T>)> implements Heapable<HeapElementWrapper<T>>
{
public var position:Int;
View
114 src/de/polygonal/ds/PriorityQueue.hx
@@ -37,63 +37,6 @@ private typedef PriorityQueueFriend<T> =
private var _size:Int;
}
-#if doc
-private
-#end
-class PriorityQueueIterator<T:(Prioritizable)> implements de.polygonal.ds.Itr<T>
-{
- var _f:PriorityQueue<T>;
- var _a:Array<T>;
- var _i:Int;
- var _s:Int;
-
- public function new(f:PriorityQueue<T>)
- {
- _f = f;
- _a = new Array<T>();
- _a[0] = null;
- reset();
- }
-
- public function free()
- {
- _a = null;
- }
-
- inline public function reset():Itr<T>
- {
- _s = _f.size() + 1;
- _i = 1;
- var a = __a(_f);
- for (i in 1..._s) _a[i] = a[i];
- return this;
- }
-
- inline public function hasNext():Bool
- {
- return _i < _s;
- }
-
- inline public function next():T
- {
- return _a[_i++];
- }
-
- inline public function remove()
- {
- #if debug
- assert(_i > 0, "call next() before removing an element");
- #end
-
- _f.remove(_a[_i - 1]);
- }
-
- inline function __a(f:PriorityQueueFriend<T>)
- {
- return f._a;
- }
-}
-
/**
* <p>A priority queue is heap data structure with a simplified API for managing prioritized data.</p>
* Adds additional methods for removing and re-prioritizing elements.</p>
@@ -733,6 +676,63 @@ class PriorityQueue<T:(Prioritizable)> implements Queue<T>
}
}
+#if doc
+private
+#end
+class PriorityQueueIterator<T:(Prioritizable)> implements de.polygonal.ds.Itr<T>
+{
+ var _f:PriorityQueue<T>;
+ var _a:Array<T>;
+ var _i:Int;
+ var _s:Int;
+
+ public function new(f:PriorityQueue<T>)
+ {
+ _f = f;
+ _a = new Array<T>();
+ _a[0] = null;
+ reset();
+ }
+
+ public function free()
+ {
+ _a = null;
+ }
+
+ inline public function reset():Itr<T>
+ {
+ _s = _f.size() + 1;
+ _i = 1;
+ var a = __a(_f);
+ for (i in 1..._s) _a[i] = a[i];
+ return this;
+ }
+
+ inline public function hasNext():Bool
+ {
+ return _i < _s;
+ }
+
+ inline public function next():T
+ {
+ return _a[_i++];
+ }
+
+ inline public function remove()
+ {
+ #if debug
+ assert(_i > 0, "call next() before removing an element");
+ #end
+
+ _f.remove(_a[_i - 1]);
+ }
+
+ inline function __a(f:PriorityQueueFriend<T>)
+ {
+ return f._a;
+ }
+}
+
private class PQElementWrapper<T:(Prioritizable)> implements Prioritizable
{
public var priority:Float;
View
3 src/de/polygonal/ds/error/Assert.hx
@@ -38,10 +38,9 @@ class Assert
{
macro public static function assert(predicate:Expr, ?info:Expr):Expr
{
- if (!Context.defined("debug")) return {expr: EConst(CInt("0")), pos: Context.currentPos()};
+ if (!Context.defined("debug")) return macro {};
var error = false;
-
switch (Context.typeof(predicate))
{
case TAbstract(_, _):

0 comments on commit 43c0e98

Please sign in to comment.
Something went wrong with that request. Please try again.