Comparing version 2.0.0 to 2.0.1
61
index.js
@@ -19,6 +19,9 @@ 'use strict' | ||
var fullfilter = makefilter(opts.filter) | ||
var offset = opts.offset || 0 | ||
var def = reverse ? over.count - 1 : 0 | ||
var offset = (typeof opts.offset !== 'undefined' ? opts.offset : def) | ||
var stack = [{obj: over}] | ||
// console.log('poing offset', offset) | ||
return { | ||
@@ -29,10 +32,18 @@ pushcount: 0, | ||
if (!stack[0].idx) { | ||
if (offset) { | ||
// console.log('poinglol', stack[0].obj.type, stack[0].idx) | ||
if (typeof stack[0].idx === 'undefined') { | ||
// console.log('poingset', offset) | ||
if (offset !== 'resolved') { | ||
var idxRest = stack[0].obj.offset(offset) | ||
// console.log('poing', offset, idxRest) | ||
stack[0].idx = idxRest[0] | ||
offset = idxRest[1] | ||
} else { | ||
stack[0].idx = reverse ? -1 : 0 | ||
// console.log('poing pappa') | ||
stack[0].idx = reverse ? stack[0].obj.children -1 : 0 | ||
} | ||
// console.log('poing ...', stack[0].idx) | ||
} | ||
@@ -60,3 +71,4 @@ | ||
} else { // leaf | ||
// console.log('leaf') | ||
offset = 'resolved' | ||
// console.log('poing leaf', element) | ||
reverse ? stack[0].idx-- : stack[0].idx++ | ||
@@ -98,2 +110,3 @@ cb(null, element) | ||
count: count, | ||
children: 1, | ||
hash: hash, | ||
@@ -125,3 +138,3 @@ append: function (el, cb) { | ||
if (idx === 0 || idx === -1) { | ||
if (idx === 0) { | ||
if (!subsetMatches(self.filters, filter.blooms)) { | ||
@@ -162,2 +175,3 @@ cb(null, null, SKIP) | ||
count: elements.length, | ||
children: elements.length, | ||
append: function (el, cb) { | ||
@@ -175,2 +189,3 @@ if (this.elements.length === BUCKET_SIZE) { | ||
offset: function (ofs) { | ||
// console.log('poing bucket ofs', ofs) | ||
return [ofs, 0] | ||
@@ -192,7 +207,2 @@ }, | ||
get: function (idx, filter, cb) { | ||
if (idx < 0) { | ||
idx += this.elements.length | ||
} | ||
var el = this.elements[idx] | ||
@@ -239,2 +249,3 @@ if (typeof el === 'undefined') return cb(null, null, EOF) | ||
}, 0), | ||
children: refs.length, | ||
append: function (el, cb) { | ||
@@ -263,5 +274,2 @@ if (this.refs.length === BUCKET_SIZE) { | ||
get: function (idx, filter, cb) { | ||
if (idx < 0) { | ||
idx += this.refs.length | ||
} | ||
var ref = this.refs[idx] | ||
@@ -328,2 +336,3 @@ if (ref) { | ||
count: head.count + rest.count + tail.count, | ||
children: 3, | ||
append: function (el, cb) { | ||
@@ -351,15 +360,5 @@ tail.append(el, function (err, newtail) { | ||
offset: function (ofs) { | ||
// console.log('finger ofs') | ||
// console.log(ofs) | ||
// if (ofs < 0) { | ||
// ofs += this.count | ||
// } | ||
// console.log(this.count) | ||
// console.log(ofs) | ||
// console.log('finger ofs poing', ofs) | ||
var idx = 0 | ||
if (this.head.count < ofs) { | ||
if (this.head.count <= ofs) { | ||
ofs -= this.head.count | ||
@@ -371,3 +370,3 @@ idx++ | ||
if (this.rest.count < ofs) { | ||
if (this.rest.count <= ofs) { | ||
ofs -= this.rest.count | ||
@@ -379,3 +378,3 @@ idx++ | ||
if (this.tail.count < ofs) { | ||
if (this.tail.count <= ofs) { | ||
ofs -= this.tail.count | ||
@@ -387,5 +386,5 @@ idx++ | ||
get: function (idx, filter, cb) { | ||
if (idx === 0 || idx === -3) return cb(null, head) | ||
if (idx === 1 || idx === -2) return cb(null, rest) | ||
if (idx === 2 || idx === -1) return cb(null, tail) | ||
if (idx === 0) return cb(null, head) | ||
if (idx === 1) return cb(null, rest) | ||
if (idx === 2) return cb(null, tail) | ||
cb(null, null, EOF) | ||
@@ -392,0 +391,0 @@ }, |
{ | ||
"name": "aolog", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Append only log", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -213,3 +213,3 @@ 'use strict' | ||
var SIZE = BUCKET_SIZE * 64 | ||
var SIZE = BUCKET_SIZE + 1 | ||
@@ -232,2 +232,3 @@ var log | ||
// helper | ||
@@ -267,2 +268,30 @@ function range (from, to) { | ||
}) | ||
SIZE = BUCKET_SIZE * 10 | ||
it('should take all from all offsets in reverse', function (done) { | ||
var count = 0 | ||
_.map(range(0, SIZE), function (ofs) { | ||
var iter = log.iterator({offset: ofs, reverse: true}) | ||
count++ | ||
iter.all(function (err, array) { | ||
if (err) throw err | ||
assert.deepEqual(array, reference.slice(0, ofs+1).reverse()) | ||
if (!--count) done() | ||
}) | ||
}) | ||
}) | ||
it('should take 1 from all offsets in reverse', function (done) { | ||
var count = 0 | ||
_.map(range(0, SIZE), function (ofs) { | ||
var iter = log.iterator({offset: ofs, reverse: true}) | ||
iter.next(function (err, res) { | ||
if (err) throw err | ||
assert.deepEqual(res, reference[ofs]) | ||
if (++count === SIZE) done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -430,3 +459,3 @@ | ||
var haystack = [] | ||
for (let i = 0 ; i < HAYSIZE ; i++) { | ||
for (var i = 0 ; i < HAYSIZE ; i++) { | ||
haystack.push({is: "haystrand #" + i}) | ||
@@ -433,0 +462,0 @@ } |
Sorry, the diff of this file is too big to display
758530
21773