@@ -92,6 +92,36 @@ size_t onesidedgallopingintersection(const uint32_t *smallset,
9292 return out - initout;
9393}
9494
95+ // from: http://didawiki.di.unipi.it/doku.php/magistraleinformaticanetworking/ae/ae2019/start#books_notes_etc
96+ // "The magic of Algorithms! "
97+ // Chap. 6, Algorithm 6.1 Intersection based on Mutual Partitioning
98+ //
99+ size_t mutualPartitioningIntersect (const uint32_t * small_set, size_t small_length,
100+ const uint32_t * large_set, size_t large_length,
101+ uint32_t * result) {
102+ if ((small_length <= 0 ) || (large_length <= 0 )) {
103+ return 0 ;
104+ }
105+ if (small_length > large_length) {
106+ return mutualPartitioningIntersect (large_set, large_length, small_set, small_length, result);
107+ }
108+ int mid_index = small_length / 2 ;
109+ const auto mid_val = small_set[mid_index];
110+ auto it = std::lower_bound (large_set, large_set + large_length, mid_val);
111+ size_t out_num = mutualPartitioningIntersect (small_set, mid_index, large_set, it - large_set, result);
112+ if (it == large_set + large_length) {
113+ return out_num;
114+ }
115+ if (*it == mid_val) {
116+ *result++ = mid_val;
117+ ++it;
118+ ++out_num;
119+ }
120+ ++mid_index;
121+ return out_num + mutualPartitioningIntersect (small_set + mid_index, small_length - mid_index,
122+ it, large_set + large_length - it, result);
123+ }
124+
95125/* *
96126 * Fast scalar scheme designed by N. Kurz.
97127 */
@@ -1269,6 +1299,7 @@ initializeintersectionfactory() {
12691299 std::map<std::string, intersectionfunction> schemes;
12701300 schemes[" simd" ] = SIMDintersection;
12711301 schemes[" galloping" ] = onesidedgallopingintersection;
1302+ schemes[" mut_part" ] = mutualPartitioningIntersect;
12721303 schemes[" scalar" ] = scalar;
12731304 schemes[" v1" ] = v1;
12741305 schemes[" v3" ] = v3;
0 commit comments