Skip to content

Commit

Permalink
v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayMakhonin committed Jun 25, 2022
1 parent 5fc0171 commit a1d0841
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
21 changes: 14 additions & 7 deletions dist/bundle/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,21 @@ this._root=l(this._root,e,this._lessThanFunc))
get:function(){return null==this._root},
enumerable:!1,configurable:!0
}),e.prototype[Symbol.iterator]=function(){
var e=this._lessThanFunc;return function r(o){
return this._iterate(!1)
},e.prototype.nodes=function(){
return this._iterate(!0)
},e.prototype._iterate=function(e){
var r=this._lessThanFunc;return function o(l){
return t(this,(function(t){switch(t.label){case 0:
return o?[4,o.item]:[3,5];case 1:
return t.sent(),o.next?[5,n(r(o.next))]:[3,3]
;case 2:t.sent(),t.label=3;case 3:
return o.child?(o.child=i(o.child,e),[5,n(r(o.child))]):[3,5]
;case 4:t.sent(),t.label=5;case 5:return[2]}}))
}(this._root)},e}();function l(e,t,n){var r,o
return l?e?[4,l]:[3,2]:[3,8];case 1:
return t.sent(),[3,4];case 2:return[4,l.item]
;case 3:t.sent(),t.label=4;case 4:
return l.next?[5,n(o(l.next))]:[3,6];case 5:
t.sent(),t.label=6;case 6:
return l.child?(null!=l.child.next&&(l.child=i(l.child,r)),
[5,n(o(l.child))]):[3,8];case 7:t.sent(),t.label=8
;case 8:return[2]}}))}(this._root)},e}()
;function l(e,t,n){var r,o
;return null==e?t:null==t||e===t?e:(n(t.item,e.item)?(r=t,
o=e):(r=e,o=t),o.next=r.child,
null!=r.child&&(r.child.prev=o),o.prev=r,r.child=o,
Expand Down
17 changes: 15 additions & 2 deletions dist/lib/PairingHeap.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,28 @@ class PairingHeap {
return this._root == null;
}
[Symbol.iterator]() {
return this._iterate(false);
}
nodes() {
return this._iterate(true);
}
_iterate(nodes) {
const lessThanFunc = this._lessThanFunc;
function* iterate(node) {
if (node) {
yield node.item;
if (nodes) {
yield node;
}
else {
yield node.item;
}
if (node.next) {
yield* iterate(node.next);
}
if (node.child) {
node.child = collapse(node.child, lessThanFunc);
if (node.child.next != null) {
node.child = collapse(node.child, lessThanFunc);
}
yield* iterate(node.child);
}
}
Expand Down
4 changes: 3 additions & 1 deletion dist/lib/PairingHeap.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export declare class PairingHeap<TItem> {
* @return True if queue holds nothing, false otherwise
*/
get isEmpty(): boolean;
[Symbol.iterator](): any;
[Symbol.iterator](): Iterator<TItem, any, undefined>;
nodes(): Iterator<PairingNode<TItem>, any, undefined>;
private _iterate;
readonly merge: typeof merge;
readonly collapse: typeof collapse;
}
Expand Down
17 changes: 15 additions & 2 deletions dist/lib/PairingHeap.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,28 @@ class PairingHeap {
return this._root == null;
}
[Symbol.iterator]() {
return this._iterate(false);
}
nodes() {
return this._iterate(true);
}
_iterate(nodes) {
const lessThanFunc = this._lessThanFunc;
function* iterate(node) {
if (node) {
yield node.item;
if (nodes) {
yield node;
}
else {
yield node.item;
}
if (node.next) {
yield* iterate(node.next);
}
if (node.child) {
node.child = collapse(node.child, lessThanFunc);
if (node.child.next != null) {
node.child = collapse(node.child, lessThanFunc);
}
yield* iterate(node.child);
}
}
Expand Down

0 comments on commit a1d0841

Please sign in to comment.