File tree Expand file tree Collapse file tree 2 files changed +17
-19
lines changed Expand file tree Collapse file tree 2 files changed +17
-19
lines changed Original file line number Diff line number Diff line change @@ -83,8 +83,6 @@ _int_same(PG_FUNCTION_ARGS)
8383 if (avoid || bvoid )
8484 return (avoid && bvoid ) ? TRUE : FALSE;
8585
86- SORT (a );
87- SORT (b );
8886 na = ARRNELEMS (a );
8987 nb = ARRNELEMS (b );
9088 da = ARRPTR (a );
@@ -94,7 +92,10 @@ _int_same(PG_FUNCTION_ARGS)
9492
9593 if (na == nb )
9694 {
95+ SORT (a );
96+ SORT (b );
9797 result = TRUE;
98+
9899 for (n = 0 ; n < na ; n ++ )
99100 if (da [n ] != db [n ])
100101 {
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ inner_int_contains(ArrayType *a, ArrayType *b)
3434 j ++ ;
3535 }
3636 else
37- j ++ ;
37+ break ;
3838
3939 return (n == nb ) ? TRUE : FALSE;
4040}
@@ -76,13 +76,6 @@ ArrayType *
7676inner_int_union (ArrayType * a , ArrayType * b )
7777{
7878 ArrayType * r = NULL ;
79- int na ,
80- nb ;
81- int * da ,
82- * db ,
83- * dr ;
84- int i ,
85- j ;
8679
8780 CHECKARRVALID (a );
8881 CHECKARRVALID (b );
@@ -94,31 +87,35 @@ inner_int_union(ArrayType *a, ArrayType *b)
9487 if (ARRISVOID (b ))
9588 r = copy_intArrayType (a );
9689
97- if (r )
98- dr = ARRPTR (r );
99- else
90+ if (!r )
10091 {
101- na = ARRNELEMS (a );
102- nb = ARRNELEMS (b );
103- da = ARRPTR (a );
104- db = ARRPTR (b );
92+ int na = ARRNELEMS (a ),
93+ nb = ARRNELEMS (b );
94+ int * da = ARRPTR (a ),
95+ * db = ARRPTR (b );
96+ int i ,j , * dr ;
10597
10698 r = new_intArrayType (na + nb );
10799 dr = ARRPTR (r );
108100
109101 /* union */
110102 i = j = 0 ;
111- while (i < na && j < nb )
112- if (da [i ] < db [j ])
103+ while (i < na && j < nb ) {
104+ if (da [i ] == db [j ]) {
105+ * dr ++ = da [i ++ ];
106+ j ++ ;
107+ } else if (da [i ] < db [j ])
113108 * dr ++ = da [i ++ ];
114109 else
115110 * dr ++ = db [j ++ ];
111+ }
116112
117113 while (i < na )
118114 * dr ++ = da [i ++ ];
119115 while (j < nb )
120116 * dr ++ = db [j ++ ];
121117
118+ r = resize_intArrayType (r , dr - ARRPTR (r ));
122119 }
123120
124121 if (ARRNELEMS (r ) > 1 )
You can’t perform that action at this time.
0 commit comments