Comparing version 1.2.0 to 1.2.1
@@ -218,8 +218,12 @@ /*! | ||
if (a.point > b.point) { return 1; } | ||
if (a.isOpen && !b.isOpen) { return -1; } | ||
if (!a.isOpen && b.isOpen) { return 1; } | ||
if (a.isStart && b.isStart) { return 0; } | ||
if (a.isEnd && b.isEnd) { return 0; } | ||
if (b.isEnd) {return -1;} | ||
if (a.isEnd) {return 1;} | ||
if (a.isStart && b.isEnd) { return -1; } | ||
if (a.isEnd && b.isStart) { return 1; } | ||
if (a.isStart) { | ||
if (a.isOpen && !b.isOpen) { return 1; } | ||
if (!a.isOpen && b.isOpen) { return -1; } | ||
} else { | ||
if (a.isOpen && !b.isOpen) { return -1; } | ||
if (!a.isOpen && b.isOpen) { return 1; } | ||
} | ||
return 0; | ||
@@ -248,2 +252,6 @@ } | ||
function isInfinite(value) { | ||
return value === Infinity || value === -Infinity; | ||
} | ||
Insection.prototype.getGaps = function () { | ||
@@ -305,3 +313,7 @@ var queryInterval = Insection.interval.apply(null, arguments); | ||
} else if (lastStart) { | ||
if (lastStart.point !== endPoint.point) { | ||
if ( | ||
lastStart.point !== endPoint.point || | ||
(!isInfinite(lastStart.point) && | ||
(!lastStart.isOpen || !endPoint.isOpen)) | ||
) { | ||
result.push(Insection.interval( | ||
@@ -308,0 +320,0 @@ lastStart.isOpen ? '(' : '[', |
@@ -197,8 +197,12 @@ var InvalidIntervalError = require('./InvalidIntervalError'); | ||
if (a.point > b.point) { return 1; } | ||
if (a.isOpen && !b.isOpen) { return -1; } | ||
if (!a.isOpen && b.isOpen) { return 1; } | ||
if (a.isStart && b.isStart) { return 0; } | ||
if (a.isEnd && b.isEnd) { return 0; } | ||
if (b.isEnd) {return -1;} | ||
if (a.isEnd) {return 1;} | ||
if (a.isStart && b.isEnd) { return -1; } | ||
if (a.isEnd && b.isStart) { return 1; } | ||
if (a.isStart) { | ||
if (a.isOpen && !b.isOpen) { return 1; } | ||
if (!a.isOpen && b.isOpen) { return -1; } | ||
} else { | ||
if (a.isOpen && !b.isOpen) { return -1; } | ||
if (!a.isOpen && b.isOpen) { return 1; } | ||
} | ||
return 0; | ||
@@ -227,2 +231,6 @@ } | ||
function isInfinite(value) { | ||
return value === Infinity || value === -Infinity; | ||
} | ||
Insection.prototype.getGaps = function () { | ||
@@ -284,3 +292,7 @@ var queryInterval = Insection.interval.apply(null, arguments); | ||
} else if (lastStart) { | ||
if (lastStart.point !== endPoint.point) { | ||
if ( | ||
lastStart.point !== endPoint.point || | ||
(!isInfinite(lastStart.point) && | ||
(!lastStart.isOpen || !endPoint.isOpen)) | ||
) { | ||
result.push(Insection.interval( | ||
@@ -287,0 +299,0 @@ lastStart.isOpen ? '(' : '[', |
{ | ||
"name": "insection", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A data structure for storing number intervals", | ||
@@ -5,0 +5,0 @@ "main": "lib/insection.js", |
@@ -158,3 +158,3 @@ # Insection | ||
Time complexity: `O(log(n*m))` where `n` is the number of intervals in | ||
Time complexity: `O(log(n)*m)` where `n` is the number of intervals in | ||
the data structure and `m` is the number of found intervals. | ||
@@ -197,3 +197,3 @@ | ||
Time complexity: `O(log(n*m))` where `n` is the number of intervals in | ||
Time complexity: `O(log(n)*m)` where `n` is the number of intervals in | ||
the data structure and `m` is the number of found intervals. | ||
@@ -223,2 +223,3 @@ | ||
``` | ||
### getEntries | ||
@@ -245,3 +246,3 @@ | ||
Time complexity: `O(log(n*m))` where `n` is the number of intervals in | ||
Time complexity: `O(log(n)*m)` where `n` is the number of intervals in | ||
the data structure and `m` is the number of found intervals. | ||
@@ -343,2 +344,39 @@ | ||
### getGaps | ||
Retrieves intervals for all gaps in the insection within a given interval. | ||
Signature: | ||
```js | ||
insection.getGaps(p) => insection.getGaps('[', p, p, ']'); | ||
insection.getGaps(start, end) => insection.getGaps('[', start, end, ']'); | ||
insection.getGaps('[', start, end, ']') => | ||
insection.getGaps(Insection.interval('[', start, end, ']')); | ||
insection.getGaps('[', start, end, ')') => | ||
insection.getGaps(Insection.interval('[', start, end, ')')); | ||
insection.getGaps('(', start, end, ']') => | ||
insection.getGaps(Insection.interval('(', start, end, ']')); | ||
insection.getGaps('(', start, end, ')') => | ||
insection.getGaps(Insection.interval('(', start, end, ')')); | ||
insection.getGaps(interval); | ||
``` | ||
Time complexity: `O(log(n)*m)` where `n` is the number of intervals in | ||
the data structure and `m` is the number of found intervals. | ||
Example: | ||
```js | ||
var insection = new Insection(); | ||
insection.add(0, 2, '0'); | ||
insection.add(3, 6, '1'); | ||
insection.add('[', 5, 7, ')', '2'); | ||
insection.add('(', 7, 8, ']', '3'); | ||
insection.add(9, 10, '4'); | ||
expect(insection.getGaps(0, 10).map(function (interval) { | ||
return interval.toString(); | ||
}).sort(), 'to equal', [ '(2;3)', '(8;9)', '[7;7]' ]); | ||
``` | ||
### interval | ||
@@ -345,0 +383,0 @@ |
@@ -490,10 +490,22 @@ var Insection = require('../lib/Insection.js'); | ||
it('returns an empty array if the insection contains no other gaps than points for the given interval', function () { | ||
it('returns an empty array if the insection contains no gaps for the given interval', function () { | ||
var insection = new Insection(); | ||
insection.add('(', 0, 3, ')', '0'); | ||
insection.add('(', 3, 6, ')', '1'); | ||
insection.add('(', 6, 9, ')', '2'); | ||
insection.add(0, 3, '0'); | ||
insection.add(3, 6, '1'); | ||
insection.add(6, 9, '2'); | ||
expect(insection.getGaps(0, 9), 'to be empty'); | ||
}); | ||
it('success the readme example', function () { | ||
var insection = new Insection(); | ||
insection.add(0, 2, '0'); | ||
insection.add(3, 6, '1'); | ||
insection.add('[', 5, 7, ')', '2'); | ||
insection.add('(', 7, 8, ']', '3'); | ||
insection.add(9, 10, '4'); | ||
expect(insection.getGaps(0, 10).map(function (interval) { | ||
return interval.toString(); | ||
}).sort(), 'to equal', [ '(2;3)', '(8;9)', '[7;7]' ]); | ||
}); | ||
}); | ||
}); |
108513
2168
424