trevnorris / cbuffer Goto Github PK
View Code? Open in Web Editor NEWJavaScript Circular Buffer
License: MIT License
JavaScript Circular Buffer
License: MIT License
Add rotateLeft()
and rotateRight()
to the API. Should be simple enough. Just move the pointers right/left by count.
Is there a way to get the total number of items in the buffer?
Also, I want to completely dump the buffer by calling .pop()
in iteration. Can I call .pop and then check the size until the size is zero?
The bower.json file may contain the main
property to prevent problems with build systems who need that.
The primary acting files necessary to use your package. While Bower does not directly use these files, they are listed with the commands bower list --json andbower list --paths, so they can be used by build tools.
I was trying to use this for backing a d3.js graph, and after a bit of debugging found that (to me) it looks like the semantics of .length
and .size
are the wrong way around. That is to say, for a "plain" JS Array
, .length
is (usually, except for some edge cases) the number of elements in the array, what is CBuffer.size
here.
For using CBuffer
as a "drop-in" replacement for a plain old Array
, exchanging these meanings might be helpful. What do you think?
I have a case where I fill the buffer and do some action only when it's full. Could you add a method or attribute to check whether the buffer is full? Or is there already such a thing that I overlooked?
Of course checking buffer.size == buffer.length
works too, but a more explicit helper method would be nice :)
var b = new CBuffer(10);
b.push(1, 2, 3, 4, 5);
b.rotateLeft();
b.sort();
b.toArray();
=> [1, 1, 2, 3, 4]
Seems the culprit is the use of shift
in rotateLeft
, which moves the start index but leaves the shifted item in the underlying array. Explicitly setting that array index to undefined seems to fix the above. Not sure if it would have other consequences.
Thanks for the implementation!
Consider implementation of a quicksort. This would be especially useful once Typed Array Views
and Buffers
are supported.
Beside avg() and sum() a median() function could be useful, too.
http://caseyjustus.com/finding-the-median-of-an-array-with-javascript
Hi, thanks for your useful class. I'm using it with the latest node (0.8.11)
With current version, it looks like 'fill' does not actually fill the entire buffer, but only the first value. For instance,
var cb = new CBuffer(10);
cb.fill(0);
Then,
console.log(cb.data)
or
console.log(cb.toArray())
show that only the first value was set to 0, the other values remain null.
{ start: 0,
size: 0,
overflow: false,
data: [ 0, , , , , , , , , ],
length: 10,
end: 9 }
If confirmed on your side, could you please explain how to get the expected behavior or fix the issue?
Cheers
"repository" : {
"type" : "git",
"url" : "https://github.com/trevnoris/cbuffer.git"
}
I believe you mistyped trevnoris
instead of correct trevnorris
.
When linking to your github page from https://npmjs.org/package/CBuffer you will get 404 this way.
I'm not sure how to do it but it would let it be used on sites like code pen easily.
https://github.com/cdnjs/cdnjs
Nice project. Could you maybe declare its license? Or did I just overlook it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.