functions_intersection.qbk 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. [/
  2. Copyright (c) 2008-2010 Joachim Faulhaber
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. ]
  7. [/ //= Intersection ============================================================]
  8. [section Intersection][/ Intersection]
  9. [section Synopsis][/ Intersection]
  10. [table
  11. [[Intersection] [__ch_itv_t__][__ch_itv_sets__][__ch_itv_maps__][__ch_ele_sets__][__ch_ele_maps__]]
  12. [[`void add_intersection(T&, const T&, const P&)`][ ] [__eiS][__eiS __bpM][ ] [ ] ]
  13. [[`T& operator &=(T&, const P&)`] [ ] [__eiS][__eiS __bpM][__es] [__bm] ]
  14. [[`T operator & (T, const P&)`\n
  15. `T operator & (const P&, T)`] [__i] [__eiS][__eiS __bpM][__es] [__bm] ]
  16. [[`bool intersects(const T&, const P&)`\n
  17. `bool disjoint(const T&, const P&)`] [__i] [__eiS][__eiS __bpM][__es] [__bm] ]
  18. ]
  19. Functions and operators that are related to ['*intersection*] on *icl* objects
  20. are given in the table above.
  21. [table
  22. [[] [Description of Intersection]]
  23. [[`Sets`][Intersection on Sets implements ['*set intersection*]]]
  24. [[`Maps`][Intersection on Maps implements a ['*map intersection*] function similar to /set intersection/.
  25. If, on intersection, an element value pair `(k,v)` it's key `k` is in the map
  26. already, the intersection function is propagated to the associated value,
  27. if it exists for the Map's codomain_type.
  28. If the codomain_type has no intersection operation, associated
  29. values are combined using addition. For partial map types this
  30. results in an addition on the intersection of the domains of
  31. the intersected sets. For total maps intersection and
  32. addition are identical in this case.
  33. See also
  34. [link boost_icl.semantics.quantifiers__maps_of_numbers.intersection_on_quantifiers ['intersection on Maps of numbers]].
  35. A Map can be intersected with key types: an element
  36. (an interval for interval_maps) and and a Set. This
  37. results in the selection of a submap, and can be
  38. defined as a generalized selection function on Maps.
  39. ]]
  40. ]
  41. [endsect][/ Synopsis Intersection]
  42. [section Functions][/ Intersection]
  43. The overloaded function
  44. `void add_intersection(T& result, const T& y, const P& x)`
  45. allows to accumulate the intersection of `y` and `x` in the first argument `result`.
  46. `Result` might already contain data. In this case the intersection of `y` and `x`
  47. is `added` the the contents of `result`.
  48. ``
  49. T s1 = f, s2 = f, y = g; P x = h; // The effect of
  50. add_intersection(s1, y, x); // add_intersection
  51. s2 += (y & x); // and & followed by +=
  52. assert(s1==s2); // is identical
  53. ``
  54. This might be convenient, if intersection is used like a generalized selection function.
  55. Using element or segment types for `P`, we can select small parts of a container
  56. `y` and accumulate them in `section`.
  57. The admissible combinations of types for function
  58. `void add_intersection(T&, const T&, const P&)` can be summarized in the
  59. ['*overload table*] below.
  60. Compared to other overload tables, placements of function arguments are
  61. different: Row headers denote type `T` of `*this` object.
  62. Columns headers denote type `P` of the second function argument.
  63. The table cells contain the arguments `T` of the intersections
  64. `result`, which is the functions first argument.
  65. ``
  66. /* overload table for */ T\P| e i b p
  67. void T::add_intersection(T& result, const P&)const ---+--------
  68. s | s
  69. m | m m
  70. S | S S
  71. M | M M M M
  72. ``
  73. The next table contains complexity characteristics for function `add_intersection`.
  74. [table Time Complexity for function add_intersection on icl containers
  75. [[`void add_intersection(T&, const T&, const P&)const`] [__ch_dom_t__][__ch_itv_t__][__ch_dom_mp_t__][__ch_itv_mp_t__]]
  76. [[__icl_set__] [__Olgn__] [] [] [] ]
  77. [[__icl_map__] [__Olgn__] [] [__Olgn__] [] ]
  78. [[__itv_sets__] [__Olgn__] [__On__] [] [] ]
  79. [[__itv_maps__] [__Olgn__] [__On__] [__On__] [__On__] ]
  80. ]
  81. [endsect][/ Function Intersection]
  82. [section Inplace operators][/ Intersection]
  83. The overload tables below are giving admissible
  84. type combinations for the intersection `operator &=`.
  85. As for the overload patterns of /subtraction/
  86. intersections are possible within Sets and Maps
  87. but also for Maps combined with /key objects/
  88. which are /key elements, intervals/ and /Sets of keys/.
  89. ``
  90. // overload tables for element containers: interval containers:
  91. T& operator &= (T&, const P&) &= | e b s m &= | e i b p S M
  92. ---+-------- ---+------------
  93. s | s s S | S S S
  94. m | m m m m M | M M M M M M
  95. ``
  96. While intersection on maps can be viewed as
  97. a ['*generalisation of set intersection*]. The
  98. combination on Maps and Sets can be interpreted as
  99. a ['*generalized selection function*], because it
  100. allows to select parts of a maps using
  101. /key/ or /selection objects/.
  102. So we have a ['*generalized intersection*] for
  103. these overloads,
  104. ``
  105. /* (Generalized) intersection */ &= | e b s m &= | e i b p S M
  106. ---+-------- ---+------------
  107. s | s s S | S S S
  108. m | m m M | M M M
  109. ``
  110. [*and] a ['*selection by key objects*] here:
  111. ``
  112. /* Selection by key objects */ &= | e b s m &= | e i b p S M
  113. ---+-------- ---+------------
  114. s | s s S | S S S
  115. m | m m M | M M M
  116. ``
  117. The differences for the different functionalities
  118. of `operator &=` are on the Map-row of the
  119. tables. Both functionalities fall together
  120. for Sets in the function ['*set intersection*].
  121. Complexity characteristics for inplace intersection operations are
  122. given by the next tables where
  123. ``
  124. n = iterative_size(y);
  125. m = iterative_size(x); //if P is a container type
  126. ``
  127. [table Time Complexity for inplace intersection on element containers
  128. [[`T& operator &= (T& y, const P& x)`][__ch_dom_t__][__ch_dom_mp_t__][__ch_icl_set__][__ch_icl_map__]]
  129. [[__icl_set__] [__Olgn__] [] [__Omlgn__] [] ]
  130. [[__icl_map__] [__Olgn__] [__Olgn__] [__Omlgn__] [__Omlgn__] ]
  131. ]
  132. [table Time Complexity for inplace intersection on interval containers
  133. [[`T& operator &= (T& y, const P& x)`][__ch_dom_t__][__ch_itv_t__][__ch_dom_mp_t__][__ch_itv_mp_t__][__ch_itv_sets__][__ch_itv_maps__]]
  134. [[interval_sets] [__Olgn__] [__On__] [] [] [__Omlgnpm__] [] ]
  135. [[interval_maps] [__Olgn__] [__On__] [__Olgn__] [__On__] [__Omlgnpm__] [__Omlgnpm__] ]
  136. ]
  137. [endsect][/ Inplace operators Intersection]
  138. [section Infix operators][/ Intersection]
  139. For the *icl's* infix intersection the
  140. following overloads are available:
  141. ``
  142. // overload tables for element containers: interval containers:
  143. T operator & (T, const P&) & | e b s m & | e i b p S1 S2 S3 M1 M3
  144. T operator & (const P&, T) ---+-------- ---+---------------------------
  145. e | s m e | S1 S2 S3 M1 M3
  146. b | m i | i S1 S2 S3 M1 M3
  147. s | s s m b | M1 M3
  148. m | m m m m p | M1 M3
  149. S1 | S1 S1 S1 S2 S3 M1 M3
  150. S2 | S2 S2 S2 S2 S3 M1 M3
  151. S3 | S3 S3 S3 S3 S3 M1 M3
  152. M1 | M1 M1 M1 M1 M1 M1 M1 M1 M3
  153. M3 | M3 M3 M3 M3 M3 M3 M3 M3 M3
  154. ``
  155. To resolve ambiguities among interval containers
  156. the ['*finer*] container type is chosen as result type.
  157. Again, we can split up the overload tables of
  158. `operator &` in a part describing
  159. the ['*generalized intersection] on interval containers
  160. and a second part defining the
  161. ['*selection by key object] functionality.
  162. ``
  163. /* (Generalized) intersection */ & | e b s m & | e i b p S1 S2 S3 M1 M3
  164. ---+-------- ---+---------------------------
  165. e | s e | S1 S2 S3
  166. b | m i | i S1 S2 S3
  167. s | s s b | M1 M3
  168. m | m m p | M1 M3
  169. S1 | S1 S1 S1 S2 S3
  170. S2 | S2 S2 S2 S2 S3
  171. S3 | S3 S3 S3 S3 S3
  172. M1 | M1 M1 M1 M3
  173. M3 | M3 M3 M3 M3
  174. ``
  175. ``
  176. /* Selection by key objects */ & | e b s m & | e i b p S1 S2 S3 M1 M3
  177. ---+-------- ---+---------------------------
  178. e | s m e | S1 S2 S3 M1 M3
  179. b | i | i S1 S2 S3 M1 M3
  180. s | s s m b |
  181. m | m m p |
  182. S1 | S1 S1 S1 S2 S3 M1 M3
  183. S2 | S2 S2 S2 S2 S3 M1 M3
  184. S3 | S3 S3 S3 S3 S3 M1 M3
  185. M1 | M1 M1 M1 M1 M1
  186. M3 | M3 M3 M3 M3 M3
  187. ``
  188. [endsect][/ Inplace operator Intersection]
  189. [section Intersection tester]
  190. [table
  191. [[Tester] [Desctription]]
  192. [[`bool intersects(const T& left, const P& right)`][Tests, if `left` and `right` intersect.]]
  193. [[`bool disjoint(const T& left, const P& right)`] [Tests, if `left` and `right` are disjoint.]]
  194. [[] [`intersects(x,y) == !disjoint(x,y)`]]
  195. ]
  196. ``
  197. bool intersects(const T&, const P&) T\P| e b s m T\P| e i b p S M
  198. bool disjoint(const T&, const P&) ---+-------- ---+------------
  199. s | 1 1 S | 1 1 1
  200. m | 1 1 1 1 M | 1 1 1 1 1 1
  201. ``
  202. [endsect][/ Intersection tester]
  203. ['*See also . . .*]
  204. [table
  205. []
  206. [[[link boost_icl.function_reference.symmetric_difference ['*Symmetric difference*]] ]]
  207. [[[link boost_icl.function_reference.subtraction ['*Subtraction*]] ]]
  208. [[[link boost_icl.function_reference.addition ['*Addition*]] ]]
  209. ]
  210. ['*Back to section . . .*]
  211. [table
  212. []
  213. [[[link function_synopsis_table ['*Function Synopsis*]] ]]
  214. [[[link boost_icl.interface ['*Interface*]] ]]
  215. ]
  216. [endsect][/ Intersection]