Skip to content
Snippets Groups Projects
Commit 951a00c4 authored by Alexander Rose's avatar Alexander Rose
Browse files

fixed OrderedSet.areIntersecting

parent e3bd6e3b
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@ describe('ordered set', () => {
const singleton10 = OrderedSet.ofSingleton(10);
const range1_4 = OrderedSet.ofRange(1, 4);
const arr136 = OrderedSet.ofSortedArray([1, 3, 6]);
const arr12369 = OrderedSet.ofSortedArray([1, 2, 3, 6, 9]);
const iB = (s: number, e: number) => Interval.ofBounds(s, e);
......@@ -47,6 +48,14 @@ describe('ordered set', () => {
expect(OrderedSet.areIntersecting(empty, singleton10)).toBe(false);
expect(OrderedSet.areIntersecting(empty, range1_4)).toBe(false);
expect(OrderedSet.areIntersecting(empty, arr136)).toBe(false);
expect(OrderedSet.areIntersecting(Interval.ofRange(2, 3), arr12369)).toBe(true);
expect(OrderedSet.areIntersecting(Interval.ofRange(2, 6), arr12369)).toBe(true);
expect(OrderedSet.areIntersecting(Interval.ofRange(2, 8), arr12369)).toBe(true);
expect(OrderedSet.areIntersecting(Interval.ofRange(4, 8), arr12369)).toBe(true);
expect(OrderedSet.areIntersecting(Interval.ofRange(4, 5), arr12369)).toBe(false);
expect(OrderedSet.areIntersecting(Interval.ofRange(7, 8), arr12369)).toBe(false);
});
it('isSubset', () => {
......
......@@ -29,6 +29,8 @@ export function indexOf(set: OrderedSetImpl, x: number) { return I.is(set) ? I.i
export function getAt(set: OrderedSetImpl, i: number) { return I.is(set) ? I.getAt(set, i) : set[i]; }
export function min(set: OrderedSetImpl) { return I.is(set) ? I.min(set) : S.min(set); }
export function max(set: OrderedSetImpl) { return I.is(set) ? I.max(set) : S.max(set); }
export function start(set: OrderedSetImpl) { return I.is(set) ? I.start(set) : S.start(set); }
export function end(set: OrderedSetImpl) { return I.is(set) ? I.end(set) : S.end(set); }
export function hashCode(set: OrderedSetImpl) { return I.is(set) ? I.hashCode(set) : S.hashCode(set); }
// TODO: possibly add more hash functions to allow for multilevel hashing.
......@@ -97,7 +99,10 @@ export function subtract(a: OrderedSetImpl, b: OrderedSetImpl) {
function areEqualIS(a: I, b: S) { return I.size(a) === S.size(b) && I.start(a) === S.start(b) && I.end(a) === S.end(b); }
function areIntersectingSI(a: S, b: I) {
return areRangesIntersecting(a, b);
if (S.size(a) === 0 || I.size(b) === 0) return false
const predAMinB = S.findPredecessorIndex(a, I.min(b))
const predAMaxB = S.findPredecessorIndex(a, I.max(b))
return predAMinB !== predAMaxB
}
function isSubsetSI(a: S, b: I) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment