Skip to content

Commit

Permalink
Make .length O(1) by using the global item count
Browse files Browse the repository at this point in the history
  • Loading branch information
erayd committed Sep 8, 2016
1 parent 0dbc8e1 commit 8dc62f7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spique",
"version": "1.0.2",
"version": "1.0.3",
"description": "A spiral deque - high performance and dynamic queue size",
"main": "spique.js",
"scripts": {
Expand Down
5 changes: 1 addition & 4 deletions spique.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ function Spique(maxItems, circumference) {

// get the number of items in the buffer
Object.defineProperty(this, 'length', {get: function() {
var length = 0;
for(var r = firstRing; r; r = r.nextRing)
length += r.length;
return length;
return items;
}});

// get the current capacity
Expand Down

0 comments on commit 8dc62f7

Please sign in to comment.