Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e2ba1c

Browse files
akorotkovzilder
authored andcommitted
Comments about rangesets.
1 parent99c24a4 commit6e2ba1c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

‎contrib/pathman/rangeset.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#include"pathman.h"
22

3+
/* Check if two ranges are intersecting */
34
bool
45
irange_intersects(IndexRangea,IndexRangeb)
56
{
67
return (irange_lower(a) <=irange_upper(b))||
78
(irange_lower(b) <=irange_upper(a));
89
}
910

11+
/* Check if two ranges are conjuncted */
1012
bool
1113
irange_conjuncted(IndexRangea,IndexRangeb)
1214
{
1315
return (irange_lower(a)-1 <=irange_upper(b))||
1416
(irange_lower(b)-1 <=irange_upper(a));
1517
}
1618

19+
/* Make union of two ranges. They should have the same lossiness. */
1720
IndexRange
1821
irange_union(IndexRangea,IndexRangeb)
1922
{
@@ -23,6 +26,7 @@ irange_union(IndexRange a, IndexRange b)
2326
irange_is_lossy(a));
2427
}
2528

29+
/* Get intersection of two ranges */
2630
IndexRange
2731
irange_intersect(IndexRangea,IndexRangeb)
2832
{
@@ -31,6 +35,9 @@ irange_intersect(IndexRange a, IndexRange b)
3135
irange_is_lossy(a)||irange_is_lossy(b));
3236
}
3337

38+
/*
39+
* Make union of two index rage lists.
40+
*/
3441
List*
3542
irange_list_union(List*a,List*b)
3643
{
@@ -47,6 +54,7 @@ irange_list_union(List *a, List *b)
4754
{
4855
IndexRangenext;
4956

57+
/* Fetch next range with lesser lower bound */
5058
if (ca&&cb)
5159
{
5260
if (irange_lower(lfirst_irange(ca)) <=irange_lower(lfirst_irange(cb)))
@@ -73,13 +81,17 @@ irange_list_union(List *a, List *b)
7381

7482
if (!have_cur)
7583
{
84+
/* Put this range as current value if don't have it yet */
7685
cur=next;
7786
have_cur= true;
7887
}
7988
else
8089
{
8190
if (irange_conjuncted(next,cur))
8291
{
92+
/*
93+
* Ranges are conjuncted, try to unify them.
94+
*/
8395
if (irange_is_lossy(next)==irange_is_lossy(cur))
8496
{
8597
cur=irange_union(next,cur);
@@ -105,18 +117,26 @@ irange_list_union(List *a, List *b)
105117
}
106118
else
107119
{
120+
/*
121+
* Next range is not conjuncted with current. Put current to the
122+
* result list and put next as current.
123+
*/
108124
result=lappend_irange(result,cur);
109125
cur=next;
110126
}
111127
}
112128
}
113129

130+
/* Put current value into result list if any */
114131
if (have_cur)
115132
result=lappend_irange(result,cur);
116133

117134
returnresult;
118135
}
119136

137+
/*
138+
* Find intersection of two range lists.
139+
*/
120140
List*
121141
irange_list_intersect(List*a,List*b)
122142
{
@@ -132,10 +152,16 @@ irange_list_intersect(List *a, List *b)
132152
{
133153
ra=lfirst_irange(ca);
134154
rb=lfirst_irange(cb);
155+
156+
/* Only care about intersecting ranges */
135157
if (irange_intersects(ra,rb))
136158
{
137159
IndexRangeintersect,last;
138160

161+
/*
162+
* Get intersection and try to "glue" it to previous range,
163+
* put it separately otherwise.
164+
*/
139165
intersect=irange_intersect(ra,rb);
140166
if (result!=NIL)
141167
{
@@ -156,6 +182,11 @@ irange_list_intersect(List *a, List *b)
156182
}
157183
}
158184

185+
/*
186+
* Fetch next ranges. We use upper bound of current range to determine
187+
* which lists to fetch, since lower bound of next range is greater (or
188+
* equal) to upper bound of current.
189+
*/
159190
if (irange_upper(ra) <=irange_upper(rb))
160191
ca=lnext(ca);
161192
if (irange_upper(ra) >=irange_upper(rb))
@@ -164,6 +195,7 @@ irange_list_intersect(List *a, List *b)
164195
returnresult;
165196
}
166197

198+
/* Get total number of elements in range list */
167199
int
168200
irange_list_length(List*rangeset)
169201
{
@@ -178,6 +210,7 @@ irange_list_length(List *rangeset)
178210
returnresult;
179211
}
180212

213+
/* Find particular index in range list */
181214
bool
182215
irange_list_find(List*rangeset,intindex,bool*lossy)
183216
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp