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

Commit549f211

Browse files
committed
Merge branch 'master_fixed_rangeset' into rel_1_2_beta
2 parentsb803886 +fcccced commit549f211

File tree

4 files changed

+252
-49
lines changed

4 files changed

+252
-49
lines changed

‎src/rangeset.c

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,6 @@ irange_eq_bounds(IndexRange a, IndexRange b)
4444
(irange_upper(a)==irange_upper(b));
4545
}
4646

47-
/* Comapre lossiness factor of two ranges */
48-
ir_cmp_lossiness
49-
irange_cmp_lossiness(IndexRangea,IndexRangeb)
50-
{
51-
if (is_irange_lossy(a)==is_irange_lossy(b))
52-
returnIR_EQ_LOSSINESS;
53-
54-
if (is_irange_lossy(a))
55-
returnIR_A_LOSSY;
56-
57-
if (is_irange_lossy(b))
58-
returnIR_B_LOSSY;
59-
60-
returnIR_EQ_LOSSINESS;
61-
}
62-
6347

6448
/* Make union of two conjuncted ranges */
6549
IndexRange
@@ -161,6 +145,10 @@ irange_union_internal(IndexRange first,
161145
IndexRangesecond,
162146
List**new_iranges)
163147
{
148+
/* Assert that both IndexRanges are valid */
149+
Assert(is_irange_valid(first));
150+
Assert(is_irange_valid(second));
151+
164152
/* Swap 'first' and 'second' if order is incorrect */
165153
if (irange_lower(first)>irange_lower(second))
166154
{
@@ -332,39 +320,48 @@ irange_list_intersection(List *a, List *b)
332320
IndexRangera=lfirst_irange(ca),
333321
rb=lfirst_irange(cb);
334322

323+
/* Assert that both IndexRanges are valid */
324+
Assert(is_irange_valid(ra));
325+
Assert(is_irange_valid(rb));
326+
335327
/* Only care about intersecting ranges */
336328
if (iranges_intersect(ra,rb))
337329
{
338-
IndexRangeintersect,last;
330+
IndexRangeir_intersection;
331+
boolglued_to_last= false;
339332

340333
/*
341334
* Get intersection and try to "glue" it to
342-
*previous range, put it separately otherwise.
335+
*last irange, put it separately otherwise.
343336
*/
344-
intersect=irange_intersection_simple(ra,rb);
337+
ir_intersection=irange_intersection_simple(ra,rb);
345338
if (result!=NIL)
346339
{
347-
last=llast_irange(result);
348-
if (iranges_adjoin(last,intersect)&&
349-
is_irange_lossy(last)==is_irange_lossy(intersect))
350-
{
351-
llast(result)=alloc_irange(irange_union_simple(last,intersect));
352-
}
353-
else
340+
IndexRangelast=llast_irange(result);
341+
342+
/* Test if we can glue 'last' and 'ir_intersection' */
343+
if (irange_cmp_lossiness(last,ir_intersection)==IR_EQ_LOSSINESS&&
344+
iranges_adjoin(last,ir_intersection))
354345
{
355-
result=lappend_irange(result,intersect);
346+
IndexRangeir_union=irange_union_simple(last,ir_intersection);
347+
348+
/* We allocate a new IndexRange for safety */
349+
llast(result)=alloc_irange(ir_union);
350+
351+
/* Successfully glued them */
352+
glued_to_last= true;
356353
}
357354
}
358-
else
359-
{
360-
result=lappend_irange(result,intersect);
361-
}
355+
356+
/* Append IndexRange if we couldn't glue it */
357+
if (!glued_to_last)
358+
result=lappend_irange(result,ir_intersection);
362359
}
363360

364361
/*
365-
* Fetch nextranges. We use upper bound of currentrange to determine
366-
* which lists to fetch, since lower bound of next range is greater (or
367-
* equal) to upper bound of current.
362+
* Fetch nextiranges. We use upper bound of currentirange to
363+
*determinewhich lists to fetch, since lower bound of next
364+
*irange is greater (orequal) to upper bound of current.
368365
*/
369366
if (irange_upper(ra) <=irange_upper(rb))
370367
ca=lnext(ca);

‎src/rangeset.h

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ typedef struct {
4444
#defineirange_upper(irange)( (uint32) (irange.upper & IRANGE_BONDARY_MASK) )
4545

4646

47+
#definelfirst_irange(lc)( *(IndexRange *) lfirst(lc) )
48+
#definelappend_irange(list,irange)( lappend((list), alloc_irange(irange)) )
49+
#definelcons_irange(irange,list)( lcons(alloc_irange(irange), (list)) )
50+
#definelist_make1_irange(irange)( lcons_irange(irange, NIL) )
51+
#definellast_irange(list)( lfirst_irange(list_tail(list)) )
52+
#definelinitial_irange(list)( lfirst_irange(list_head(list)) )
53+
54+
4755
inlinestaticIndexRange
4856
make_irange(uint32lower,uint32upper,boollossy)
4957
{
@@ -82,25 +90,17 @@ irb_pred(uint32 boundary)
8290
return0;
8391
}
8492

85-
/* Returnpredecessor or IRANGE_BONDARY_MASK */
93+
/* Returnsuccessor or IRANGE_BONDARY_MASK */
8694
inlinestaticuint32
8795
irb_succ(uint32boundary)
8896
{
8997
if (boundary >=IRANGE_BONDARY_MASK)
90-
returnboundary;
98+
returnIRANGE_BONDARY_MASK;
9199

92100
returnboundary+1;
93101
}
94102

95103

96-
#definelfirst_irange(lc)( *(IndexRange *) lfirst(lc) )
97-
#definelappend_irange(list,irange)( lappend((list), alloc_irange(irange)) )
98-
#definelcons_irange(irange,list)( lcons(alloc_irange(irange), (list)) )
99-
#definelist_make1_irange(irange)( lcons(alloc_irange(irange), NIL) )
100-
#definellast_irange(list)( lfirst_irange(list_tail(list)) )
101-
#definelinitial_irange(list)( lfirst_irange(list_head(list)) )
102-
103-
104104
/* Result of function irange_cmp_lossiness() */
105105
typedefenum
106106
{
@@ -109,12 +109,27 @@ typedef enum
109109
IR_B_LOSSY/* IndexRange 'b' is lossy ('a' is not) */
110110
}ir_cmp_lossiness;
111111

112+
/* Comapre lossiness factor of two IndexRanges */
113+
inlinestaticir_cmp_lossiness
114+
irange_cmp_lossiness(IndexRangea,IndexRangeb)
115+
{
116+
if (is_irange_lossy(a)==is_irange_lossy(b))
117+
returnIR_EQ_LOSSINESS;
118+
119+
if (is_irange_lossy(a))
120+
returnIR_A_LOSSY;
121+
122+
if (is_irange_lossy(b))
123+
returnIR_B_LOSSY;
124+
125+
returnIR_EQ_LOSSINESS;
126+
}
127+
112128

113129
/* Various traits */
114130
booliranges_intersect(IndexRangea,IndexRangeb);
115131
booliranges_adjoin(IndexRangea,IndexRangeb);
116132
boolirange_eq_bounds(IndexRangea,IndexRangeb);
117-
ir_cmp_lossinessirange_cmp_lossiness(IndexRangea,IndexRangeb);
118133

119134
/* Basic operations on IndexRanges */
120135
IndexRangeirange_union_simple(IndexRangea,IndexRangeb);

‎tests/cmocka/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ build_extension:
2626

2727
clean:
2828
rm -f$(OBJ)$(TEST_BIN)
29+
30+
check: all
31+
./$(TEST_BIN)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp