Skip to content

Commit e811ece

Browse files
🤖 chore: Lint source files.
These changes were automatically generated by a transform whose code can be found at: - https://github.com/aureooms/rejuvenate/blob/3361c487f4a9437f3d4eeec1499bf8d09d1f5005/src/transforms/sources:initial-lint.js Please contact the author of the transform if you believe there was an error.
1 parent e7519a8 commit e811ece

File tree

9 files changed

+132
-169
lines changed

9 files changed

+132
-169
lines changed

doc/scripts/header.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
1-
var domReady = function(callback) {
2-
var state = document.readyState ;
3-
if ( state === 'interactive' || state === 'complete' ) {
4-
callback() ;
5-
}
6-
else {
1+
const domReady = function (callback) {
2+
const state = document.readyState;
3+
if (state === 'interactive' || state === 'complete') {
4+
callback();
5+
} else {
76
document.addEventListener('DOMContentLoaded', callback);
87
}
9-
} ;
10-
8+
};
119

12-
domReady(function(){
13-
14-
var projectname = document.createElement('a');
10+
domReady(() => {
11+
const projectname = document.createElement('a');
1512
projectname.classList.add('project-name');
1613
projectname.text = 'aureooms/js-pairing-heap';
17-
projectname.href = './index.html' ;
14+
projectname.href = './index.html';
1815

19-
var header = document.getElementsByTagName('header')[0] ;
20-
header.insertBefore(projectname,header.firstChild);
16+
const header = document.querySelectorAll('header')[0];
17+
header.insertBefore(projectname, header.firstChild);
2118

22-
var testlink = document.querySelector('header > a[data-ice="testLink"]') ;
23-
testlink.href = 'https://coveralls.io/github/aureooms/js-pairing-heap' ;
24-
testlink.target = '_BLANK' ;
19+
const testlink = document.querySelector('header > a[data-ice="testLink"]');
20+
testlink.href = 'https://coveralls.io/github/aureooms/js-pairing-heap';
21+
testlink.target = '_BLANK';
2522

26-
var searchBox = document.querySelector('.search-box');
27-
var input = document.querySelector('.search-input');
23+
const searchBox = document.querySelector('.search-box');
24+
const input = document.querySelector('.search-input');
2825

29-
// active search box when focus on searchBox.
30-
input.addEventListener('focus', function(){
26+
// Active search box when focus on searchBox.
27+
input.addEventListener('focus', () => {
3128
searchBox.classList.add('active');
3229
});
33-
3430
});

src/Node.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
21
export default class Node {
3-
4-
constructor ( value ) {
5-
this.value = value; // key
6-
this.prev = null; // pointer to previous sibling
7-
this.next = null; // pointer to next sibling
8-
this.children = new Beginning(); // pointer to children list
9-
// first child is this.children.next
2+
constructor(value) {
3+
this.value = value; // Key
4+
this.prev = null; // Pointer to previous sibling
5+
this.next = null; // Pointer to next sibling
6+
this.children = new Beginning(); // Pointer to children list
7+
// first child is this.children.next
108
}
11-
129
}
1310

1411
/**
1512
* Avoids if-then-else logic when manipulating child nodes
1613
*/
1714
export class Beginning {
18-
constructor () {
15+
constructor() {
1916
this.next = null;
2017
}
2118
}
2219

23-
//export class End {
24-
//constructor (prev) {
25-
//this.prev = prev;
26-
//}
27-
//}
20+
// Export class End {
21+
// constructor (prev) {
22+
// this.prev = prev;
23+
// }
24+
// }

src/PairingHeap.js

Lines changed: 52 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,50 @@
1-
import merge from "./merge.js" ;
2-
import mergepairs from "./mergepairs.js" ;
3-
import decreasekey from "./decreasekey.js" ;
4-
import Node from "./Node.js" ;
1+
import merge from './merge.js';
2+
import mergepairs from './mergepairs.js';
3+
import decreasekey from './decreasekey.js';
4+
import Node from './Node.js';
55

66
export default class PairingHeap {
7-
8-
constructor (compare) {
9-
this.compare = compare ; // comparison function
10-
this.min = null ; // root node, must have .prev = .next = null at all times
7+
constructor(compare) {
8+
this.compare = compare; // Comparison function
9+
this.min = null; // Root node, must have .prev = .next = null at all times
1110
}
1211

1312
/**
14-
* find-min: simply return the top element of the heap.
13+
* Find-min: simply return the top element of the heap.
1514
*/
16-
head () {
17-
if ( this.min === null ) return undefined;
15+
head() {
16+
if (this.min === null) return undefined;
1817
return this.min.value;
1918
}
2019

21-
22-
headreference () {
20+
headreference() {
2321
return this.min;
2422
}
2523

2624
/**
27-
* delete-min: remove the root and merge its subtrees. Various strategies
25+
* Delete-min: remove the root and merge its subtrees. Various strategies
2826
* are employed.
2927
*/
30-
pop () {
28+
pop() {
3129
const min = this.popreference();
32-
return min === null ? undefined : min.value ;
30+
return min === null ? undefined : min.value;
3331
}
3432

3533
/**
3634
*/
37-
popreference () {
38-
if (this.min === null ) return null;
35+
popreference() {
36+
if (this.min === null) return null;
3937
const min = this.min;
40-
this.min = mergepairs(this.compare, min.children); // min.children.next = null
38+
this.min = mergepairs(this.compare, min.children); // Min.children.next = null
4139
return min;
4240
}
4341

4442
/**
45-
* insert: create a new heap for the inserted element and merge into the
43+
* Insert: create a new heap for the inserted element and merge into the
4644
* original heap.
4745
*/
48-
push ( value ) {
49-
const node = new Node(value) ;
46+
push(value) {
47+
const node = new Node(value);
5048
return this.pushreference(node);
5149
}
5250

@@ -56,88 +54,81 @@ export default class PairingHeap {
5654
* PairingHeap#pushreference with an internal reference from this tree or
5755
* another, except the root of another tree.
5856
*/
59-
pushreference ( ref ) {
57+
pushreference(ref) {
6058
if (this.min === null) this.min = ref;
6159
else {
62-
// this.min != null != ref
63-
this.min = merge( this.compare , this.min , ref ) ;
60+
// This.min != null != ref
61+
this.min = merge(this.compare, this.min, ref);
6462
}
63+
6564
return ref;
6665
}
6766

68-
6967
/**
7068
* Supposes the same comparison function is used in both trees.
7169
* We can call pushreference since other.min.next = other.min.prev = null.
7270
*/
73-
merge ( other ) {
74-
const ref = other.min ;
75-
if (ref !== null) this.pushreference( ref ) ;
71+
merge(other) {
72+
const ref = other.min;
73+
if (ref !== null) this.pushreference(ref);
7674
}
7775

78-
7976
/**
8077
* @param {Node} ref Non-null internal node object.
8178
* @param {Object} value The new value for ref.
8279
*/
83-
update ( ref , value ) {
84-
85-
const d = this.compare(value, ref.value) ;
86-
87-
if ( d < 0 ) this.decreasekey(ref, value) ;
88-
else if ( d > 0 ) this.increasekey(ref, value) ;
89-
else ref.value = value ;
80+
update(ref, value) {
81+
const d = this.compare(value, ref.value);
9082

83+
if (d < 0) this.decreasekey(ref, value);
84+
else if (d > 0) this.increasekey(ref, value);
85+
else ref.value = value;
9186
}
9287

9388
/**
94-
* decrease-key
89+
* Decrease-key
9590
*
9691
* @param {Node} ref Non-null internal node object.
9792
* @param {Object} value The new value for ref.
9893
*/
99-
decreasekey ( ref , value ) {
100-
if (ref === this.min) ref.value = value ;
94+
decreasekey(ref, value) {
95+
if (ref === this.min) ref.value = value;
10196
else {
102-
// this.min != null, ref != null
103-
this.min = decreasekey( this.compare , this.min , ref , value ) ;
97+
// This.min != null, ref != null
98+
this.min = decreasekey(this.compare, this.min, ref, value);
10499
}
105100
}
106101

107102
/**
108-
* increase-key: remove the item at the key to be increased, replace
103+
* Increase-key: remove the item at the key to be increased, replace
109104
* the key with a larger key, then push the result back into the heap.
110105
*
111106
* @param {Node} ref Non-null internal node object.
112107
* @param {Object} value The new value for ref.
113108
*
114109
*/
115-
increasekey ( ref , value ) {
116-
110+
increasekey(ref, value) {
117111
this.delete(ref);
118112

119113
ref.value = value;
120114

121-
this.pushreference( ref ) ;
122-
115+
this.pushreference(ref);
123116
}
124117

125118
/**
126-
* ref must be internal
119+
* Ref must be internal
127120
* ref.prev and ref.next get reset to null
128121
*/
129-
delete ( ref ) {
130-
131-
if ( ref === this.min ) {
132-
this.popreference() ;
133-
return ;
122+
delete(ref) {
123+
if (ref === this.min) {
124+
this.popreference();
125+
return;
134126
}
135127

136-
const successor = mergepairs(this.compare, ref.children); // ref.children.next = null
128+
const successor = mergepairs(this.compare, ref.children); // Ref.children.next = null
137129

138130
// ref has no children
139131
if (successor === null) {
140-
141132
// _ _ _
142133
// | | --> | | --> | |
143134
// |_| <-- |_| <-- |_|
@@ -152,7 +143,7 @@ export default class PairingHeap {
152143
// - |_| <-/
153144
// R
154145
//
155-
ref.prev.next = ref.next ; // must be != null because ref != min
146+
ref.prev.next = ref.next; // Must be != null because ref != min
156147

157148
if (ref.next !== null) {
158149
//
@@ -164,7 +155,7 @@ export default class PairingHeap {
164155
// |----- |_|
165156
// R
166157
//
167-
ref.next.prev = ref.prev ;
158+
ref.next.prev = ref.prev;
168159
//
169160
// _ _
170161
// | | ----------> | |
@@ -189,20 +180,16 @@ export default class PairingHeap {
189180
ref.prev = null;
190181

191182
return;
192-
193183
}
194184

195-
successor.prev = ref.prev ; // must be != null because ref != min
196-
successor.prev.next = successor ;
185+
successor.prev = ref.prev; // Must be != null because ref != min
186+
successor.prev.next = successor;
197187
ref.prev = null;
198188

199189
if (ref.next !== null) {
200-
successor.next = ref.next ; // might be null
201-
successor.next.prev = successor ;
190+
successor.next = ref.next; // Might be null
191+
successor.next.prev = successor;
202192
ref.next = null;
203193
}
204-
205194
}
206-
207-
208195
}

src/decreasekey.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import merge from "./merge.js" ;
1+
import merge from './merge.js';
22

33
/**
4-
* decrease-key: remove the subtree rooted at the key to be decreased, replace
4+
* Decrease-key: remove the subtree rooted at the key to be decreased, replace
55
* the key with a smaller key, then merge the result back into the heap.
66
*
77
* @param {Function} compare Comparison function for keys.
@@ -10,22 +10,21 @@ import merge from "./merge.js" ;
1010
* @param {Object} value The new value for the key of the node to update.
1111
* @returns {Node} Returns the node containing the minimum key.
1212
*/
13-
export default function decreasekey ( compare , min , node , value ) {
13+
export default function decreasekey(compare, min, node, value) {
14+
// Update node's key
15+
node.value = value;
1416

15-
// update node's key
16-
node.value = value ;
17-
18-
// remove node from tree
19-
node.prev.next = node.next ; // by assumption node.prev != null
17+
// Remove node from tree
18+
node.prev.next = node.next; // By assumption node.prev != null
2019
if (node.next !== null) {
21-
node.next.prev = node.prev ;
22-
node.next = null ;
20+
node.next.prev = node.prev;
21+
node.next = null;
2322
}
24-
node.prev = null ;
2523

26-
// merge, remember we move the whole subtree with children
24+
node.prev = null;
25+
26+
// Merge, remember we move the whole subtree with children
2727
// node.prev = node.next = null at this point so safe to call merge
2828
// min != null and node != null
2929
return merge(compare, min, node);
30-
3130
}

src/index.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
import Node from "./Node.js" ;
2-
import PairingHeap from "./PairingHeap.js" ;
3-
import prepend from "./prepend.js" ;
4-
import decreasekey from "./decreasekey.js" ;
5-
import merge from "./merge.js" ;
6-
import mergepairs from "./mergepairs.js" ;
1+
import Node from './Node.js';
2+
import PairingHeap from './PairingHeap.js';
3+
import prepend from './prepend.js';
4+
import decreasekey from './decreasekey.js';
5+
import merge from './merge.js';
6+
import mergepairs from './mergepairs.js';
77

8-
export default PairingHeap ;
8+
export default PairingHeap;
99

10-
export {
11-
Node ,
12-
PairingHeap ,
13-
prepend ,
14-
decreasekey ,
15-
merge ,
16-
mergepairs ,
17-
} ;
10+
export {Node, PairingHeap, prepend, decreasekey, merge, mergepairs};

0 commit comments

Comments
 (0)