circular-buffer
Advanced tools
Comparing version 0.0.2 to 0.0.3
13
index.js
@@ -5,3 +5,4 @@ function CircularBuffer(capacity){ | ||
throw new TypeError("Invalid capacity"); | ||
var buffer=new Array(capacity),first=capacity-1,size=0; | ||
var buffer=new Array(capacity),first=capacity,size=0; | ||
this.size=function(){return size;}; | ||
@@ -31,5 +32,9 @@ this.capacity=function(){return capacity;}; | ||
var res=[],i; | ||
for(i=start;i<=end;i++)res.push(buffer[(first+i)%capacity]); | ||
return res; | ||
if(first+start>=capacity){ | ||
//make sure first+start and first+end are in a normal range | ||
start-=capacity; //becomes a negative number | ||
end-=capacity; | ||
} | ||
if(first+end<capacity)return buffer.slice(first+start,first+end+1); | ||
else return buffer.slice(first+start,capacity).concat(buffer.slice(0,first+end+1-capacity)); | ||
}; | ||
@@ -36,0 +41,0 @@ this.toarray=function(){ |
{ | ||
"name": "circular-buffer", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A NodeJS simple circular buffer implementation supporting indexing ", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.2.4", | ||
"chai": "^2.2.0" | ||
}, | ||
"repository": { | ||
@@ -10,0 +14,0 @@ "type": "git", |
@@ -47,1 +47,5 @@ # NodeJS Circular Buffer | ||
- Equivalent to `buf.get(0,buf.size() - 1)`: exports all items in the buffer in order. | ||
## Testing | ||
To test the package simply run `npm update && npm test` in the package's root folder. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
6156
5
105
1
51
2