距离路口/联合路口、距离

由网友(骚年先疯队)分享简介:我开发的,我想提供一个范围数据类型的编程语言,这对于现在的问题是,并不像通常对清单 INT 值(X,Y)与 X<是。我说的不是通常是因为通常的范围仅仅是一对,但在我的情况下,它是多比,允许有例如:I'm developing a programming language for which I want to...

我开发的,我想提供一个范围数据类型的编程语言,这对于现在的问题是,并不像通常对清单 INT (X,Y)与 X<是。我说的不是通常是因为通常的范围仅仅是一对,但在我的情况下,它是多比,允许有例如:

I'm developing a programming language for which I want to provide a Range data type which for now is, not as usually, a list of pairs of int values (x,y) with the constraint that x < y. I say not as usually because usually a range is just a pair but in my case it is more than than, allowing to have for example

1 to 5, 7 to 11, 13 to 22

中包含的所有的单个对象。

all contained in a single object.

我想提供两个功能来生成工会和两个范围的instersection,应包含最少数量的非重叠的区间从几个范围..因此,例如:

I would like to provide two functions to generate the union and the instersection of two ranges, that should contain the least number of non-overlapping intervals from a couple of ranges.. so for example

1 to 5 || 3 to 8 = 1 to 8
1 to 5 && 3 to 8 = 3 to 5
(1 to 3, 4 to 8) && 2 to 6 = (2 to 3, 4 to 6)

其中, || 是工会和&功放;&安培; 是路口

有关目前实施,正如前文所述,只是列出了..我知道,一个更合适的数据结构存在(间隔树),但现在我更关心的其他联盟/交集建设新的列表名单..

For now their implementation is, as stated before, just a list.. I know that a more suitable data structure exists (interval tree) but for now I'm more concerned in building new lists from the union/intersection of other lists..

这是国家的最先进的算法来实现这两种功能?

Which are the state-of-the-art algorithms to implement these two functions?

在此先感谢

推荐答案

既然你不想处理的间隔树木,只使用名单,我建议你把你的范围内重新presentation脱节的列表间隔时间排序的X坐标。

Since you don't want to deal with interval trees and use only lists, I would suggest you keep your range representation as a list of disjoint intervals sorted by the x coordinates.

由于两个列表,你可以通过做一种合并步骤像我们做排序的列表中合并计算并和交。

Given two lists, you can compute the union and intersection by doing a kind of merge step like we do in merge of sorted lists.

例如:

有关的L1和L2的工会:

For union of L1 and L2:

创建L到空表。

取与L1和L2最小X上的间隔并置于​​L;

Take the interval with smallest x from L1 and L2 and put onto L.

现在采取最小再次,比较以L的最后一个元素,并且决定是否需要合并(如重叠)或一个新的间隔所附(如果它们不重叠)为L的端部并继续处理,像我们在合并两个排序的列表。

Now take smallest again, compare with last element of L, and decide whether they need to be merged (if overlap) or a new interval appended (if they don't overlap) at the end of L and continue processing, like we do in merging two sorted lists.

一旦完成,L将其间隔由X的排序,是不相交的联盟。

Once you are done, L will be the union whose intervals are sorted by x and are disjoint.

有关路口,你可以做类似的事情。

For intersection, you can do something similar.

阅读全文

相关推荐

最新文章