-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72b1553
commit adc2ba4
Showing
6 changed files
with
155 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
/** | ||
* IfQueue#peek only valid if IfQueue#empty is false. | ||
* IfQueue#shift only valid if IfQueue#empty is false. | ||
*/ | ||
|
||
var IfQueue = function ( ) { | ||
|
||
this.front = null ; | ||
this.back = null ; | ||
|
||
} ; | ||
|
||
IfQueue.prototype.empty = function ( ) { | ||
|
||
return this.front === null ; | ||
|
||
} ; | ||
|
||
/** | ||
* Only valid if IfQueue#empty is false. | ||
*/ | ||
|
||
IfQueue.prototype.peek = function ( ) { | ||
|
||
return this.front.value ; | ||
|
||
} ; | ||
|
||
IfQueue.prototype.push = function ( value ) { | ||
|
||
if ( this.front === null ) { | ||
|
||
this.front = this.back = new Node( value , null ) ; | ||
|
||
} | ||
|
||
else { | ||
|
||
this.back = this.back.next = new Node( value , null ) ; | ||
|
||
} | ||
|
||
} ; | ||
|
||
/** | ||
* Only valid if IfQueue#empty is false. | ||
*/ | ||
|
||
IfQueue.prototype.shift = function ( ) { | ||
|
||
var node ; | ||
|
||
node = this.front ; | ||
|
||
this.front = node.next ; | ||
|
||
// necessary for garbage collector | ||
|
||
if ( this.back === node ) this.back = null ; | ||
|
||
return node.value ; | ||
|
||
} ; | ||
|
||
exports.IfQueue = IfQueue ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters