Permalink
Browse files

Refactor: Both IPCNode.js and IDProvider.js now pass JSLint with onev…

…ar: true, undef: true
  • Loading branch information...
1 parent 798d66c commit fdbdaf5c889e1f7b32738525c784fb2f665abbf5 @Frans-Willem committed Aug 3, 2010
Showing with 415 additions and 343 deletions.
  1. +21 −16 IDProvider.js
  2. +394 −327 IPCNode.js
View
@@ -15,7 +15,7 @@ IDProvider.prototype.alloc=function() {
return first.from;
}
return first.from++;
-}
+};
/**
* Free an allocated ID for re-use.
@@ -24,21 +24,25 @@ IDProvider.prototype.alloc=function() {
*/
IDProvider.prototype.free=function(id) {
//Binary search
- var left=0;
- var right=this._free.length;
+ var left=0,
+ right=this._free.length,
+ mid,current,mergeleft,mergeright;
while (right>left) {
- var mid=Math.floor((left+right)/2);
- var current=this._free[mid];
- if (current.from>id) right=mid;
- else if (current.to<id) left=mid+1;
- else
+ mid=Math.floor((left+right)/2);
+ current=this._free[mid];
+ if (current.from>id) {
+ right=mid;
+ } else if (current.to<id) {
+ left=mid+1;
+ } else {
throw new Error("ID was already de-allocated");
+ }
}
//both left and right now contain the range just past our id.
//Set left to point to the one before, keep right just past
left--;
- var mergeleft=(left>=0 && this._free[left].to==id-1);
- var mergeright=(right<this._free.length && this._free[right].from==id+1);
+ mergeleft=(left>=0 && this._free[left].to==id-1);
+ mergeright=(right<this._free.length && this._free[right].from==id+1);
if (mergeleft && mergeright) {
//Merge two ranges into one new range
this._free[left].to=this._free[right].to;
@@ -51,17 +55,18 @@ IDProvider.prototype.free=function(id) {
//Create new range inbetween
this._free.splice(right,0,{from:id,to:id});
}
-}
+};
IDProvider.prototype.used=function() {
- var total=0;
- var last=0;
- for (var i=0; i<this._free.length; i++) {
- var cur=this._free[i];
+ var total=0,
+ last=0,
+ i,cur;
+ for (i=0; i<this._free.length; i++) {
+ cur=this._free[i];
total+=cur.from - last;
last=cur.to+1;
}
return total;
-}
+};
exports.IDProvider=IDProvider;
Oops, something went wrong.

0 comments on commit fdbdaf5

Please sign in to comment.