hastic-zzz / hastic-server

Hastic data management server for analyzing patterns and anomalies from Grafana
GNU General Public License v3.0
330 stars 23 forks source link

Utils SpansCut to SegmentsCut, IntegerSegment and IntegerSegmentSet #756

Closed jonyrock closed 5 years ago

jonyrock commented 5 years ago

Just to be sure that the function Utils.spans.cutSpanWithSpans works as it should, few more tests added: It will help in future if we want to improve the performance.

I believe that Span should represent a discrete structure, which is a countable set, integer segment , subset of Z Also, I propose to stop using word "Span" without clear math definition. So I an going to rename Utils.spans.cutSpanWithSpans accordingly.

image

If we cut [z, z] and [x, y] from [a, b] , then we get [[a, z - 1], [z + 1, x - 1]]

So when we want to get cut [x, x] from [a, b] where a < x < b, then we should return split [a, x - 1] and [x + 1, b]

This PR changes the behavior of cutSpanWithSpans and renames it to cutSegmentWithSegments

Changes

New tests:

One-point cut

If we cut [1, 10] with [5, 5] , we should get spans [1, 4] and [6, 10]

Infinite spans

If we cut [0, Infinity] with [5, 10], we should get [0, 4] and [11, Infinity]

If we cut [1, 6] with [0, Infinity], we should get []

If we cut [0, 6] with [1, Infinity], we should get [0, 0]

If we cut [-Infinity, Infinity] with [-Infinity, Infinity] we should get []

Overlapping cuts

There are many combinations where cuts include each other or could be sorted wrong. Many new combinations added. Including infinite case.