home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / help / dde4ccl.in_ / DDE4CCL.INF (.txt)
Encoding:
OS/2 Help File  |  1992-10-27  |  182.1 KB  |  7,245 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Version Notice ΓòÉΓòÉΓòÉ
  3.  
  4. This document contains User's Guide and Reference Manual for the IBM Class 
  5. Library: Collection Classes 
  6.  
  7. November 1992 - External Beta The main purpose of this driver of the IBM Class 
  8. Library: Collection Classes is to provide material that can be used in 
  9. conjunction with the external beta test driver of the Toronto OS/2 C++ compiler 
  10. package. 
  11.  
  12. Current restrictions.  are described in a separate section. 
  13.  
  14. A form for readers' comments is provided at the back of this publication. If 
  15. the form has been removed, address your comments to: 
  16.  
  17. IBM Canada Ltd. Laboratory
  18. Information Development
  19. 21/986/844/TOR
  20. 844 Don Mills Road
  21. North York, Ontario, Canada. M3C 1V7
  22.  
  23. You can also send your comments by facsimile to (416) 448-6057 addressed to the 
  24. attention of the RCF Coordinator. If you have access to Internet, you can send 
  25. your comments electronically to torrcf@vnet.ibm.com; IBMLINK, to 
  26. toribm(torrcf); IBM/PROFS, to torolab4(torrcf) 
  27.  
  28. If you choose to respond through Internet, please include either your entire 
  29. Internet network address, or a postal address. 
  30.  
  31. When you send information to IBM, you grant IBM a nonexclusive right to use or 
  32. distribute the information in any way it believes appropriate without incurring 
  33. any obligation to you. 
  34.  
  35.  
  36. ΓòÉΓòÉΓòÉ 1.1. Notices ΓòÉΓòÉΓòÉ
  37.  
  38. References in this publication to IBM products, programs, or services do not 
  39. imply that IBM intends to make these available in all countries in which IBM 
  40. operates. Any reference to an IBM licensed program in this publication is not 
  41. intended to state or imply that only IBM's licensed program may be used. Any 
  42. functionally equivalent product, program, or service that does not infringe any 
  43. of IBM's intellectual property rights may be used instead of the IBM product, 
  44. program, or service. Evaluation and verification of operation in conjunction 
  45. with other products, except those expressly designated by IBM, is the user's 
  46. responsibility. 
  47.  
  48. IBM may have patents or pending patent applications covering subject matter in 
  49. this document. The furnishing of this document does not give you any license to 
  50. these patents. You can send license inquiries, in writing, to the IBM Director 
  51. of Commercial Relations, IBM Corporation, Purchase, NY 10577. 
  52.  
  53.  
  54. ΓòÉΓòÉΓòÉ 2. User's Guide ΓòÉΓòÉΓòÉ
  55.  
  56.  
  57. ΓòÉΓòÉΓòÉ 2.1. Introduction ΓòÉΓòÉΓòÉ
  58.  
  59. This document contains the information required to use the IBM Class Library: 
  60. Collection Classes (or Collection Classes for short). The Collection Classes 
  61. are generic C++ classes designed to be used in system or application programs 
  62. written in the object-oriented language C++. Each Class implements an abstract 
  63. data type of the collection variety such as list, tree, or set. 
  64.  
  65.  
  66. ΓòÉΓòÉΓòÉ 2.1.1. Who Should Read This Document ΓòÉΓòÉΓòÉ
  67.  
  68. The User's Guide and Reference Manual is intended for C++ programmers and 
  69. program designers who wish to make use of one or more C++ BBs in developing an 
  70. application. As such, it presupposes some familiarity with C++ and, in 
  71. particular, with the C++ class concept. 
  72.  
  73.  
  74. ΓòÉΓòÉΓòÉ 2.1.2. How This Document Is Organized ΓòÉΓòÉΓòÉ
  75.  
  76. User's Guide contains the following chapters: 
  77.  
  78. What the Library Offers introduces the motivation for having such a library. 
  79.  
  80. Library Overview explains the general structure of the library. 
  81.  
  82. Basic Concepts describes in detail the concepts and techniques used. 
  83.  
  84. Reference Manual - Flat Collections contains an introductory chapter, which 
  85. includes a synopsis of all functions of the flat collections, and a chapter for 
  86. each class, which describes its semantics and interfaces in detail, including 
  87. coding examples. 
  88.  
  89. subj='Tree Classes'.Reference Manual - Tree Classes is organized the same and 
  90. describes the tree classes. 
  91.  
  92. subj='Auxiliary Classes'.Reference Manual - Auxiliary Classes describes a few 
  93. auxiliary classe. 
  94.  
  95. subj='Abstract Classes'.Reference Manual - Abstract Classes describes the 
  96. abstract classes. 
  97.  
  98.  
  99. ΓòÉΓòÉΓòÉ 2.1.3. Related Documentation ΓòÉΓòÉΓòÉ
  100.  
  101. to be completed .... 
  102.  
  103.  
  104. ΓòÉΓòÉΓòÉ 2.1.4. Current restrictions ΓòÉΓòÉΓòÉ
  105.  
  106. Implementation Restrictions: 
  107.  
  108. o Trees are not available 
  109. o IBounded is not implemented 
  110. o Multi level implementation chains (like set based on key sorted set based on 
  111.   linked sequence) lead to (mangled) names longer than 255 which are not 
  112.   accepted by the linker 
  113. o Diluted arrays and b*trees are not yet implemented 
  114.  
  115.  
  116. ΓòÉΓòÉΓòÉ 2.2. What the Library Offers ΓòÉΓòÉΓòÉ
  117.  
  118. The IBM Class Library: Collection Classes implements commonly used data 
  119. abstractions such as sets, maps, sequences, relations, trees, and stacks, in 
  120. the C++ programming language. 
  121.  
  122. The major focus of the library design is on high performance. The library's 
  123. collection classes are designed to be not only for prototypes or smaller 
  124. applications, but also for production- quality high-performance systems. The 
  125. library achieves high-performance on two levels: 
  126.  
  127. o By using appropriate C++ concepts for its implementation 
  128. o By providing you with a function for tailoring collection class 
  129.   implementations to the specific needs of your software system. 
  130.  
  131. Although C++ is a high performance system programming language, several of the 
  132. programming techniques it enables can cause your programs to be inefficient. 
  133. For example, virtual functions can never be  inlined, and calling overhead may 
  134. increase as a result. Templates may cause large amounts of code to be generated 
  135. through template  instantiations. The library is designed to circumvent such 
  136. inefficiencies while still offering C++ benefits such as polymorphism and 
  137. strong typing. 
  138.  
  139. Each data abstraction has several implementations. For example, you can 
  140. implement sets through hash tables, search trees, or sequences. Your choice of 
  141. implementation depends on the context in which you apply the data abstraction 
  142. Hash tables are a good solution, but if the maximum number of elements is known 
  143. in advance and if sets are often copied, binary search arrays may provide 
  144. superior performance. In other contexts, AVL trees may be the best solution. 
  145.  
  146. Even within a given project context, you can often only decide on a concrete 
  147. implementation after you conduct prototyping experiments with the systems and 
  148. you gather initial figures about the usage of collection functions 
  149. Nonfunctional system requirements often change, especially when you are reusing 
  150. system components in other contexts. The ability to replace an implementation 
  151. that was well-suited to one context with one that is well-suited to a new 
  152. context is essential for system development, maintenance, and reuse. The 
  153. library therefore strictly distinguishes between abstract data types, such as 
  154. sets or sequences, and their concrete implementations, such as AVL trees, hash 
  155. tables, linked lists, or arrays. 
  156.  
  157. The library incorporates a common interface for the abstract data types through 
  158. which the different concrete implementations can be accessed. The main 
  159. challenge in this approach is to avoid losing the capabilities of concrete 
  160. implementations by hiding them through an abstract interface. For example, you 
  161. can implement sequences without knowing whether they are implemented by linked 
  162. nodes or by arrays. The concept of cursors, however, which are an abstraction 
  163. of node pointers and array indices, retain the critical capabilities at the 
  164. abstract sequence interface. 
  165.  
  166. The library enables you to choose the right data abstraction by providing 
  167. collection classes that are a complete, systematic, and consistent combination 
  168. of basic properties. These properties are explained in the following section. 
  169. Properties lead to questions you can ask and these questions lead you to select 
  170. the appropriate data type. These questions also prevent you from using data 
  171. types that are on a lower abstraction level than necessary. You may think of a 
  172. sorted tree when you only need a set (with fast element access) or you may 
  173. think of a sequence when you only need an unordered collection of elements. 
  174.  
  175.  
  176. ΓòÉΓòÉΓòÉ 2.3. Library Overview ΓòÉΓòÉΓòÉ
  177.  
  178. Instead of just providing common abstractions such as sets, maps, sorted 
  179. collections, and sequences, the library offers a systematic, orthogonal 
  180. framework of concepts that can be used to determine the data abstraction that 
  181. is needed in a given situation. 
  182.  
  183. The framework does not include implementation decisions, such as the choice for 
  184. implementing a set through a hash table, an AVL tree, or a binary search array. 
  185. You should defer this decision until it can be made on a more solid basis. 
  186. However, you can use a basic understanding of the implementation choices to do 
  187. some early worst case performance analysis. Implementation issues are presented 
  188. in section Tailoring a Collection Implementation. 
  189.  
  190. The main classes that the library provides are flat collections. There are also 
  191. trees and several auxiliary classes to handle garbage collection by reference 
  192. counting, or to build recursive collections: 
  193.  
  194. Flat Collections. 
  195.           Flat collections are, for example, sequences, sets, bags or maps. As 
  196.           opposed to trees, graphs or recursive collections there is no 
  197.           hierarchy of elements or recursive structure of collections. 
  198.  
  199.           Flat collections and their properties are described in detail in Flat 
  200.           Collections. 
  201.  
  202. Flat Collections with Restricted Access 
  203.           Restricted access collections are, for example, stacks or priority 
  204.           queues. They are based on flat collections and restrict the set of 
  205.           applicable functions. 
  206.  
  207.           You will find more information in Flat Collection with Restricted 
  208.           Access. 
  209.  
  210. Trees 
  211.           Trees are not flat. They can be described either as a structure where 
  212.           their elements have a hierarchy or as a special form of recursive 
  213.           structures. I.e. a tree can be recursively described as a node with 
  214.           references to other nodes. 
  215.  
  216.           The library offers two kinds of trees: 
  217.  
  218.     1. binary trees 
  219.  
  220.     2. n-ary trees Please refer to Binary Tree and N-ary Tree for a full 
  221.           explanation. 
  222.  
  223. Auxiliary Classes 
  224.           In order to use the collection classes you need also a cursor and an 
  225.           iterator class. 
  226.  
  227.           Both are further described in Cursors and Using Iterators. 
  228.  
  229.           The reference classes provides the means to manage objects and 
  230.           garbage collection. 
  231.  
  232.           Values vs. (Managed) Objects and Garbage Collection explain the 
  233.           concepts and usage in detail. 
  234.  
  235. A general property of the library's collection classes is that all collections 
  236. are implemented without structure sharing. This means that a collection 
  237. referred to by variable A cannot be part of another collection referred to by 
  238. variable B. This prevents changes performed on B from having side effects on A 
  239. and vice versa. Such side effects complicate program understanding and 
  240. validation and should in general be avoided. You can still use C++ references 
  241. or pointers to share whole collection objects or pass them as arguments. 
  242.  
  243.  
  244. ΓòÉΓòÉΓòÉ 2.3.1. Flat Collections ΓòÉΓòÉΓòÉ
  245.  
  246. There are four basic properties that are used to describe the characteristics 
  247. of flat collections: 
  248.  
  249. Ordering 
  250.           is there a next or previous relationship between the elements. 
  251.  
  252. Availability of equality for elements 
  253.           is the value of the whole element relevant. 
  254.  
  255. Access by key 
  256.           is the value of a part of the element (a key) relevant. 
  257.  
  258. Uniqueness of entries. 
  259.           are the only unique or multiple occurrences of the same element 
  260.           allowed. 
  261. The properties for flat collections are summarized in "Figure: Combination of 
  262. collection properties". Subsequent sections describe them in more detail. 
  263.  
  264.  
  265. Combination of collection properties
  266.  
  267.  
  268. ΓòÉΓòÉΓòÉ 2.3.1.1. Ordering of Collection Elements ΓòÉΓòÉΓòÉ
  269.  
  270. There are three kinds of orderings: 
  271.  
  272. o Unordered collections have no ordering of their elements at all. 
  273. o Sorted collections have their elements sorted by an ordering relation defined 
  274.   for the element type. For example integers can be sorted ascending or strings 
  275.   alphabetically The ordering relation is determined by instantiating the 
  276.   collection class. 
  277. o Sequential collections have their ordering determined by an explicit 
  278.   qualifier to the Add function, for example AddAsFirst. 
  279.  
  280. While sorted collections allow fast element access through the ordering 
  281. relation, unordered collections may be implemented in a way that also allows 
  282. fast access to the elements, for example by using a hash table or a sorted 
  283. representation. A fast locate function which can make use of this structure is 
  284. provided for unordered and sorted collections. Even though unordered 
  285. collections are often implemented by sorting the elements, you should never 
  286. make this (implicit) assumption for an unordered collection. For each of the 
  287. following collection categories, the library provides both unordered and sorted 
  288. abstractions, such as sets and sorted sets, so the choice for unordered or 
  289. sorted is independent of other selection criteria. 
  290.  
  291.  
  292. ΓòÉΓòÉΓòÉ 2.3.1.2. Elements, Keys and Equality ΓòÉΓòÉΓòÉ
  293.  
  294. The collection structure may depend on an ordering relation, or a hash function 
  295. that is defined on the element type itself, or it may be defined on a key of 
  296. the element. A key is usually a data member of the element but can be some 
  297. arbitrary function from the element type to some given key type. 
  298.  
  299. Equality or ordering for the key type may be different from equality or 
  300. ordering for the element type. Consider, for example, a task control block that 
  301. has a priority and a task identifier that defines equality for tasks. You could 
  302. choose to implement a task collection as unordered with the task ID as key, or 
  303. as sorted with the priority as key. In the first case, you have a fast access 
  304. via the task ID and no (particular) access via the priority; in the second case 
  305. you have fast access via the priority but not via the task ID. The ordering 
  306. relation on the priority key in the second case is not compatible with the task 
  307. equality, since two tasks can have equal priorities without being equal. 
  308.  
  309. These considerations show that equality for the element and equality/ordering 
  310. for the key must be distinguished. For collections with key, equality must 
  311. always be provided for at least the key type. Functions like 
  312. locateElementWithKey use this key equality for locating elements. Element 
  313. equality may optionally be provided, in addition to key equality. Functions 
  314. that are based on equality (such as locate) are only provided for collections 
  315. that have an element equality defined. Non-equality, non-key collections (Heaps 
  316. and Sequences) provide no functions for locating elements by their values or 
  317. testing for containment. They are containers which elements can be added to and 
  318. retrieved from by iteration or, for Sequences, by position. 
  319.  
  320. For sorted collections without a key there is always an ordering relation for 
  321. the element type This relation implicitly defines element equality. Sorted 
  322. collections with no key and no element equality do not make sense. 
  323.  
  324. In addition to acting as a 'carrier' for structuring information, the key 
  325. concept is mainly used for accessing an element by providing its key as 
  326. argument to functions such as elementWithKey. The alternative to defining 
  327. equality of elements as equality of their keys (in the task example: defining 
  328. task equality as equality of the task id) and then locating collection entries 
  329. by providing an equal element, causes performance problems when the element is 
  330. large or difficult to construct compared to the key alone. Consider the two 
  331. alternatives: 
  332.  
  333.   TaskId const& key (Task const& t) {return t.id;}
  334.   KeySet < Task, int > tasks;
  335.   ...
  336.   tasks.locateElementWithKey (1);
  337. and 
  338.  
  339.   Boolean operator== (Task const &t1, Task const& t2)
  340.   {return t1.id == t2.id;}
  341.   Set < Task > tasks;
  342.   ...
  343.   Task t1;
  344.   t1.id = 1;
  345.   tasks.locate (t1);
  346. The first solution is superior, if task construction (Task t1) is not free. 
  347.  
  348. The library offers the abstractions of (possibly sorted) Maps and Relations 
  349. where both key and element equality must be provided. These abstractions are 
  350. similar to KeySets and KeyBags but, in addition, the functions based on element 
  351. equality are defined in particular, union and intersection. Furthermore, the 
  352. add function behaves differently toward the corresponding classes without 
  353. element equality with respect to uniqueness of elements. This is discussed in 
  354. the following section. 
  355.  
  356. In mathematics, maps and relations are mostly defined as sets of pairs of 
  357. components: a key component and an information component. Maps and Relations as 
  358. the library defines them do not make the pairing explicit; they expect the 
  359. element type to be the pair, with the key given by some access function. 
  360. Pairing can easily be put on top of this implementation but a given 
  361. key/information pair type on top of a map that requires the two components to 
  362. be separated is not possible. 
  363.  
  364.  
  365. ΓòÉΓòÉΓòÉ 2.3.1.3. Unique vs. Multiple Occurrences ΓòÉΓòÉΓòÉ
  366.  
  367. The same element or key may be added several times to the same collection. If 
  368. the programmer is interested in the number of occurrences of the element, an 
  369. element can be added once or multiple times. According to this distinction we 
  370. say that collections have unique or multiple elements or keys. 
  371.  
  372. For collections with a key uniqueness is always with respect to the key (this 
  373. means uniqueness for the element, because unequal keys mean unequal elements). 
  374. For non-unique collections with key and element equality (Relations), elements 
  375. are always unique (while keys can occur multiple times). A collection with 
  376. multiple elements and keys together with element equality is not provided; the 
  377. corresponding collection without element equality may be used instead, but the 
  378. element dependent functions (such as remove) must be implemented by the 
  379. programmer, for example, by iterating over the elements associated with the 
  380. given key. For collections without key and with no element equality there is no 
  381. unique variant because containment is not defined. 
  382.  
  383. Unique and multiple collections are established by defining the behavior of the 
  384. add function, according to whether it adds the element or not. The add function 
  385. has, in general, two properties: 
  386.  
  387. o All elements that have been contained in the collection before will be 
  388.   contained afterwards 
  389. o The given element will be contained afterwards. 
  390. This property could not be fulfilled for Map, if an element is added to that 
  391. which another element with the same key is already contained. In this case, an 
  392. exception will be thrown. For KeySet which does not know about element 
  393. equality, the element is not added if an element with the same key already 
  394. exists. This may violate the condition stated before, that element equality is 
  395. different from key equality for a KeySet; the alternative to always raising an 
  396. exception would, however, be less desirable. There are the functions 
  397. locateOrAddElementWithKey and addOrReplaceElementWithKey which explicitly state 
  398. what shall happen in case an element with the same key is already contained in 
  399. the collection. 
  400.  
  401. "Figure: Behavior of add for unique and multiple collections" illustrates the 
  402. concept of keys, element equality and uniqueness. Consider elements which are 
  403. pairs of integers, the first being the key. Element equality, if defined, is 
  404. equality of both integers. Adding the following (pair-)elements will yield the 
  405. corresponding results so the ordering of the elements is irrelevant. 
  406.  
  407. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  408. Γöé add        Γöé Map        Γöé Relation   Γöé KeySet     Γöé KeyBag     Γöé
  409. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  410. Γöé <1,1>      Γöé <1,1>      Γöé <1,1>      Γöé <1,1>      Γöé <1,1>      Γöé
  411. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  412. Γöé <2,1>      Γöé <1,1>,     Γöé <1,1>,     Γöé <1,1>,     Γöé <1,1>,     Γöé
  413. Γöé            Γöé <2,1>      Γöé <2,1>      Γöé <2,1>      Γöé <2,1>      Γöé
  414. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  415. Γöé <1,1>      Γöé <1,1>,     Γöé <1,1>,     Γöé <1,1>,     Γöé <1,1>,     Γöé
  416. Γöé            Γöé <2,1>      Γöé <2,1>      Γöé <2,1>      Γöé <2,1>,     Γöé
  417. Γöé            Γöé            Γöé            Γöé            Γöé <1,1>      Γöé
  418. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  419. Γöé <1,2>      Γöé exception: Γöé <1,1>,     Γöé <1,1>,     Γöé <1,1>,     Γöé
  420. Γöé            Γöé KeyAlreadyEΓöéi<2,1>,     Γöé <2,1>      Γöé <2,1>,     Γöé
  421. Γöé            Γöé            Γöé <1,2>      Γöé            Γöé <1,1>,     Γöé
  422. Γöé            Γöé            Γöé            Γöé            Γöé <1,2>      Γöé
  423. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  424.  
  425. Behavior of add for unique and multiple collections 
  426.  
  427.  
  428. ΓòÉΓòÉΓòÉ 2.3.2. Flat Collection with Restricted Access ΓòÉΓòÉΓòÉ
  429.  
  430. Restricted access collections are, for example, stacks or priority queues. They 
  431. are based on flat collections and restrict the set of applicable functions. 
  432. These restrictions are present for two reasons: 
  433.  
  434.  1. They allow certain assumptions to be made when validating and inspecting 
  435.     the code; a stack, for example, does not allow the removal of any element 
  436.     except the top one. 
  437.  2. Functionality restrictions open up new implementation alternatives. With 
  438.     stacks, for example, a linked implementation that shares common front nodes 
  439.     is possible, whereas sequence functions that change other than the top 
  440.     element prohibit this implementation. 
  441. Currently you will find restricted access classes for sequences and key sorted 
  442. bags: 
  443.  
  444. o Stacks, deques and queues are all based on sequence. 
  445. o Priority Queues are based on key sorted bags. 
  446.  
  447.  
  448. ΓòÉΓòÉΓòÉ 2.3.3. Trees ΓòÉΓòÉΓòÉ
  449.  
  450. Trees are not flat. They can be described either as a structure where their 
  451. elements have a hierarchy or as a special form of recursive structures. I.e. a 
  452. tree can be recursively described as a node with references to other nodes. 
  453.  
  454. The library offers two kinds of trees: 
  455.  
  456.  1. binary trees 
  457.  
  458.  2. n-ary trees 
  459. Please refer to Binary Tree and N-ary Tree for a full explanation. 
  460.  
  461.  
  462. ΓòÉΓòÉΓòÉ 2.3.4. Auxilitary Classes ΓòÉΓòÉΓòÉ
  463.  
  464. In order to use the collection classes you need also a cursor and an iterator 
  465. class. 
  466.  
  467. They are further described in Cursors and Using Iterators. 
  468.  
  469. The reference classes provides the means to manage objects and garbage 
  470. collection. 
  471.  
  472. Values vs. (Managed) Objects and hdref refid=garb. explain the concepts and 
  473. usage in detail. 
  474.  
  475.  
  476. ΓòÉΓòÉΓòÉ 2.3.5. The Overall Implementation Structure ΓòÉΓòÉΓòÉ
  477.  
  478. It is a major design issue of the library, to achieve maximum efficiency 
  479. together with ease of use. This goal has lead to a class structure that 
  480. combines the common features of object-orientation, such as class hierarchies, 
  481. polymorphism and late binding, with a more efficiency-oriented class structure 
  482. using inline functions. This section gives a brief overview of the library 
  483. structure which is sketched in "Figure: Overall library structure". A more 
  484. detailed explanation of the particular concepts is found in subsequent 
  485. sections. 
  486.  
  487. You do not have to understand the whole implementation structure right from the 
  488. start. There are three levels of complexity that you can approach step by step: 
  489.  
  490. use the defaults only 
  491.           in this case you only worry about the default classes. 
  492.  
  493. use different implementations 
  494.           using techniques that are described in Tailoring a Collection 
  495.           Implementation you use the concrete classes to replace the default 
  496.           implementation. 
  497.  
  498. make use of polymorphism 
  499.           abstract classes and reference classes provide the means for that. 
  500. The categories of classes are shown in "Figure: Overall library structure". and 
  501. are introduced briefly below. 
  502.  
  503.  
  504. Overall library structure
  505.  
  506. Default Classes 
  507.           The easiest way to use the library's collection classes is through 
  508.           the provided default classes. Two default classes are provided for 
  509.           each data abstraction, one that is instantiated only with the element 
  510.           (and possibly key) type (ISet), and one that, in addition, takes 
  511.           element specific functions (IGSet, see section Defining Element 
  512.           Functions). 
  513.  
  514. Concrete Classes 
  515.           For each abstraction there exist several concrete representations; 
  516.           sets may, for example, be implemented based on sorted maps or on hash 
  517.           tables, or sorted maps may be implemented on AVL trees or on 
  518.           sequences. Concrete classes are grouped according to the data 
  519.           abstraction which they implement. They all have the same interface. 
  520.  
  521.           Based on relationships in "Figure: Overall library structure" 
  522.           indicate that the based class is a template that needs to be 
  523.           instantiated with a class that implements the interface of the 
  524.           class(es) to which the arrow points. This mechanism is used for 
  525.           reference classes and for concrete implementations that are based on 
  526.           other classes. Names of concrete classes based on other concrete 
  527.           classes start with IW, for example IWSetOnSortedMap. These classes 
  528.           are instantiated to compose a specific implementation, such as a set 
  529.           being based on a sorted map again being based on a sequence. This 
  530.           mechanism is further explained in section Tailoring a Collection 
  531.           Implementation. 
  532.  
  533. Abstract Classes 
  534.           Object-orientation ordinarily represents this grouping by a class 
  535.           hierarchy. The library defines this hierarchy by the abstract 
  536.           classes. Names of abstract classes start with IA. The leaves of the 
  537.           abstract class hierarchy define the data abstractions for which 
  538.           concrete implementations are provided. The full abstract class 
  539.           hierarchy is shown in "Figure: The abstract class hierarchy". 
  540.  
  541.  
  542.                     The abstract class hierarchy
  543.  
  544. Reference Classes 
  545.           The concrete classes are not derived from the abstract classes 
  546.           because this would cause inevitable virtual function call overhead 
  547.           (see footnote  (**) in section Introduction). Programmers who do not 
  548.           want to make use of the polymorphism for collections, do not want to 
  549.           pay the function call penalty. Abstract and concrete classes are 
  550.           linked through so-called reference classes. These classes are derived 
  551.           from the abstract classes and implement the functions based on a 
  552.           given, corresponding concrete class. Names of reference classes start 
  553.           with IR. This mechanism is further described in section Polymorphic 
  554.           Use of Collections. 
  555.  
  556. Implementation Classes 
  557.           Implementation classes are used for handling the problem of 
  558.           (unnecessary) code expansion (see footnote  (**) in section 
  559.           Introduction). They provide an untyped (void*) interface which is 
  560.           used by the concrete class implementations. Programmers will never 
  561.           use the implementation classes directly. 
  562.  
  563.  
  564. ΓòÉΓòÉΓòÉ 2.4. Basic Concepts ΓòÉΓòÉΓòÉ
  565.  
  566.  
  567. ΓòÉΓòÉΓòÉ 2.4.1. Instantiating and Using the Collection Classes ΓòÉΓòÉΓòÉ
  568.  
  569. Using a collection class generally proceeds in three steps: 
  570.  
  571.  1. Instantiating a collection class template, and providing arguments for the 
  572.     formal template arguments 
  573.  
  574.  2. Defining one or more objects of this instantiated class, possibly providing 
  575.     constructor argument(s) 
  576.  
  577.  3. Applying functions to these objects. 
  578.  
  579. Section The Based-On Concept will introduce another step before class 
  580. instantiation, namely the composition of several class templates to a new one 
  581. (for example, implementing a set based on a sorted collection which is again 
  582. based on a sequence for which, finally, a tabular sequence implementation is 
  583. chosen). For each abstraction there is at least one predefined, default 
  584. implementation choice. 
  585.  
  586.  
  587. ΓòÉΓòÉΓòÉ 2.4.1.1. Instantiation and Object Definition ΓòÉΓòÉΓòÉ
  588.  
  589. This section describes instantiation for the default implementation. For a 
  590. given class, say ISet, and a given element type, say Task, an instantiation for 
  591. a new class that represents sets of tasks is written as: 
  592.  
  593.    typedef ISet < Task > TaskSet;
  594. or 
  595.  
  596.    class TaskSet : public ISet < Task > {
  597.    public:
  598.      TaskSet (INumber n = 100) : ISet < Task > (n) {}
  599.    }
  600. The second form defines a new class type which is upward, but not downward 
  601. compatible with ISet < Task >, and does not inherit any constructor with 
  602. default arguments, which would have to be redefined as shown. The first form 
  603. introduces a shorthand for this name. 
  604.  
  605. Objects, such as toBeDone, pending, and delayed of this class can now be 
  606. defined by: 
  607.  
  608.    TaskSet toBeDone, pending, delayed;
  609.  
  610. Both steps might technically also have to be done in one: 
  611.  
  612.    ISet < Task > toBeDone, pending, delayed;
  613. It is recommended to explicitly define or derive a named class which is used 
  614. for the intended purpose (here, sets of tasks) and which can later on be 
  615. redefined using an implementation more suitable than the default (see Tailoring 
  616. a Collection Implementation). 
  617.  
  618.  
  619. ΓòÉΓòÉΓòÉ 2.4.1.2. Bounded and Unbounded Collections ΓòÉΓòÉΓòÉ
  620.  
  621. If a collection is bounded it can contain a certain maximum number of elements. 
  622. This decision can be made independent of the choice of collection 
  623. implementation; all implementations allow an arbitrary number of elements 
  624. (until the memory is exceeded) which may, involve restructuring or reallocation 
  625. of space. 
  626.  
  627. A collection should only be made bounded if the number of elements is bounded 
  628. by some other criterion. Sets, for example, may be bounded by a known number of 
  629. elements that are in the set; a set of states may be bounded by the number of 
  630. different states. It is generally not a good idea to impose a size restriction 
  631. by choosing an upper bound for the size of a collection. 
  632.  
  633. The primary collection constructor has two arguments: the number of elements 
  634. and an indication of whether the collection shall be bounded or unbounded. 
  635.  
  636.    enum IBoundIndicator {IBounded, IUnbounded};
  637.    ...
  638.    class <AnyCollection> {
  639.      ...
  640.      <AnyCollection> (INumber = 100, IBoundIndicator = IUnbounded);
  641.    };
  642.  
  643. If the BoundIndicator is IUnbounded the number specifies an estimate for the 
  644. number of elements in the collection which is not upper bound. If the 
  645. BoundIndicator is IBounded the number specifies an upper bound for the number 
  646. of elements in the collection. If this bound is exceeded, the exception 
  647. IFullException will be raised. The function isFull can be used to check (in 
  648. advance) whether the collection is full. 
  649.  
  650. The function isBounded can be used to test whether a collection is bounded and, 
  651. if it is, the function maxNumberOfElements tells its maximum element number. 
  652.  
  653.  
  654. ΓòÉΓòÉΓòÉ 2.4.1.3. Adding, Removing, and Replacing Elements ΓòÉΓòÉΓòÉ
  655.  
  656. The main functions for constructing collections are (different variations of) 
  657. add, remove, and replace. 
  658.  
  659. The function add adds the given element to the collection. According to the 
  660. collection properties this function behaves differently for different 
  661. collections: with unique collections the element is not added if it is already 
  662. contained; for sorted collections it is added according to its ordering 
  663. relation; for sequential collections, it is added last. A general rule for the 
  664. behavior of add is that iterating over a given collection and adding each 
  665. element to a new collection that is initially empty yields a copy of the given 
  666. collection in the new collection. In particular, for a sequential collection 
  667. add must add the element as last, because iteration iterates from the first 
  668. towards the last element. 
  669.  
  670. For sequential collections, elements can be added at a given position. Elements 
  671. before and including this position will be 'shifted'. Positions can be 
  672. specified by a number, where counting starts with 1 for the first element, or 
  673. relative to some other element occurrence (asNext, asPrevious), or relative to 
  674. the collection (asFirst, asLast). 
  675.  
  676. Removal of an element can in general be done for the element occurrence 
  677. referred to by a given cursor (see section Cursors). All other removal 
  678. functions can be reduced to this function by first generating a cursor that 
  679. refers to the desired position and then removing the element to which the 
  680. cursor refers. There is an important difference between element values and 
  681. element occurrences. An element value may, for non-unique collections, occur 
  682. more than once. The basic remove function always removes only one occurrence of 
  683. an element. 
  684.  
  685. For collections with keys or element equality, there are removal functions that 
  686. remove one or all occurrence(s) of a given key or element, ( remove, 
  687. removeElementWithKey, removeAllOccurrences, and removeAllElementsWithKey). 
  688. Ordered (sorted as well as sequential) collections provide functions for 
  689. removing an element at a given position given by a number or as First or Last. 
  690.  
  691. After an element has been added or removed, all cursors of the collection 
  692. become undefined (see section Cursors). Therefore, removing all elements with a 
  693. given property from a collection cannot be done efficiently, because after 
  694. removing one element with the property, the collection would have to be 
  695. searched 'from the beginning' for the next element with the property. For this 
  696. purpose, the function removeAll (predicate) is provided. Predicate is a 
  697. function that, for a given element and an optional additional argument, returns 
  698. a boolean result, indicating whether the element shall be removed or not. The 
  699. following example removes all even elements from an integer collection: 
  700.  
  701.   Boolean isEven (int const& i, void*)
  702.   { return i % 2 == 0;
  703.   }
  704.   ...
  705.     intSet.removeAll (isEven);
  706. The purpose and usage of the additional argument will be explained in section 
  707. Using Iterators. 
  708.  
  709. Collections can be modified by replacing the value of an element occurrence. 
  710. Adding and removing elements usually involves the creation or deletion of 
  711. 'nodes' or the shifting of elements within a tabular implementation, replacing 
  712. an element leaves the internal representation of collections unchanged. 
  713. Therefore, cursors of the collection do not become undefined. 
  714.  
  715. For collections that are organized according to some element properties, such 
  716. as an ordering relation or a hash function, the replace function must not 
  717. change this element property; for key collections the new key must be equal to 
  718. the old key; for non-key collections with element equality the new element must 
  719. be equal to the old element, both as defined by the equality or comparison 
  720. function provided for the key or element type, respectively. This key or 
  721. element value is called the positioning property of the element with respect to 
  722. the given collection type. As an alternative to replacing the value of an 
  723. element occurrence you can remove the old and add the new element value; this 
  724. must be done if the element's positioning property is being changed. For 
  725. sequential collections and heaps, there is no such property; element values in 
  726. sequences and heaps can be changed freely. Replacing element values involves 
  727. copying of the whole value. If only a small part of the element is to be 
  728. changed it is more efficient to use the elementAt access function that is 
  729. described in section Locating and Accessing Elements. While the replace 
  730. function checks the validity of the position property as a precondition, the 
  731. elementAt function leaves this responsibility to the programmer. 
  732.  
  733.  
  734. ΓòÉΓòÉΓòÉ 2.4.1.4. Cursors ΓòÉΓòÉΓòÉ
  735.  
  736. A cursor  is a handle to an element in a collection. It is used for several 
  737. purposes, for example to access the result of the locate function, and to 
  738. indicate the current working point for iterating over the elements of a 
  739. collection. A cursor is always associated with a collection. The collection is 
  740. specified at construction time and can not be changed later on. The association 
  741. of the collection to the cursor is used for two reasons: 
  742.  
  743. o Simple functions, in particular advancing the cursor, can be functions of the 
  744.   cursor instead of being collection functions that take the cursor as an 
  745.   argument. 
  746. o Collections that take a cursor argument can have as a precondition, that the 
  747.   cursor actually belongs to this collection; the association of the collection 
  748.   to the cursor makes the check effectively executable. Errors of using a 
  749.   cursor with a collection to which it does not belong and for which it might 
  750.   not work as expected, are otherwise hard to detect. 
  751.  
  752. Cursors are only temporarily defined: as soon as elements are being added to, 
  753. or removed from the collection, existing cursors are no longer defined. 
  754. Remember that cursors can be implemented as C++ pointers (to nodes that carry 
  755. the elements) in case of implementations that are called linked or as indices 
  756. to an array in case of implementations that are called tabular. For tabular 
  757. implementations, cursors may no longer refer to the original element occurrence 
  758. if this element is shifted with adding or removing. For this reason, if you 
  759. wish to leave the choice for a linked and a tabular implementation open, you 
  760. should not make use of a cursor after elements have been added to, or removed 
  761. from the corresponding collection. The reference manual states that, for such 
  762. functions all cursors will be undefined. If you restrict yourself to linked 
  763. implementations, this decision must be specified (documented by a comment) with 
  764. the class instantiation, so that: 
  765.  
  766. o All who use the collection class know whether they may assume this property 
  767.   or not. 
  768.  
  769. o Tailoring only chooses appropriate implementations. 
  770.  
  771. Cursors and iteration by cursors can be used with any collection. This 
  772. provides: 
  773.  
  774. o An iteration scheme that is simpler than using iterators (see Using 
  775.   Iterators). 
  776. o The ability to define functions that have cursors as output argument and 
  777.   thereby either grant fast access to an element if it exists, or indicate the 
  778.   non-existence by an invalid cursor. 
  779.  
  780. Different collection implementations use different cursor classes; linked 
  781. implementations use pointers to nodes; array implementations use numeric 
  782. indices; hash tables use an index into the hash table and a pointer to the node 
  783. in the collision list; bags based on dictionaries use the dictionary cursor and 
  784. a count for equal elements. 
  785.  
  786. Each concrete collection class, for example C, has an inner definition of a 
  787. class Cursor which can be accessed as C::Cursor. 
  788.  
  789. Since abstract classes will also declare functions on cursors, there is a base 
  790. class ICursor for these specific cursor classes. To allow the creation of 
  791. specific cursors for all kinds of collections, there is a virtual member 
  792. function newCursor for all abstract collection classes, creating an appropriate 
  793. cursor for the given collection object. 
  794.  
  795.  
  796. ΓòÉΓòÉΓòÉ 2.4.1.5. Locating and Accessing Elements ΓòÉΓòÉΓòÉ
  797.  
  798. Cursors provide a basic mechanism for accessing elements; all other access 
  799. mechanism can be reduced to first finding an appropriate cursor and then 
  800. accessing the element via this cursor. Two functions are provided for accessing 
  801. an element through a cursor: 
  802.  
  803.   const Element& elementAt (Cursor const&) const;
  804.         Element& elementAt (Cursor const&);
  805. which return a reference to an element and thereby avoid the actual element 
  806. copying within the function. Assume an element with a size of some KBytes and a 
  807. situation where you want to access a 2 Byte data member of an element pointed 
  808. to by a given cursor; you would not want to copy the element to some local 
  809. variable and then access the data member but instead, use a pointer or 
  810. reference to the element. 
  811.  
  812. There are several other functions, such as firstElement, or elementWithKey that 
  813. yield a reference to an element. They can be thought of as first executing a 
  814. corresponding cursor function, such as setToFirst or locateElementWithKey and 
  815. then accessing the element via the cursor. It is necessary to assert the 
  816. existence of the element before accessing it. If this is not known from the 
  817. context it must first be checked; in order to save the extra effort of locating 
  818. the desired element twice (once for checking whether it exists and then for 
  819. actually retrieving its reference), the cursor that results from the locate 
  820. function can be used for fast element access like this: 
  821.  
  822.   if (locateElementWithKey (key, cursor))
  823.     ... elementAt (cursor) ...
  824.  
  825. The elementAt function can also be used to replace the value of the referenced 
  826. element occurrence. The programmer is responsible for not changing the 
  827. positioning property of the element (with respect to the given collection; see 
  828. section Adding, Removing, and Replacing Elements). 
  829.  
  830.   class Task
  831.   { ...
  832.     TaskId ivId;
  833.     State ivState;
  834.     ...
  835.   };
  836.   ...
  837.   elementWithKey (tid).ivState = RUNNING;
  838.  
  839. The distinction of a constant and a non-constant elementAt function guarantees 
  840. that for a constant collection no elements can be changed via this function; 
  841. still, the constant function can be used (that means it is automatically 
  842. selected by the compiler) to gain read access to the element. 
  843.  
  844.  
  845. ΓòÉΓòÉΓòÉ 2.4.1.6. Iterating over Collections ΓòÉΓòÉΓòÉ
  846.  
  847. Iterating over all or some elements of a collection is a common pattern. The 
  848. library provides two iteration concepts: iteration by cursors and iteration by 
  849. iterators or iteration functions. 
  850.  
  851. Ordered (including sorted) collections have a well defined ordering of their 
  852. elements, while unordered collections have no defined order in which the 
  853. elements will be visited. However, it is guaranteed that each element will be 
  854. visited exactly once. 
  855.  
  856. While iterating over a collection no elements may be added to or removed from 
  857. the collection. Otherwise it is not guaranteed that all elements will be 
  858. visited once. Cursor iteration can be used to relax this rule in order to 
  859. iteratively remove all elements from the collection that have a certain 
  860. property. 
  861.  
  862.  
  863. Cursor Iteration 
  864.  
  865. Cursor iteration can be done with a for loop, for example: 
  866.  
  867.   XYCollection collection;
  868.   XYCollection::Cursor current (collection);
  869.   for (current.setToFirst (); current.isValid (); current.setToNext ())
  870.   { ... collection.elementAt (current) ...
  871.   }
  872.  
  873. One of the challenges with iteration is the removal of elements while 
  874. iterating; removing or adding elements changes the collections and implicitly 
  875. makes all cursors to the collection undefined. One could not 'remember' the 
  876. cursor of the next element, remove the current, and then proceed iteration with 
  877. the remembered cursor (think of array implementations). Therefore, the remove 
  878. function that gets as an argument a cursor pointing to the element that is to 
  879. be removed, also sets this cursor to the next element. So, an iteration 
  880. removing all elements with a certain property from an arbitrary collection 
  881. could work as follows: 
  882.  
  883.   Cursor current (collection);
  884.   for (current.setToFirst (); current.isValid ();)
  885.   { ...
  886.     if (... collection.elementAt (current) ...)
  887.       collection.removeAt (current);
  888.     else
  889.       current.setToNext ();
  890.   }
  891.  
  892. Using Iterators 
  893.  
  894. Cursor iteration may have two drawbacks: 
  895.  
  896. o For unordered collections the explicit notion of an (arbitrary) ordering may 
  897.   be undesirable for stylistic reasons. 
  898. o Iteration in an arbitrary order might be done more efficiently as with 
  899.   cursors. For example with tree representations, a recursive descent iteration 
  900.   may be faster than the cursor navigation, even though the time for extra 
  901.   function calls must be considered. 
  902.  
  903. The library provides the functions allElementsDo which address both drawbacks 
  904. by taking a function that is applied to all elements. The function returns a 
  905. boolean value which tells whether the iteration should be continued or not. For 
  906. ordered collections, the function is applied in this order, otherwise the order 
  907. is unspecified. 
  908.  
  909. The function applied in each iteration step can be given in two ways: as a C++ 
  910. function, or as an object of a so-called iterator class. The advantage of the 
  911. iterator class is that additional arguments that are needed by the iteration 
  912. function can be better encapsulated. The C++ function has an additional 
  913. argument which may be used for this purpose. In addition, for both of these 
  914. possibilities, it is distinguished whether the function leaves the element 
  915. constant or not. This gives the following four cases: 
  916.  
  917.    template < class Element >
  918.    class IIterator {
  919.    public:
  920.      virtual Boolean applyTo (Element&) = 0;
  921.    };
  922.  
  923.    template < class Element >
  924.    class IConstantIterator {
  925.    public:
  926.      virtual Boolean applyTo (Element const&) = 0;
  927.    };
  928.  
  929.    template < class Element, ... >
  930.    class <AnyCollection> {
  931.      ...
  932.      Boolean allElementsDo (Boolean (*) (Element&, void*),
  933.                             void*);
  934.      Boolean allElementsDo (Boolean (*) (Element const&, void*),
  935.                             void*) const;
  936.      Boolean allElementsDo (IIterator < Element >);
  937.      Boolean allElementsDo (IConstantIterator < Element >);
  938.    }
  939.  
  940. Using the iterator class, the programmer derives the class IIterator or 
  941. IContsantIterator, respectively, and defines the applyTo function for the 
  942. derived class. Additional arguments needed for the iteration can, for example, 
  943. be passed as constructor arguments of the derived iterator class. The 
  944. programmer defines the function with the given argument and result types. For 
  945. additional arguments it might be necessary to define a separate class or 
  946. structure. The following example adds all integers in a set, showing the usage 
  947. of both mechanisms in the case of additional arguments required. 
  948.  
  949.    typedef ISet < int > IntSet;
  950.  
  951.    class SumIterator : public IConstantIterator < int > {
  952.      int ivSum;
  953.    public:
  954.      SumIterator () : ivSum (0) {}
  955.      Boolean applyTo (int const& i) {
  956.        ivSum += i;
  957.        return True;
  958.      }
  959.      int sum () { return ivSum; }
  960.    };
  961.  
  962.    int sumUsingIterator (ISet const& set) {
  963.      SumIterator sumUp;
  964.      set.allElementsDo (sumUp);
  965.      return sumUp.sum ();
  966.    }
  967.  
  968.    Boolean sumUpFunction (int &const i, void* sum) {
  969.      *(int*)sum += i;
  970.      return True;
  971.    };
  972.  
  973.    int sumUsingFunction (ISet const& set) {
  974.      int sum = 0;
  975.      set.allElementsDo (sumUpFunction, &sum);
  976.      sum;
  977.    }
  978.  
  979.  
  980. ΓòÉΓòÉΓòÉ 2.4.1.7. Copying and Referencing Collections ΓòÉΓòÉΓòÉ
  981.  
  982. As mentioned in section Flat Collections, the library's collections implement 
  983. no structure sharing. The assignment operator and the copy constructor for 
  984. collections are defined to copy all elements of the given collection into the 
  985. assigned or constructed collection. This should be noted when using collection 
  986. types as arguments to functions: If the argument type is not a reference or 
  987. pointer type, the collection will be copied and, in particular, changes made to 
  988. the collection within the function will not 'write through' to the actual 
  989. argument; in most cases collections should therefore be passed by reference: 
  990.  
  991.    void removePrimes (ISet < int > set) { ... // wrong!
  992.    void removePrimes (ISet < int >& set) { ... // right
  993. For the same reason it is not advisable to have collection types being result 
  994. types of functions. For example: 
  995.  
  996.    ISet < int > f () {
  997.       ISet < int > result;
  998.       ...
  999.       result result;
  1000.    }
  1001.    ...
  1002.    intSet = f ();
  1003. In this program the situation would be worse: the result of f would be copied 
  1004. in a temporary which would be taken as (reference) argument to the assignment 
  1005. operation which would again copy the set. The above program should therefore 
  1006. look like this: 
  1007.  
  1008.    void f (ISet < int > &result) {
  1009.       ...
  1010.    }
  1011.    ...
  1012.    f (intSet);
  1013.  
  1014. The rationale for using collection types as argument rather than result types 
  1015. will be discussed in section Polymorphic Use of Collections. 
  1016.  
  1017.  
  1018. ΓòÉΓòÉΓòÉ 2.4.2. Exception Handling ΓòÉΓòÉΓòÉ
  1019.  
  1020. The C++ exception handling mechanism enables a program to recover from an 
  1021. 'exceptional' situation. An exceptional situation occurs within a function 
  1022. which the programmer did not or could not explicitly consider when writing a 
  1023. call to this function. 
  1024.  
  1025. There is some ambiguity in the notion of exceptional and it is left to the 
  1026. design of a class interface to define which situations are considered 
  1027. exceptional and which are considered regular. 
  1028.  
  1029. Exceptional situations can result from two major sources: 
  1030.  
  1031. o The violation of a precondition 
  1032.  
  1033. o The occurrence of an internal system failure or system restriction. 
  1034.  
  1035. A precondition of a function is a condition that the function requires to be 
  1036. true when being called. It is the caller's responsibility to assure this 
  1037. condition. The function implementation may assert that the condition holds 
  1038. without further checking it; in the case of a precondition violation, the 
  1039. function may behave in an arbitrarily negative manner, for example, overwriting 
  1040. foreign storage areas. 
  1041.  
  1042. In order to make programs more robust and to locate errors in the test phase, 
  1043. preconditions must be checked by the function. Since this checking may require 
  1044. significant overhead, it is helpful to turn it off after the system has been 
  1045. tested or even systematically verified with respect to the preconditions. The 
  1046. programmer does not 'expect' a function call to violate the function's 
  1047. precondition, so this is a typically exceptional situation. In the checked 
  1048. case, the function would throw an exception in case of a violated precondition; 
  1049. in the unchecked case, the behavior would be unpredictable. 
  1050.  
  1051. System failures and restrictions are different from preconditions. They are 
  1052. usually not anticipated by the programmer and are therefore exceptional. 
  1053. However, the programmer has no chance of verifying that such a situation, like 
  1054. storage overflow, does not occur. These exceptions should therefore be checked 
  1055. for and thrown as an exception if they occur. 
  1056.  
  1057.  
  1058. ΓòÉΓòÉΓòÉ 2.4.2.1. Precondition vs. Defined Behavior ΓòÉΓòÉΓòÉ
  1059.  
  1060. Exceptions are not generally used for 'regular' programming. For example, the 
  1061. exit from an iteration through a collection should not be implemented using an 
  1062. exception which is raised when accessing elements through an invalid cursor. It 
  1063. should, explicitly test for the cursor being valid.  In order to make this 
  1064. possible, there must be a function that efficiently tests this condition. 
  1065.  
  1066. There are situations where the test for a condition can be done more 
  1067. efficiently in combination with performing the actual function. In such cases 
  1068. it is appropriate - for performance reasons - to make the situation regular and 
  1069. return the condition as a boolean result. Consider a function that first tests 
  1070. whether an element exists with a given key and, if so, accesses it, for 
  1071. example: 
  1072.  
  1073.    if (c.containsElementWithKey (key)) {
  1074.      ...
  1075.      ... c.elementWithKey (key) ...
  1076.      ...
  1077.    } else {
  1078.      <else-part>
  1079.    }
  1080. This solution is inefficient because it does the locating twice. Consider the 
  1081. following example: 
  1082.  
  1083.    try {
  1084.      ...
  1085.      ... c.elementWithKey (key) ...
  1086.      ...
  1087.    } catch (INotContainsKeyException) {
  1088.      <else-part>
  1089.    }
  1090. This solution is undesirable because it violates the mentioned programming 
  1091. practice. The correct solution is to first obtain a cursor together with the 
  1092. containment test, and then use the cursor for a fast element access: 
  1093.  
  1094.    if (c.locateElementWithKey (key, cursor)) {
  1095.      ...
  1096.      ... elementAt (cursor) ...
  1097.      ...
  1098.    } else {
  1099.      <else-part>
  1100.    }
  1101.  
  1102.  
  1103. ΓòÉΓòÉΓòÉ 2.4.2.2. Levels of Checking ΓòÉΓòÉΓòÉ
  1104.  
  1105. There are different levels of cost versus expected benefit ratios for different 
  1106. kinds of preconditions; the precondition that a cursor for a linked collection 
  1107. implementation actually (still) points to an element of a given collection is 
  1108. rather costly (iterating over the complete collection) and would probably only 
  1109. be turned on in cases where the programmer is rather desperate; checking for an 
  1110. empty collection, however, is rather inexpensive and could be done in the 
  1111. production version. 
  1112.  
  1113. The library provides three levels of precondition checking which are selected 
  1114. by the following macro variable definitions (use, for example, compile flag 
  1115. -DINO_CHECKS): 
  1116.  
  1117. INO_CHECKS       Skip all checks except memory overflow 
  1118.  
  1119. default          Perform those checks only where the ratio of safety through 
  1120.                  checking versus its cost is high 
  1121.  
  1122. IALL_CHECKS      Perform all checks 
  1123.  
  1124.  
  1125. ΓòÉΓòÉΓòÉ 2.4.2.3. List of Exceptions ΓòÉΓòÉΓòÉ
  1126.  
  1127. Currently, the library defines the following exceptions.  Exceptions that are 
  1128. checked with IALL_CHECKS only are marked as 'optional'. 
  1129. IChildAlreadyExistsException A tree must not already contain a child at the 
  1130. position specified for the function addAsChild. 
  1131. ICursorInvalidException 
  1132.  
  1133. There are three cursor properties that may be checked for different functions 
  1134. and lead to the ICursorInvalidException: 
  1135.  
  1136. o A given cursor must always belong to the collection to which the function is 
  1137.   applied; this means it must be defined with this collection as its 
  1138.   constructor argument. This applies to every function that has a cursor as in- 
  1139.   or out-argument (add, setToFirst, locate, ...). 
  1140.  
  1141. o For functions that have a cursor as in-argument (elementAt, removeAt, 
  1142.   replaceAt, isValid function and means that the cursor actually refers to some 
  1143.   element within the collection. Invalid cursors are well-defined and are, for 
  1144.   example, the result of unsuccessful location functions. 
  1145.  
  1146. o If a cursor must be valid, the programmer can check that the cursor actually 
  1147.   points to an element that is 
  1148.  
  1149.      in the collection (see cursor function
  1150.   isValid). This check is effective and may be costly only for linked and 
  1151.   diluted implementations. 
  1152.  
  1153. IEmptyException The collection must not be empty with any function that 
  1154. accesses the first or last element (firstElement, removeFirstElement, ...). 
  1155. IFullException A bounded collection must not be full already with any function 
  1156. that adds an element (add, addAsFirst, ...). 
  1157. IIdenticalCollectionException The receiving collection must not be the same as 
  1158. the From-collection  with function addAllFrom. 
  1159. IKeyAlreadyExistsException A unique key collection must not already contain a 
  1160. different element with the same key, with any function that adds an element 
  1161. (add, addAllFrom, ...). 
  1162. INotBoundedException The collection must be bounded for the function 
  1163. maxNumberOfElements. 
  1164. INotContainsKeyException The element with the specified key must be contained 
  1165. in the collection, for the function elementWithKey.  . 
  1166. IOutOfMemory IOutOfMemory exceptions are not the result of a precondition 
  1167. violation. They can occur during any function that adds something  (add, 
  1168. addAsFirst, ...). 
  1169. IPositionInvalidException That the position specified is valid in the 
  1170. collection, is a precondition for any function that specifies a position  ( 
  1171. elementAtPosition, removeAtPosition, setToPosition, ...). 
  1172. IRootAlreadyExistsException A tree must not already have a root when the 
  1173. function addAsRoot is called.  This is equivalent to the precondition that the 
  1174. tree must be empty. 
  1175.  
  1176.  
  1177. ΓòÉΓòÉΓòÉ 2.4.2.4. The Hierarchy of Exceptions ΓòÉΓòÉΓòÉ
  1178.  
  1179.  
  1180. IException
  1181.   |
  1182. .
  1183. .
  1184. .
  1185.   |
  1186.   |-- IPreconditionViolation
  1187.   |     |-- IChildAlreadyExistsException
  1188.   |     |-- ICursorInvalidException
  1189.   |     |-- IEmptyException
  1190.   |     |-- IFullException
  1191.   |     |-- IIdenticalCollectionException
  1192.   |     |-- IKeyAlreadyExistsException
  1193.   |     |-- INotBoundedException
  1194.   |     |-- INotContainsKeyException
  1195.   |     |-- IPositionInvalidException
  1196.   |     |-- IRootAlreadyExistsException
  1197.   |
  1198. .
  1199. .
  1200. .
  1201.   |
  1202.   |-- IResourceExhausted
  1203.   |     |
  1204.   |     |-- IOutOfMemory
  1205.   |     |
  1206. .
  1207. .
  1208. .
  1209.  
  1210. IException offers the following functions that return information on the 
  1211. exception: 
  1212. unsigned long  errorId() The ID of the error is returned. 
  1213. unsigned int  isRecoverable() 1 is returned, if the exception is deemed to be 
  1214. recoverable, 0 if it is not. 
  1215. const char*  name() The name of the exception class is returned. 
  1216. const char*  text(unsigned long indexFromTop = 0) A text string with additional 
  1217. information about the exception is returned.  There is a stack of text strings. 
  1218. Index 0, the top of the stack, is the default for argument indexFromTop. 
  1219. unsigned long  textCount() The number of levels of message text in the 
  1220. exception message stack is returned. 
  1221.  
  1222.  
  1223. ΓòÉΓòÉΓòÉ 2.4.3. Required Functions of Elements and Keys ΓòÉΓòÉΓòÉ
  1224.  
  1225.  
  1226. ΓòÉΓòÉΓòÉ 2.4.3.1. Defining Element Functions ΓòÉΓòÉΓòÉ
  1227.  
  1228. Functions of the collection classes call other functions to determine their 
  1229. element and key types. For example, they use the element's assignment or copy 
  1230. constructors for adding an element, or they use the element's equality operator 
  1231. for locating an element in the collection. In addition, they use memory 
  1232. management functions for the allocation and deallocation of dynamically created 
  1233. internal objects (nodes). 
  1234.  
  1235. Element functions that may be required are: 
  1236.  
  1237. o default and copy constructor, 
  1238. o destructor, 
  1239. o assignment, 
  1240. o equality test, 
  1241. o ordering relation, 
  1242. o key access, and 
  1243. o hash function. 
  1244. Key functions that may be required are: 
  1245.  
  1246. o equality test, 
  1247. o ordering relation, and 
  1248. o hash function. 
  1249. Memory management functions are: 
  1250.  
  1251. o allocation 
  1252. o deallocation 
  1253. The element/key functions can be provided in three different ways, allowing 
  1254. three different levels of flexibility and tailoring. 
  1255.  
  1256.  
  1257. Using Standard Operators 
  1258.  
  1259. The easiest way is to use the element/key's standard operators. This is the 
  1260. only way for constructors and destructors. For assignment, equality and 
  1261. ordering relation, the operators =, ==, and < are used, respectively. This 
  1262. function is not applicable for key access, hash function and memory management. 
  1263. It is important that the argument types are defined as const except for the 
  1264. first assignment argument, or in case of class member functions, that the 
  1265. functions are defined to be const for the class; missing consts will result in 
  1266. compile errors. 
  1267.  
  1268.    void          operator=  (Element&, Element const&);
  1269.    Boolean       operator== (Element const&, Element const&);
  1270.    long          operator<  (Element const&, Element const&);
  1271. or 
  1272.  
  1273.    class Element
  1274.    { void          operator=  (Element const&);
  1275.      Boolean       operator== (Element const&) const;
  1276.      long          operator<  (Element const&) const;
  1277.    };
  1278.  
  1279.  
  1280. Using Separate Functions 
  1281.  
  1282. The second level uses the following functions, which may be defined by the 
  1283. programmer; the previously described function works by providing a default 
  1284. (template) definition for these functions: 
  1285.  
  1286.    void          assign  (Element&, Element const&);
  1287.  
  1288.    Boolean       equal   (Element const&, Element const&);
  1289.    long          compare (Element const&, Element const&);
  1290.    Key const&    key     (Element const&);
  1291.    unsigned long hash    (Element const&);
  1292.    Boolean       equal   (Key const&, Key const&);
  1293.    long          compare (Key const&, Key const&);
  1294.    unsigned long hash    (Key const&);
  1295. as well as the standard memory management functions 
  1296.  
  1297.    void*         operator new (size_t);
  1298.    void          operator delete (void*);
  1299. The default definition for the compare function uses two comparisons with 
  1300. operator<. It is therefore advisable to (re-)define the compare function if the 
  1301. given element type has a more efficient implementation available. Such 
  1302. definitions are already provided for integer types, using operator- and for 
  1303. char* using strcmp. By default, the standard memory management functions are 
  1304. being used. 
  1305.  
  1306. The second level will be used, in particular, if the programmer who 
  1307. instantiates the collection class has no control over the element class and the 
  1308. element class does not define the appropriate functions. It is also the most 
  1309. convenient way for providing key access and hash function: 
  1310.  
  1311.   typedef unsigned long TaskId;
  1312.   typedef int Priority;
  1313.   class Task
  1314.   { TaskId ivId;
  1315.     Priority ivPriority;
  1316.   public:
  1317.     TaskId   id ()       { return ivId; }
  1318.     Priority priority () { return ivPriority; }
  1319.     ...
  1320.   };
  1321.   ...
  1322.   TaskId key (Task const& t)
  1323.   { return t.id (); }
  1324.   ...
  1325.   IKeySet <Task, TaskId> runningTasks;
  1326.  
  1327.  
  1328. Using Element Operation Classes 
  1329.  
  1330. For each collection class there is an argument that takes a class defining all 
  1331. required element/key operations. By default, a class is used that defines these 
  1332. operations via the corresponding element/key functions. The advantage of 
  1333. passing the arguments via an extra class instead of passing them as function 
  1334. pointers is that the class solution allows, (and mostly in fact uses) inlining. 
  1335. Collection classes with the operation class argument are called IG..., for 
  1336. example, IGSequence. Programmers may define such classes themselves and pass 
  1337. them to the IG... templates. This may, in particular, be useful in cases where, 
  1338. for two different instantiations of (maybe different) collections with the same 
  1339. element or key type, two different key or hash functions shall be used. 
  1340.  
  1341. Operation classes look as follows, where the keyOps member must only be present 
  1342. for key collections: 
  1343.  
  1344.   class ...Ops
  1345.   { void*         allocate     (size_t);
  1346.     void          deallocate   (void*);
  1347.     void          assign       (Element&, Element const&);
  1348.  
  1349.     Boolean       equal        (Element const&, Element const&);
  1350.     long          compare      (Element const&, Element const&);
  1351.     Key const&    key          (Element const&);
  1352.     unsigned long hash         (Element const&);
  1353.  
  1354.     class KeyOps
  1355.     { Boolean       equal        (Key const&, Key const&);
  1356.       long          compare      (Key const&, Key const&);
  1357.       unsigned long hash         (Key const&);
  1358.     } keyOps;
  1359.   };
  1360. For defining operation classes, the following class templates may be used which 
  1361. define a single function that calls the corresponding non-member function. 
  1362. Templates with argument type T may be used for both the element and the key 
  1363. type. 
  1364.  
  1365.   class IStdMemOps
  1366.   { void* allocate (size_t);
  1367.     void deallocate (void*);
  1368.   };
  1369.  
  1370.   template < class T >
  1371.   class IStdAsOps
  1372.   { void assign (T&, T const&);
  1373.   };
  1374.  
  1375.   template < class T >
  1376.   class IStdEqOps
  1377.   { Boolean equal (T const&, T const&);
  1378.   };
  1379.  
  1380.   template < class T >
  1381.   class IStdCmpOps
  1382.   { long compare (T const&, T const&);
  1383.   };
  1384.  
  1385.   template < class Element, class Key >
  1386.   class IStdKeyOps
  1387.   { Key const& key (Element const&);
  1388.   };
  1389.  
  1390.   template < class T >
  1391.   class IStdHshOps
  1392.   { unsigned long hash (T const&);
  1393.   };
  1394.  
  1395. In order to define an operation class, use the predefined templates for 
  1396. standard functions and define the specific functions 'by hand'. As an example, 
  1397. consider tasks that have an identifier and a priority. The identifier might 
  1398. serve as the key in a collection that keeps track of all active tasks, while 
  1399. the priority might be used for implementing priority controlled task queues. 
  1400. Since the key function is already defined to yield the task identifier, the 
  1401. priority queue would have to be instantiated like this: 
  1402.  
  1403.   class TaskPrioOps : public IStdMemOps,
  1404.                       public IStdAsOps < Task >,
  1405.   { Priority key (Task const& t)
  1406.     { returnt.priority (); }
  1407.  
  1408.     IStdCmpOps < int > keyOps;
  1409.   };
  1410.   ...
  1411. IGPriorityQueue < Task, Priority, TaskPrioOps > taskPriorityQueue;
  1412.  
  1413. The functions that are required for a certain collection class depends not only 
  1414. on the abstract class but also on the concrete implementation choice. If you 
  1415. choose a set to be implemented through a hash table, the elements require a 
  1416. hash function;if you choose a (sorted) AVL tree implementation, elements need a 
  1417. comparison function. Even the default implementations may require more 
  1418. functions to be provided than would be necessary for the logic of the 
  1419. collection interface; The reference manual defines which functions must be 
  1420. provided for keys and elements for each implementation choice; for the default 
  1421. implementation (for example IGSet), a default operation class is provided 
  1422. (IGSetOps). This class may be used as a base class for deriving a specific 
  1423. class with non-standard element or key functions. The following example uses 
  1424. the standard sequence operations but provides a non-standard memory manager: 
  1425.  
  1426.   class MySeqOps : public ISequenceOps < MyElement >
  1427.   { void* allocate   (size_t s) {...}
  1428.     void  deallocate (void* p)  {...}
  1429.   };
  1430.  
  1431.   class MyElementSeq : public IGSequence < MyElement, MySeqOps >
  1432.   {...};
  1433.  
  1434. Note that the instantiation of the default collection operations will cause the 
  1435. standard key and element functions to be instantiated; these functions or 
  1436. operators must be defined even though they are redefined in the derived class. 
  1437.  
  1438.  
  1439. ΓòÉΓòÉΓòÉ 2.4.3.2. Values vs. (Managed) Objects ΓòÉΓòÉΓòÉ
  1440.  
  1441. C++ is a 'value-oriented' language due to its origination and compatibility 
  1442. with C. This means that unless otherwise stated, variables, and function 
  1443. arguments and results have their value (contents) copied when assigned. 
  1444. Pointers or references are used for the common object semantics, which means 
  1445. copying just a pointer or reference to the object, thus enabling polymorphic 
  1446. applications through virtual functions. Pointers to elements can be used as 
  1447. collection element types in such cases, because references are not allowed as 
  1448. collection element types. For KeySets, this procedure works fine (note that the 
  1449. key function is defined with argument type Task*): 
  1450.  
  1451.   class Task
  1452.   { ...
  1453.   };
  1454.   TaskId const& key (Task* const& t) { return t.ivId; }
  1455.   IKeySet < Task*, int > tasks;
  1456.  
  1457. For collections with element equality, the situation is not as simple. 
  1458. Instantiating the collection template with the element pointer type will result 
  1459. in applying pointer assignment and comparison for the elements which is, in 
  1460. general, not intended. In the following example, adding, locating and other 
  1461. functions would be based on pointer equality and, possible, ordering, and not 
  1462. the equality defined for the Task type. 
  1463.  
  1464.   class Task
  1465.   { TaskId ivId;
  1466.     ...
  1467.     Boolean operator== (Task const& t)
  1468.     { return ivId == t.ivId; }
  1469.   };
  1470.   ISet < Task* > tasks;
  1471.  
  1472. For the 'simulation' of references to elements, the library has the template 
  1473. class IRef, which is instantiated with the element type. IRefs are constructed 
  1474. (or converted) from an element pointer and can be converted to element 
  1475. references. 
  1476.  
  1477.   typedef IRef < Task > TaskRef;
  1478.   ISet < TaskRef > taskSet;
  1479.   TaskRef t1 (new Task);
  1480.   taskSet.add (t1);
  1481.   ...
  1482.   taskSet.remove (t1);
  1483.   delete &t1;
  1484.  
  1485. Note that the dynamically created elements are not automatically deleted when 
  1486. they are removed from the collection. For managed references that provide 
  1487. automatic garbage collection see section Garbage Collection. 
  1488.  
  1489.  
  1490. ΓòÉΓòÉΓòÉ 2.4.3.3. Garbage Collection ΓòÉΓòÉΓòÉ
  1491.  
  1492. The class IMgRef implements a reference class as defined in the previous 
  1493. section together with garbage collection for the referenced element. Garbage 
  1494. collection is implemented by reference counting; its proper behaviour requires 
  1495. that the pointer to the element from which the reference is initially 
  1496. constructed is no longer used. 
  1497.  
  1498.   typedef IMgRef < Task > TaskRef;
  1499.   ISet < TaskRef > tasks;
  1500.   TaskRef t1 (new Task);
  1501.   tasks.add (t1);
  1502.   ...
  1503.   tasks.remove (t1);
  1504. In the example, the allocated task will automatically be deleted within the 
  1505. remove function unless it is referenced through another TaskRef; in this case 
  1506. it will be removed when it is referenced by no other TaskRef. 
  1507.  
  1508. Garbage collection is particularly useful when functions return pointers or 
  1509. references to objects that they have created (dynamically allocated) and the 
  1510. 'last user' of the object is responsible for cleaning up. The class IMgRef can 
  1511. also be used for this purpose. 
  1512.  
  1513.  
  1514. ΓòÉΓòÉΓòÉ 2.4.3.4. Functions for Derived Element Classes ΓòÉΓòÉΓòÉ
  1515.  
  1516. Due to the C++ language rule that states function template instantiations to be 
  1517. considered before conversions, element functions like equal or compare defined 
  1518. for some classes will not be considered for a derived class; the default 
  1519. template functions will be instantiated instead: 
  1520.  
  1521.   class A
  1522.   { ...
  1523.   };
  1524.   long compare (A const&, A const&);
  1525.   class B : public A
  1526.   { ...
  1527.   };
  1528.   ISortedSet < B > BSet;
  1529. The example will instantiate the default compare function for B which uses the 
  1530. operator< of B, if defined, or otherwise reports it as an error. To get the 
  1531. intended behavior, standard functions like equal or compare must be 
  1532. (re-)defined for the actual element type. 
  1533.  
  1534. IRef classes cope with this problem by using an extra indirection, to make an 
  1535. instantiation like ISet < IRef < Task > > use the right functions. This 
  1536. indirection is, in general, transparent to the programmer, but must be 
  1537. considered when deriving from the IRef class. The standard operation classes 
  1538. first apply a function elementForOps to the element before they apply the 
  1539. corresponding non-member (equal, ...) function. By default, a corresponding 
  1540. template function is instantiated for elementForOps which yields the identity. 
  1541. For IRef (and similar classes) this function is defined to yield the referenced 
  1542. element instead. Note, that if a class derived from IRef < E > is used as 
  1543. collection element type, the default template functions must be instantiated 
  1544. before a conversion will be considered; a derived class will therefore have to 
  1545. explicitly redefine the elementForOps function: 
  1546.  
  1547.   class TaskRef : public IRef < Task >
  1548.   { Task& elementForOps ()
  1549.     { return IRef < Task >::elementForOps (); }
  1550.     Task const& elementForOps () const
  1551.     { return IRef < Task >::elementForOps (); }
  1552.   };
  1553.   Set < TaskRef > taskSet;
  1554.  
  1555.  
  1556. ΓòÉΓòÉΓòÉ 2.4.4. Tailoring a Collection Implementation ΓòÉΓòÉΓòÉ
  1557.  
  1558. Section Instantiation and Object Definition introduced the instantiation of the 
  1559. collections' default implementations. The library suggests a development 
  1560. methodology that starts with the default implementation for all (or most) 
  1561. collections, and ends with a final tuning or tailoring phase where 
  1562. implementations are chosen, according to the actual needs. These needs can, for 
  1563. example, be derived with profiling or other measurement tools. This section 
  1564. will describe how to choose and possibly compose implementation classes. 
  1565.  
  1566. As described in section The Overall Implementation Structure, each data 
  1567. abstraction has several possible implementations. Some of these concrete 
  1568. classes are basic, like the AVL trees, hash tables, or linked and tabular 
  1569. sequences, others are based on other collection classes, like the bag. 
  1570. Exchanging the default implementation with a basic implementation is simple. If 
  1571. you want to use an AVL tree for the implementation of a particular class, say 
  1572. MyType that is a map and has been defined with a default implementation IKeySet 
  1573. you can just replace 
  1574.  
  1575.    typedef IKeySet < Element, Key > MyType;
  1576. by 
  1577.  
  1578.    typedef IAvlKeySet < Element, Key > MyType;
  1579.  
  1580. If the implementation that you choose is based on some other collection, you 
  1581. must first choose this collection and then use it to instantiate the based 
  1582. collection. This mechanism will be outlined in the following section. 
  1583.  
  1584.  
  1585. ΓòÉΓòÉΓòÉ 2.4.4.1. The Based-On Concept ΓòÉΓòÉΓòÉ
  1586.  
  1587. In order to achieve a high degree of implementation choice flexibility, several 
  1588. collection class implementations are based on another abstract class, rather 
  1589. than implemented directly by a concrete implementation variant of this class. 
  1590.  
  1591. For choosing a concrete implementation, like a Set based on a KeySorted Set 
  1592. based on a Tabular Sequence, these class templates have to be 'plugged 
  1593. together'.  The plug mechanism requires class templates being used as template 
  1594. arguments; unfortunately, C++ does not allow this.  Therefore, the library 
  1595. simulates the plug mechanism by macros.  Two macros are needed: one for 
  1596. defining a template with an additional function class argument (see section 
  1597. Defining Element Functions), and one for defining a template with just the 
  1598. element and, possibly, key types as arguments. 
  1599.  
  1600. The element functions that are needed by a particular implementation may depend 
  1601. on all collection class templates that participate in the implementation. 
  1602. While ISet requires at least element equality to be defined, an AVL tree 
  1603. implementation of this set will require the element type to provide a 
  1604. comparison function, and a hash table implementation will require the element 
  1605. type to have a hash function. Standard function class templates are predefined 
  1606. which can be used for defining particular collection implementations. Their 
  1607. names are systematically derived from the operations they define. The name 
  1608. structure is: I<elem-ops>[K<key-ops>]Ops, where <elem-ops> and <key-ops> are a 
  1609. sequence of letters E for equality, C for comparison, and H for hashing. 
  1610. IEKEHOps, for example, is an operation template providing, besides the basic 
  1611. memory management and element assignment operations, element equality, and key 
  1612. equality and hashing. 
  1613.  
  1614.   IDefineSetOnKeySortedSet (IGAvlKeySortedSet, IGAvlSet)
  1615.   IDefineCollectionWithOps (IGAvlSet, IECOps, IAvlSet)
  1616. The first of these defines a Set class template named IGAvlSet as based on a 
  1617. KeySorted Set class template IGAvlKeySortedSet.  The second defines a Set class 
  1618. template named IAvlSet as the Set class template IGAvlSet with the element and 
  1619. key functions specified with IECOps. 
  1620.  
  1621.  
  1622. Together with the definition of IECOps this expands to: 
  1623.  
  1624.   template < class Element, class ElementOps >
  1625.   class IGAvlSet :
  1626.     public IGAvlKeySortedSet < Element, Element,
  1627.                                IOpsWithKey < Element, ElementOps > >
  1628.   { ... constructor redefinition
  1629.   };
  1630.   template < class Element >
  1631.   class IECOps : public IStdMemOps,
  1632.                  public IStdAsOps < Element >,
  1633.                  public IStdEqOps < Element >,
  1634.                  public IStdCmpOps < Element >
  1635.   {
  1636.   };
  1637.   template < class Element >
  1638.   class IAvlSet : public IGAvlSet < Element, IECOps < Element > >
  1639.   { ... constructor redefinition
  1640.   };
  1641. For multilevel based-on implementations, the same mechanism is applied as 
  1642. follows: 
  1643.  
  1644.   IDefineGKeySortedSetOnGSequence
  1645.     (IGLinkedSequence, IGKeySortedSetOnLnkSeq)
  1646.   IDefineGSetOnGKeySortedSet
  1647.     (IGKeySortedSetOnLnkSeq, IGSetOnSortedLnkSeq)
  1648.   IDefineCollectionWithOps
  1649.     (IGSetOnSortedLnkSeq, IECOps, ISetOnSortedLnkSeq)
  1650.  
  1651.  
  1652. ΓòÉΓòÉΓòÉ 2.4.4.2. Provided Implementation Variants ΓòÉΓòÉΓòÉ
  1653.  
  1654.  reftype=hd."Figure: Possible Implementation Paths" contains the basic and 
  1655. based implementations provided by the library. The upper left corner of each 
  1656. entry contains the name of the (abstract) collection class; basic 
  1657. implementations are written in bold letters while based implementations are 
  1658. described by arrows starting from the class which they implement and ending in 
  1659. the (abstract) class on which they are based. An implementation choice for a 
  1660. given class must use either a basic implementation for this class or follow a 
  1661. based implementation path which ultimately leads to a basic implementation. 
  1662. For ease of use, and for the avoidance of very long (mangled) names, the based 
  1663. implementations denoted by non-bold arrows are provided as shortcuts. 
  1664.  
  1665. Take the example of the Bag abstraction.  The Bag is not implemented directly. 
  1666. It can only be based on the KeySet abstraction, which itself is either 
  1667. implemented directly with a HashTable or can be based on the KeySorted Set. 
  1668. The KeySorted Set is either directly implemented as Avl Tree or B* Tree or can 
  1669. be based on the Sequence abstraction.  The Sequence is implemented directly as 
  1670. a linked or tabular undiluted or tabular diluted data structure, into which is 
  1671. inserted keeping the elements sorted. 
  1672.  
  1673.  
  1674. PossibleImplementationPaths
  1675.  
  1676.  
  1677. ΓòÉΓòÉΓòÉ 2.4.5. Implementation Classes and Include Files ΓòÉΓòÉΓòÉ
  1678.  
  1679.  
  1680. Following is the list of provided abstract classes and their implementations. 
  1681. The first mentioned implementation for each abstract class is the current 
  1682. default. The default implementation is defined as a template with the given 
  1683. name and can be accessed through the include files specified for each abstract 
  1684. class; the corresponding template with additional operation class argument is 
  1685. called IG... instead of I..., for example template classes IMap and IGMap are 
  1686. defined in include file imap.h as based on KeySortedSet. Knowledge about the 
  1687. implementation classes, their names and their include files is only necessary 
  1688. for selecting alternative implementations as described in section The Based-On 
  1689. Concept. 
  1690.  
  1691.  
  1692.  
  1693. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  1694. Γöé CLASS NAME       Γöé INCLUDE     Γöé DESCRIPTION                   Γöé
  1695. Γöé                  Γöé FILE        Γöé                               Γöé
  1696. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1697. Γöé IMap             Γöé imap.h      Γöé based on AVL KeySortedSet     Γöé
  1698. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1699. Γöé  IWMapOnKSSet    Γöé imapkss.h   Γöé based on KeySortedSet         Γöé
  1700. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1701. Γöé  IWMapOnKeySet   Γöé imapks.h    Γöé based on KeySet               Γöé
  1702. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1703. Γöé IRelation        Γöé irel.h      Γöé based on Hash table KeyBag    Γöé
  1704. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1705. Γöé  IWRelOnKeyBag   Γöé imapks.h    Γöé based on KeyBag               Γöé
  1706. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1707. Γöé IKeySet          Γöé ikeyset.h   Γöé based on AVL KeySortedSet     Γöé
  1708. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1709. Γöé  IWKeySetOnKSSet Γöé ikskss.h    Γöé based on KeySortedSet         Γöé
  1710. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1711. Γöé  IGHashKeySet    Γöé ihshks.h    Γöé Hash table for KeySet (basic) Γöé
  1712. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1713. Γöé IKeyBag          Γöé ikeybag.h   Γöé Hash table for KeyBag         Γöé
  1714. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1715. Γöé  IGHashKeyBag    Γöé ihshkb.h    Γöé Hash table for KeyBag (basic) Γöé
  1716. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1717. Γöé ISet             Γöé iset.h      Γöé based on AVL KeySortedSet     Γöé
  1718. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1719. Γöé  IWSetOnKSSet    Γöé isetkss.h   Γöé based on KeySortedSet         Γöé
  1720. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1721. Γöé  IWSetOnKeySet   Γöé isetks.h    Γöé based on KeySet               Γöé
  1722. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1723. Γöé IBag             Γöé ibag.h      Γöé based on AVL KeySortedSet     Γöé
  1724. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1725. Γöé  IWBagOnKSSet    Γöé ibagkss.h   Γöé based on KeySortedSet         Γöé
  1726. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1727. Γöé ISortedMap       Γöé isrtmap.h   Γöé based on AVL KeySortedSet     Γöé
  1728. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1729. Γöé  IWSrtMapOnKSSet Γöé ismkss.h    Γöé based on KeySortedSet         Γöé
  1730. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1731. Γöé ISortedRelation  Γöé isrtrel.h   Γöé based on KeySortedBag on      Γöé
  1732. Γöé                  Γöé             Γöé LinkedSequence                Γöé
  1733. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1734. Γöé  IWSrtRelOnKSBag Γöé isrksb.h    Γöé based on KeySortedBag         Γöé
  1735. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1736. Γöé IKeySortedSet    Γöé iksset.h    Γöé AVL tree for KeySortedSet     Γöé
  1737. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1738. Γöé                  Γöé iavlkss.h   Γöé AVL tree for KeySortedSet     Γöé
  1739. Γöé IGAvlKeySortedSetΓöé             Γöé (basic)                       Γöé
  1740. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1741. Γöé IKeySortedBag    Γöé iksbag.h    Γöé based on LinkedSequence       Γöé
  1742. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1743. Γöé  IWKSBagOnSeq    Γöé iksbseq.h   Γöé based on Sequence             Γöé
  1744. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1745. Γöé ISortedSet       Γöé isrtset.h   Γöé based on AVL KeySortedSet     Γöé
  1746. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1747. Γöé  IWSSetOnKSSet   Γöé isskss.h    Γöé based on KeySortedSet         Γöé
  1748. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1749. Γöé ISortedBag       Γöé isrtbag.h   Γöé based on AVL KeySortedSet     Γöé
  1750. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1751. Γöé  IWSrtBagOnKSSet Γöé isbkss.h    Γöé based on KeySortedSet         Γöé
  1752. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1753. Γöé IEqualitySequenceΓöé ieqseq.h    Γöé based on LinkedSequence       Γöé
  1754. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1755. Γöé  IWEqSeqOnSeq    Γöé iesseq.h    Γöé based on Sequence             Γöé
  1756. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1757. Γöé ISequence        Γöé iseq.h      Γöé linked sequence               Γöé
  1758. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1759. Γöé  ILinkedSequence Γöé ilnseq.h    Γöé linked sequence (basic)       Γöé
  1760. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1761. Γöé                  Γöé itbseq.h    Γöé tabular sequence (basic)      Γöé
  1762. Γöé ITabularSequence Γöé             Γöé                               Γöé
  1763. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1764. Γöé                  Γöé itdseq.h    Γöé tabular diluted sequence      Γöé
  1765. Γöé IDilutedSequence Γöé             Γöé (basic)                       Γöé
  1766. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1767. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  1768.  
  1769.  
  1770. ΓòÉΓòÉΓòÉ 2.4.6. Polymorphic Use of Collections ΓòÉΓòÉΓòÉ
  1771.  
  1772. Polymorphism allows the programmer to take an abstract view on an object or 
  1773. function argument and accept any concrete objects or arguments that are 
  1774. specialized (derived) from this abstract view. The collection properties 
  1775. defined in section Flat Collections serve to define such abstract views. They 
  1776. are represented in the form of a class hierarchy that is illustrated in 
  1777. "Figure: The abstract class hierarchy". 
  1778.  
  1779. Each abstract class is defined by its functions and their behavior. The most 
  1780. abstract view of a collection is a container without any ordering or any 
  1781. specific element or key properties. A heap is a concrete implementation of just 
  1782. this abstract view. Elements can be added to a collection and a collection can 
  1783. be iterated over. Collections whose elements define equality or key equality 
  1784. provide, in addition to the common collection functions, functions for 
  1785. retrieving element occurrences by a given element or key value. Ordered 
  1786. collections provide the notion of a well-defined ordering of the element 
  1787. occurrences, either by an element ordering relation or by explicit positioning 
  1788. of elements within a sequence. They define operations for positional element 
  1789. access. Sorted collections provide no further functions, but define a more 
  1790. specific behavior, namely that the elements or their keys are sorted. 
  1791.  
  1792. These properties are combined through so-called multiple inheritance: the 
  1793. abstract collection class IEqualitySortedCollection, for example, combines the 
  1794. abstract concepts of element equality and of being sorted which implies being 
  1795. ordered. 
  1796.  
  1797. For performance reasons that were explained in section The Overall 
  1798. Implementation Structure the concrete collection classes are not directly 
  1799. derived from the abstract classes. Instead, the programmer must use an 
  1800. indirection that 'couples' a concrete collection with an abstract class. Users 
  1801. of concrete classes need not pay the runtime (and partly even codesize) 
  1802. overhead that comes with abstract class hierarchies. For each leaf in the 
  1803. collection class hierarchy, for example, ISet there is such an indirection 
  1804. class template called IRSet (see "Figure: Overall library structure"). It takes 
  1805. as template arguments the element type and, for key collections, the key type 
  1806. and a concrete collection class that has been instantiated with this element 
  1807. and key type. Instances of this indirection class refer to instances of the 
  1808. concrete collection class (the R in IRSet stands for 'reference'). The IR... 
  1809. classes are derived from the corresponding abstract IA... classes and are 
  1810. therefore part of the C++ class hierarchy. Instances of this class can be used 
  1811. wherever an instance (pointer or reference) of an abstract base class is 
  1812. required. 
  1813.  
  1814.   class TaskPrinter {
  1815.   public:
  1816.     print (IACollection < Task* > const& tasks)
  1817.     { cout << "ID     ..."
  1818.       ICursor *cursor = tasks.newCursor ();
  1819.       forCursor (*cursor)
  1820.       { Task* task = tasks.elementAt (*cursor);
  1821.         cout << task->id() << ...
  1822.       }
  1823.     }
  1824.   };
  1825.   ...
  1826.   typedef IKeySet < Task*, int > TaskSet;
  1827.   TaskSet running;
  1828.   ...
  1829.   IRKeySet < Task*, TaskSet > refRunning (running);
  1830.   TaskPrinter.print (refRunning);
  1831.  
  1832.  
  1833. ΓòÉΓòÉΓòÉ 3. Reference Manual - Flat Collections ΓòÉΓòÉΓòÉ
  1834.  
  1835. This part contains detailed descriptions of the flat collections of the  IBM 
  1836. Class Library: Collection Classes for reference. 
  1837.  
  1838. It starts with a chapter containing a list of all functions available in 
  1839. alphabetical order. This chapter contains all information relevant for each 
  1840. function. 
  1841.  
  1842. You will notice that the classes have many member functions in common. For 
  1843. example most classes have an addElement and  removeElement function. 
  1844. So instead of describing the same function over and over again for each class 
  1845. you will find each function described in detail in All Functions. 
  1846.  
  1847. For each class you will find 
  1848.  
  1849. o ... an abstract. E.g. what is a set or what is a tree. 
  1850.  
  1851. o ... 
  1852.  
  1853. o ... 
  1854.  
  1855. o ... a summary of all functions. 
  1856.  
  1857. o ... an example. 
  1858.  
  1859.  
  1860. ΓòÉΓòÉΓòÉ 3.1. All Functions ΓòÉΓòÉΓòÉ
  1861.  
  1862. This chapter lists all functions in alphabetical order. 
  1863.  
  1864. At the beginning, you will find an explanation of some of the terms used. 
  1865.  
  1866.  
  1867. ΓòÉΓòÉΓòÉ 3.1.1. Terms Used ΓòÉΓòÉΓòÉ
  1868.  
  1869. this collection     is the collection on which a function is applied. As 
  1870.                     opposed to the given collection. 
  1871.  
  1872. given collection    is a collection given as a function argument. 
  1873.  
  1874. given element       is an element given as a function argument. 
  1875.  
  1876. returned element    is an element returned as a function return value. 
  1877.  
  1878. positioning property the property of an element which is used to poition the 
  1879.                     element in a collection. E.g. the value of the whole 
  1880.                     element or the value of the key. 
  1881.  
  1882. iteration order     the order in which elements are visited in allElementsDo 
  1883.                     and setToNext or setToPrevious. 
  1884.                     In SORTED collections elements are visited following there 
  1885.                     positioning property. 
  1886.                     In ORDERED collections the element at position 1 will be 
  1887.                     visited first, then element at postion 2, etc.. (ORDERED 
  1888.                     collection are not necessarily SORTED!). 
  1889.                     In collections that are not ORDERED the ELEMENTS are 
  1890.                     visited in an arbitrary order. Each element is visited 
  1891.                     exactly once. 
  1892.  
  1893.  
  1894. ΓòÉΓòÉΓòÉ 3.1.2. List of Functions ΓòÉΓòÉΓòÉ
  1895.  
  1896.  
  1897. ΓòÉΓòÉΓòÉ 3.1.2.1. add ΓòÉΓòÉΓòÉ
  1898.  
  1899.  Boolean add (Element const&);
  1900.  Boolean add (Element const&,ICursor&);
  1901. If the collection has UNIQUE ELEMENTS and the element is already contained in 
  1902. the collection, set the cursor to the existing element in the collection and do 
  1903. not add the element. Otherwise, add the element to the collection and set the 
  1904. cursor to the added element. In SEQUENTIAL collections, 
  1905.  
  1906.  the given element is added as the last element.
  1907. In SORTED collections, the element is added at a position determined by the 
  1908. element or key value. 
  1909. ReturnValue: True if the element was added. 
  1910. Side Effect: If an element was added all cursors of this collection, except the 
  1911. given cursor, become undefined. 
  1912. Precondition: 
  1913.  
  1914. o The cursor must belong to the collection.. 
  1915. o If BOUNDED and UNIQUE: 
  1916.   Element exists or numberOfElements < maxNumberOfElements 
  1917. o If BOUNDED and NON UNIQUE: 
  1918.   NumberOfElements < maxNumberOfElements. 
  1919. o If UNIQUE KEY: 
  1920.   If the collection contains some element with the same key as the given 
  1921.   element, then this element must be equal to the given element. 
  1922. o If MAPPING: 
  1923.   If the collection contains some element with the same key as the given 
  1924.   element, then this element must be equal to the given element. 
  1925.  
  1926. Exceptions: 
  1927.  
  1928. o IMemoryExhaustedException 
  1929. o ICursorInvalidException 
  1930. o If BOUNDED: IFullException 
  1931. o If MAPPING: IKeyAlreadyExistsException 
  1932.  
  1933.  
  1934. ΓòÉΓòÉΓòÉ 3.1.2.2. addAllFrom ΓòÉΓòÉΓòÉ
  1935.  
  1936.  void addAllFrom (CLASS_NAME const&);
  1937.  void addAllFrom (IACollection <Element> const&);
  1938. Add (copy) all elements of the given collection to the collection. The sequence 
  1939. in which the elements are copied is according to the definition off 
  1940. allElementsDo of the given collection. The elements are added according to the 
  1941. definition of add for this collection. 
  1942. Side Effect: If some elements were actually added all cursors of this 
  1943. collection would become undefined. 
  1944. Precondition: See preconditions of add. 
  1945.  
  1946. The collection may not be the same as the given collection. I.e. you can't copy 
  1947. a collection to itself. 
  1948. Exceptions: 
  1949.  
  1950. o IMemoryExhaustedException 
  1951. o IIdenticalCollectionException 
  1952. o If BOUNDED: IFullException 
  1953. o If MAPPING: IKeyAlreadyExistsException 
  1954.  
  1955.  
  1956. ΓòÉΓòÉΓòÉ 3.1.2.3. addAsFirst ΓòÉΓòÉΓòÉ
  1957.  
  1958.  void addAsFirst (Element const&);
  1959.  void addAsFirst (Element const&,ICursor&);
  1960. Add the element to the collection as the first element in sequential order. Set 
  1961. the cursor to the added element. 
  1962. Side Effect: All cursors of this collection, except the given cursor, become 
  1963. undefined. 
  1964. Precondition: The cursor must belong to the collection. 
  1965. If BOUNDED: 
  1966. numberOfElements < maxNumberOfElements. 
  1967. Exceptions: 
  1968.  
  1969. o ICursorInvalidException 
  1970. o IMemoryExhaustedException 
  1971. o If BOUNDED: IFullException 
  1972.  
  1973.  
  1974. ΓòÉΓòÉΓòÉ 3.1.2.4. addAsLast ΓòÉΓòÉΓòÉ
  1975.  
  1976.  void addAsLast (Element const&);
  1977.  void addAsLast (Element const&,ICursor&);
  1978. Add the element to the collection as the last element in sequential order. Set 
  1979. the cursor to the added element. 
  1980. Side Effect: All cursors of this collection, except the given cursor, become 
  1981. undefined. 
  1982. Precondition: The cursor must belong to the collection. 
  1983. If BOUNDED: 
  1984. numberOfElements < maxNumberOfElements. 
  1985. Exceptions: 
  1986.  
  1987. o ICursorInvalidException 
  1988. o IMemoryExhaustedException 
  1989. o If BOUNDED: IFullException 
  1990.  
  1991.  
  1992. ΓòÉΓòÉΓòÉ 3.1.2.5. addAsNext ΓòÉΓòÉΓòÉ
  1993.  
  1994.  void addAsNext (Element const&,ICursor&);
  1995. Add the element to the collection as the element which is in sequential order 
  1996. next to the element pointed to by the cursor. Set the cursor to the added 
  1997. element. 
  1998. Side Effect: If the element was actually added all cursors of this collection, 
  1999. except the given cursor, become undefined. 
  2000. Precondition: If BOUNDED: The cursor must belong to the collection. 
  2001. numberOfElements < maxNumberOfElements. 
  2002. Exceptions: 
  2003.  
  2004. o IMemoryExhaustedException 
  2005. o ICursorInvalidException 
  2006. o If BOUNDED: IFullException 
  2007.  
  2008.  
  2009. ΓòÉΓòÉΓòÉ 3.1.2.6. addAsPrevious ΓòÉΓòÉΓòÉ
  2010.  
  2011.  void addAsPrevious (Element const&,ICursor&);
  2012. Add the element to the collection as the element which, in sequential order is 
  2013. previous to the element pointed to by the cursor. Set the cursor to the added 
  2014. element. 
  2015. Side Effect: If the element was actually added all cursors of this collection, 
  2016. except the given cursor, would become undefined. 
  2017. Precondition: The cursor must belong to the collection. 
  2018. If BOUNDED: 
  2019. numberOfElements < maxNumberOfElements. 
  2020. Exceptions: 
  2021.  
  2022. o IMemoryExhaustedException 
  2023. o ICursorInvalidException 
  2024. o If BOUNDED: IFullException 
  2025.  
  2026.  
  2027. ΓòÉΓòÉΓòÉ 3.1.2.7. addAtPosition ΓòÉΓòÉΓòÉ
  2028.  
  2029.  void addAtPosition (IPosition,Element const&);
  2030.  void addAtPosition (IPosition,Element const&,ICursor&);
  2031. Add the element at the given position to the collection. If an element exists 
  2032. at the given position, the new element will be added as the previous element to 
  2033. the existing element. Set the cursor to the added element. 
  2034. Position 1 specifies the first element. 
  2035. Side Effect: All cursors of this collection become undefined. 
  2036. Precondition: 
  2037.  
  2038. o The cursor must belong to the collection. 
  2039. o 1 <= position <= numberOfElements + 1 
  2040. o If BOUNDED: numberOfElements < maxNumberOfElements 
  2041.  
  2042. Exceptions: 
  2043.  
  2044. o IMemoryExhaustedException 
  2045. o ICursorInvalidException 
  2046. o IPositionInvalidException 
  2047. o If BOUNDED: IFullException 
  2048.  
  2049.  
  2050. ΓòÉΓòÉΓòÉ 3.1.2.8. addDifference ΓòÉΓòÉΓòÉ
  2051.  
  2052.  void addDifference (CLASS_NAME const&,CLASS_NAME const&);
  2053. Create the difference between the two given collections and add this difference 
  2054. to the collection. 
  2055. (See definition of difference at differenceWith.) 
  2056. Side Effect: If some elements are added all cursors of this collection become 
  2057. undefined. 
  2058. Precondition: See preconditions of add. 
  2059. Exceptions: 
  2060.  
  2061. o IMemoryExhaustedException 
  2062. o If BOUNDED: IFullException 
  2063. o If MAPPING: IKeyAlreadyExistsException 
  2064.  
  2065.  
  2066. ΓòÉΓòÉΓòÉ 3.1.2.9. addIntersection ΓòÉΓòÉΓòÉ
  2067.  
  2068.  void addIntersection (CLASS_NAME const&,CLASS_NAME const&);
  2069. Create the intersection of the two given collections and add this intersection 
  2070. to the collection. 
  2071. (See definition of intersection at intersectionWith.) 
  2072. Side Effect: If some elements were added all cursors of this collection become 
  2073. undefined. 
  2074. Precondition: See preconditions of add. 
  2075. Exceptions: 
  2076.  
  2077. o IMemoryExhaustedException 
  2078. o If BOUNDED: IFullException 
  2079. o If MAPPING: IKeyAlreadyExistsException 
  2080.  
  2081.  
  2082. ΓòÉΓòÉΓòÉ 3.1.2.10. addOrReplaceElementWithKey ΓòÉΓòÉΓòÉ
  2083.  
  2084.  Boolean addOrReplaceElementWithKey (Element const&);
  2085.  Boolean addOrReplaceElementWithKey (Element const&,ICursor&);
  2086. If there is an element contained in the collection where the key is equal to 
  2087. the key of the given element, set the cursor to this element in the collection 
  2088. and replace it with the given element. Otherwise, add the given element to the 
  2089. collection and set the cursor to the added or replaced element. 
  2090. ReturnValue: True if the element was added. 
  2091. Side Effect: If the element was added all cursors of this collection, except 
  2092. the given cursor, would become undefined. 
  2093. Precondition: The cursor must belong to the collection. 
  2094. If BOUNDED: 
  2095. an element with the given key is contained in the collection or 
  2096. numberOfElements < maxNumberOfElements. 
  2097. Exceptions: 
  2098.  
  2099. o IMemoryExhaustedException 
  2100. o ICursorInvalidException 
  2101. o If BOUNDED: IFullException 
  2102.  
  2103.  
  2104. ΓòÉΓòÉΓòÉ 3.1.2.11. addUnion ΓòÉΓòÉΓòÉ
  2105.  
  2106.  void addUnion (CLASS_NAME const&,CLASS_NAME const&);
  2107. Create the union of the two given collections and add this union to the 
  2108. collection. 
  2109. (See definition of union at unionWith.) 
  2110. Side Effect: If some elements were actually added all cursors of this 
  2111. collection become undefined. 
  2112. Precondition: See preconditions of add. 
  2113. Exceptions: 
  2114.  
  2115. o IMemoryExhaustedException 
  2116. o If BOUNDED: IFullException 
  2117. o If MAPPING: IKeyAlreadyExistsException 
  2118.  
  2119.  
  2120. ΓòÉΓòÉΓòÉ 3.1.2.12. allElementsDo ΓòÉΓòÉΓòÉ
  2121.  
  2122.  Boolean allElementsDo (IConstantIterator <Element>&) const;
  2123. Call the applyTo function of the given iterator for all elements of the 
  2124. collection until the applyTo function returns false. The elements are visited 
  2125. in iteration order. 
  2126. Note: The applyTo function must not remove or add elements of the collection. 
  2127. ReturnValue: True if the applyTo function returns true for every element it is 
  2128. applied to. 
  2129.  
  2130.  
  2131. ΓòÉΓòÉΓòÉ 3.1.2.13. allElementsDo ΓòÉΓòÉΓòÉ
  2132.  
  2133.  Boolean allElementsDo (Boolean (*function) (Element const&, void*),
  2134.                         void* additionalArgument)const;
  2135. Call the given function for all elements in the collection until the given 
  2136. function returns false. The elements are visited in iteration order. Additional 
  2137. arguments can be passed to the given function using additionalArgument. 
  2138. Note: The given function may not remove or add elements to the collection. 
  2139. ReturnValue: True if the given function returns true for every element it is 
  2140. applied to. 
  2141.  
  2142.  
  2143. ΓòÉΓòÉΓòÉ 3.1.2.14. allElementsDo ΓòÉΓòÉΓòÉ
  2144.  
  2145.  Boolean allElementsDo (IIterator <Element>&);
  2146. Call the applyTo function of the given iterator for all elements of the 
  2147. collection until the applyTo function returns false. The elements are visited 
  2148. in iteration order. 
  2149. Additional arguments can be passed to the applyTo function using the 
  2150. additionalArgument. 
  2151. Note: The applyTo function may not remove or add elements from or to the 
  2152. collection. 
  2153. The applyTo must not manipulate the element in the collection in a way, that 
  2154. changes the positioning property of the element. 
  2155. ReturnValue: True if the applyTo function returns true for every element it is 
  2156. applied to. 
  2157.  
  2158.  
  2159. ΓòÉΓòÉΓòÉ 3.1.2.15. allElementsDo ΓòÉΓòÉΓòÉ
  2160.  
  2161.  Boolean allElementsDo (Boolean (*function) (Element&, void*),
  2162.                         void* additionalArgument);
  2163. Call the given function to all elements in the collection until the given 
  2164. function returns false. The elements are visited in iteration order. Additional 
  2165. arguments can be passed to the given function using the additionalArgument. 
  2166. Note: The given function may not remove or add elements to or from the 
  2167. collection. 
  2168. The given function must not manipulate the element in the collection in a way 
  2169. that changes the positioning property of the element. 
  2170. ReturnValue: True if the given function returns true for every element it is 
  2171. applied to. 
  2172.  
  2173.  
  2174. ΓòÉΓòÉΓòÉ 3.1.2.16. anyElement ΓòÉΓòÉΓòÉ
  2175.  
  2176.  Element const& anyElement () const;
  2177. Returns (a constant reference to) any element of the collection. 
  2178. Precondition: The collection must not be empty. 
  2179. Exceptions: IEmptyException 
  2180.  
  2181.  
  2182. ΓòÉΓòÉΓòÉ 3.1.2.17. compare ΓòÉΓòÉΓòÉ
  2183.  
  2184.  long compare (CLASS_NAME const&, long (*comparisonFunction)
  2185.                               ( Element const&,Element const&)) const;
  2186. Lexicographically compare the collection with the given collection. Comparison 
  2187. yields: <0 if the collection is less than the given collection, 0 if the 
  2188. collection is equal to the given collection, and >0 if the collection is 
  2189. greater than the given collection. Lexicographic comparison is defined by the 
  2190. first pair of corresponding elements in both collections that are not equal. If 
  2191. no such pair exists, the collection with more elements is the greater one; 
  2192. otherwise the collection with the greater element of the pair is the greater 
  2193. one. 
  2194. Note: The comparisonFunction must deliver: >0 if element1 > element2, 0 if 
  2195. element1 == element2, <0 if element1 < element2. 
  2196. ReturnValue: Result of the comparison. 
  2197.  
  2198.  
  2199. ΓòÉΓòÉΓòÉ 3.1.2.18. Constructor ΓòÉΓòÉΓòÉ
  2200.  
  2201.  CLASS_BASE_NAME (INumber numberOfElements = 100, IBoundIndicator = IUnbounded);
  2202. Construct a collection. The boundIndicator determines whether the collection is 
  2203. bounded or unbounded. NumberOfElements is the estimated or maximum number of 
  2204. elements contained in the collection, depending on whether the collection is 
  2205. bounded or unbounded, respectively. The collection is initially empty. 
  2206. Note: It is undefined whether any elements are constructed with the collection 
  2207. constructor. For some classes the element's default constructor may be invoked. 
  2208. Exceptions: IMemoryExhaustedException 
  2209.  
  2210.  
  2211. ΓòÉΓòÉΓòÉ 3.1.2.19. contains ΓòÉΓòÉΓòÉ
  2212.  
  2213.  Boolean contains (Element const&) const;
  2214. Return true if the given element is contained in the collection. 
  2215.  
  2216.  
  2217. ΓòÉΓòÉΓòÉ 3.1.2.20. containsAllFrom ΓòÉΓòÉΓòÉ
  2218.  
  2219.  Boolean containsAllFrom (CLASS_NAME const&) const;
  2220.  Boolean containsAllFrom (IACollection <Element> const&) const;
  2221. Return true if all the elements of the given collection are contained in the 
  2222. collection. 
  2223.  
  2224.  
  2225. ΓòÉΓòÉΓòÉ 3.1.2.21. containsAllKeysFrom ΓòÉΓòÉΓòÉ
  2226.  
  2227.  Boolean containsAllKeysFrom (CLASS_NAME const&) const;
  2228.  Boolean containsAllKeysFrom (IACollection <Element> const&) const;
  2229. Return true if all the keys of the given collection are contained in the 
  2230. collection. 
  2231.  
  2232.  
  2233. ΓòÉΓòÉΓòÉ 3.1.2.22. containsElementWithKey ΓòÉΓòÉΓòÉ
  2234.  
  2235.  Boolean containsElementWithKey (Key const&) const;
  2236. Return true if the given key is contained in the collection. 
  2237.  
  2238.  
  2239. ΓòÉΓòÉΓòÉ 3.1.2.23. copy ΓòÉΓòÉΓòÉ
  2240.  
  2241.  void copy (IACollection <Element> const&);
  2242. Copy the given collection to the collection (that means reset the collection 
  2243. and add the elements from the given collection). 
  2244. Note: The given collection may be of another (concrete) type than the 
  2245. collection itself; in this case, copying implicitly performs a conversion. If, 
  2246. for example, the given collection is a Bag and the collection itself is a Set, 
  2247. elements with multiple occurrences in the copied Bag will only occur once in 
  2248. the resulting Set. 
  2249. Side Effect: All cursors of this collection become undefined. 
  2250. Precondition: See preconditions of add. 
  2251. Exceptions: 
  2252.  
  2253. o IMemoryExhaustedException 
  2254. o If BOUNDED: IFullException 
  2255. o If UNIQUE KEYS: IKeyAlreadyExistsException 
  2256.   This exception may be thrown, for example, when copying a bag into a set. 
  2257.  
  2258.  
  2259. ΓòÉΓòÉΓòÉ 3.1.2.24. Copy Constructor ΓòÉΓòÉΓòÉ
  2260.  
  2261.  CLASS_BASE_NAME (CLASS_NAME const&);
  2262. Construct the collection and copy all elements from the given collection into 
  2263. the collection. 
  2264. Exceptions: IMemoryExhaustedException 
  2265.  
  2266.  
  2267. ΓòÉΓòÉΓòÉ 3.1.2.25. dequeue ΓòÉΓòÉΓòÉ
  2268.  
  2269.  void dequeue ();
  2270.  void dequeue (Element&);
  2271. Copy the first element of the collection to the given element, if any, and 
  2272. remove it from the collection. 
  2273. Side Effect: All cursors of this collection become undefined. 
  2274. Precondition: The collection must not be empty 
  2275. Exceptions: IEmptyException 
  2276.  
  2277.  
  2278. ΓòÉΓòÉΓòÉ 3.1.2.26. Destructor ΓòÉΓòÉΓòÉ
  2279.  
  2280.  ~CLASS_BASE_NAME ();
  2281. Remove all elements from the collection. 
  2282. Side Effect: All cursors of the collection become undefined. 
  2283.  
  2284.  
  2285. ΓòÉΓòÉΓòÉ 3.1.2.27. differenceWith ΓòÉΓòÉΓòÉ
  2286.  
  2287.  void differenceWith (CLASS_NAME const&);
  2288. Make the collection the difference of the collection and the given collection. 
  2289. Note: The difference of A and B (A minus B) is the set of elements which are 
  2290. members of A but not of B. 
  2291.  
  2292. The following rules apply for Bags with duplicate elements: If bag P contains 
  2293. the element el-x m times and bag Q contains the element el-x n times, then the 
  2294. difference of P and Q contains the element el-x m-n times if m is greater than 
  2295. n, and zero times if m is equal to or smaller than n. 
  2296. Side Effect: If some elements were actually removed, all cursors of this 
  2297. collection become undefined. 
  2298.  
  2299.  
  2300. ΓòÉΓòÉΓòÉ 3.1.2.28. elementAt ΓòÉΓòÉΓòÉ
  2301.  
  2302.  Element& elementAt (ICursor const&);
  2303. Returns (a reference to) the element pointed to by the given cursor. 
  2304. Note: Do not manipulate the element in the collection in a way that may change 
  2305. the positioning property of the element (e.g. do not manipulate the key of an 
  2306. element). 
  2307. Precondition: The cursor must belong to the collection and the cursor must 
  2308. point to an element of the collection. 
  2309. Exceptions: ICursorInvalidException 
  2310.  
  2311.  
  2312. ΓòÉΓòÉΓòÉ 3.1.2.29. elementAt ΓòÉΓòÉΓòÉ
  2313.  
  2314.  Element const& elementAt (ICursor const&) const;
  2315. Returns (a constant reference to) the element pointed to by the given cursor. 
  2316. Precondition: The cursor must belong to the collection and the cursor must 
  2317. point to an element of the collection. 
  2318. Exceptions: ICursorInvalidException 
  2319.  
  2320.  
  2321. ΓòÉΓòÉΓòÉ 3.1.2.30. elementAtPosition ΓòÉΓòÉΓòÉ
  2322.  
  2323.  Element const& elementAtPosition (IPosition) const;
  2324. Returns (a constant reference to) the element at the given position in the 
  2325. collection. Position 1 specifies the first element. 
  2326. Precondition: The cursor must belong to the collection and the cursor must 
  2327. point to an element of the collection. 
  2328. Exceptions: IPositionInvalidException 
  2329.  
  2330.  
  2331. ΓòÉΓòÉΓòÉ 3.1.2.31. elementWithKey ΓòÉΓòÉΓòÉ
  2332.  
  2333.  Element& elementWithKey (Key const&);
  2334. Returns (a reference to) an element specified by the key. 
  2335. Note: Do not manipulate the element in the collection in a way that changes the 
  2336. positioning property of the element (example: do not change the key of an 
  2337. element). 
  2338. If there are several elements with the given key, an arbitrary one is returned. 
  2339. Precondition: The given key is contained in the collection. 
  2340. Exceptions: IKeyNotContainedException 
  2341.  
  2342.  
  2343. ΓòÉΓòÉΓòÉ 3.1.2.32. elementWithKey ΓòÉΓòÉΓòÉ
  2344.  
  2345.  Element const& elementWithKey (Key const&) const;
  2346. Returns (a constant reference to) an element specified by the key. 
  2347. Note If there are several elements with the given key, an arbitrary one is 
  2348. returned. 
  2349. Precondition: The given key is contained in the collection. 
  2350. Exceptions: IKeyNotContainedException 
  2351.  
  2352.  
  2353. ΓòÉΓòÉΓòÉ 3.1.2.33. enqueue ΓòÉΓòÉΓòÉ
  2354.  
  2355.  void enqueue (Element const&);
  2356.  void enqueue (Element const&,ICursor&);
  2357. Add the element to the collection and set the cursor to the added element. For 
  2358. ordinary QUEUES the given element is added as the last element. For PRIORITY 
  2359. QUEUES the element is added at a position determined by the element or key 
  2360. value. 
  2361. Side Effect: All cursors of this collection, except the given cursor, would 
  2362. become undefined. 
  2363. Precondition: 
  2364.  
  2365. o The cursor must belong to the collection.. 
  2366. o If BOUNDED: 
  2367.   numberOfElements < maxNumberOfElements. 
  2368.  
  2369. Exceptions: 
  2370.  
  2371. o IMemoryExhaustedException 
  2372. o ICursorInvalidException 
  2373. o If BOUNDED: IFullException 
  2374.  
  2375.  
  2376. ΓòÉΓòÉΓòÉ 3.1.2.34. firstElement ΓòÉΓòÉΓòÉ
  2377.  
  2378.  Element const& firstElement () const;
  2379. Returns (a constant reference to) the first element of the collection. 
  2380. Precondition: The collection must not be empty. 
  2381. Exceptions: IEmptyException 
  2382.  
  2383.  
  2384. ΓòÉΓòÉΓòÉ 3.1.2.35. intersectionWith ΓòÉΓòÉΓòÉ
  2385.  
  2386.  void intersectionWith (CLASS_NAME const&);
  2387. Make the collection the intersection of the collection and the given 
  2388. collection. 
  2389. Note: The intersection of A and B is the set of elements which are members of 
  2390. both A and B. 
  2391.  
  2392. The following rules apply for Bags with duplicate elements: If bag P contains 
  2393. the element el-x m times and bag Q contains the element el-x n times, then the 
  2394. intersection of P and Q contains the element el-x MIN(m,n) times. 
  2395. Side Effect: If some elements are actually removed, all cursors of this 
  2396. collection would become undefined. 
  2397.  
  2398.  
  2399. ΓòÉΓòÉΓòÉ 3.1.2.36. isBounded ΓòÉΓòÉΓòÉ
  2400.  
  2401.  Boolean isBounded () const;
  2402. Return true if the collection is bounded. 
  2403.  
  2404.  
  2405. ΓòÉΓòÉΓòÉ 3.1.2.37. isEmpty ΓòÉΓòÉΓòÉ
  2406.  
  2407.  Boolean isEmpty () const;
  2408. Return true if the collection is empty. 
  2409.  
  2410.  
  2411. ΓòÉΓòÉΓòÉ 3.1.2.38. isFirst ΓòÉΓòÉΓòÉ
  2412.  
  2413.  Boolean isFirst (ICursor const&) const;
  2414. Return true if the element pointed to by cursor is the first element of the 
  2415. collection. 
  2416. Precondition: The cursor must belong to the collection and the cursor must 
  2417. point to an element of the collection. 
  2418. Exceptions: ICursorInvalidException 
  2419.  
  2420.  
  2421. ΓòÉΓòÉΓòÉ 3.1.2.39. isFull ΓòÉΓòÉΓòÉ
  2422.  
  2423.  Boolean isFull () const;
  2424. Return true if the collection is bounded and contains the maximum number of 
  2425. elements, i.e. if numberOfElements == maxNumberOfElements. 
  2426.  
  2427.  
  2428. ΓòÉΓòÉΓòÉ 3.1.2.40. isLast ΓòÉΓòÉΓòÉ
  2429.  
  2430.  Boolean isLast (ICursor const&) const;
  2431. Return true if the element pointed to by cursor is the last element of the 
  2432. collection. 
  2433. Precondition: The cursor must belong to the collection and the cursor must 
  2434. point to an element of the collection. 
  2435. Exceptions: ICursorInvalidException 
  2436.  
  2437.  
  2438. ΓòÉΓòÉΓòÉ 3.1.2.41. lastElement ΓòÉΓòÉΓòÉ
  2439.  
  2440.  Element const& lastElement () const;
  2441. Returns (a constant reference to) the last element of the collection. 
  2442. Precondition: The collection must not be empty 
  2443. Exceptions: IEmptyException 
  2444.  
  2445.  
  2446. ΓòÉΓòÉΓòÉ 3.1.2.42. locate ΓòÉΓòÉΓòÉ
  2447.  
  2448.  Boolean locate (Element const&, ICursor&) const;
  2449. Locate an element in the collection which is equal to the given element. Set 
  2450. the cursor to point to the element in the collection, or invalidate the cursor 
  2451. if no such element exists. 
  2452. ReturnValue: True if an element was found. 
  2453. Precondition: The cursor must belong to the collection. 
  2454. Exceptions: ICursorInvalidException 
  2455.  
  2456.  
  2457. ΓòÉΓòÉΓòÉ 3.1.2.43. locateElementWithKey ΓòÉΓòÉΓòÉ
  2458.  
  2459.  Boolean locateElementWithKey (Key const&, ICursor&) const;
  2460. Locate an element in the collection with the given key. Set the cursor to point 
  2461. to the element in the collection. or invalidate the cursor if no such element 
  2462. exists. 
  2463. ReturnValue: True if an element was found. 
  2464. Precondition: The cursor must belong to the collection. 
  2465. Exceptions: ICursorInvalidException 
  2466.  
  2467.  
  2468. ΓòÉΓòÉΓòÉ 3.1.2.44. locateFirst ΓòÉΓòÉΓòÉ
  2469.  
  2470.  Boolean locateFirst (Element const&, ICursor&) const;
  2471. Locate the first element in iteration order in the collection which is equal to 
  2472. the given element. Set the cursor to the located element, or invalidate the 
  2473. cursor if no such element exists. 
  2474. ReturnValue: True if an element was found. 
  2475. Precondition: The cursor must belong to the collection. 
  2476. Exceptions: ICursorInvalidException 
  2477.  
  2478.  
  2479. ΓòÉΓòÉΓòÉ 3.1.2.45. locateLast ΓòÉΓòÉΓòÉ
  2480.  
  2481.  Boolean locateLast (Element const&, ICursor&) const;
  2482. Locate the last element in iteration order in the collection which is equal to 
  2483. the given element. Set the cursor to the located element, or invalidate the 
  2484. cursor if no such element exists. 
  2485. ReturnValue: True if an element was found. 
  2486. Precondition: The cursor must belong to the collection. 
  2487. Exceptions: ICursorInvalidException 
  2488.  
  2489.  
  2490. ΓòÉΓòÉΓòÉ 3.1.2.46. locateNext ΓòÉΓòÉΓòÉ
  2491.  
  2492.  Boolean locateNext (Element const&, ICursor&) const;
  2493. Locate the next element in iteration order in the collection which is equal to 
  2494. the given element starting at the element pointed to by the given cursor. Set 
  2495. the cursor to point to the element in the collection. The cursor is invalidated 
  2496. if no more occurrences of the given element are left to be visited. 
  2497. Note: For unordered collections, the elements are visited in some order that is 
  2498. not further defined. 
  2499. ReturnValue: True if the cursor is valid. 
  2500. Precondition: The cursor must belong to the collection. 
  2501. Exceptions: ICursorInvalidException 
  2502.  
  2503.  
  2504. ΓòÉΓòÉΓòÉ 3.1.2.47. locateNextElementWithKey ΓòÉΓòÉΓòÉ
  2505.  
  2506.  Boolean locateNextElementWithKey (Key const&, ICursor&) const;
  2507. Locate the next element in iteration order in the collection with the given key 
  2508. starting at the element pointed to by the given cursor. Set the cursor to point 
  2509. to the element in the collection. The cursor is invalidated if no more 
  2510. occurrences of such an element are left to be visited. 
  2511. Note: For unordered collections, the elements are visited in some order that is 
  2512. not further defined. 
  2513. ReturnValue: True if the cursor is valid. 
  2514. Precondition: The cursor must belong to the collection. 
  2515. Exceptions: ICursorInvalidException 
  2516.  
  2517.  
  2518. ΓòÉΓòÉΓòÉ 3.1.2.48. locateOrAdd ΓòÉΓòÉΓòÉ
  2519.  
  2520.  Boolean locateOrAdd (Element const&);
  2521.  Boolean locateOrAdd (Element const&, ICursor&);
  2522. Locate an element in the collection which is equal to the given element. If 
  2523. such an element is not contained add it. The cursor is set to the located or, 
  2524. respectively, added element. 
  2525. Note: This method is more efficient then using a locate followed by a 
  2526. conditional add. 
  2527. ReturnValue: True if the element was located (was already there). 
  2528. Side Effect: If the element was actually added, all cursors of this collection 
  2529. except the given cursor become undefined. 
  2530. Precondition: See preconditions of add, if the element is to be added. 
  2531. The cursor must belong to the collection. 
  2532. Exceptions: 
  2533.  
  2534. o IMemoryExhaustedException 
  2535. o ICursorInvalidException 
  2536. o If BOUNDED: IFullException 
  2537. o If MAPPING: IKeyAlreadyExistsException 
  2538.  
  2539.  
  2540. ΓòÉΓòÉΓòÉ 3.1.2.49. locateOrAddElementWithKey ΓòÉΓòÉΓòÉ
  2541.  
  2542.  Boolean locateOrAddElementWithKey (Element const&);
  2543.  Boolean locateOrAddElementWithKey (Element const&, ICursor&);
  2544. Locate any element in the collection with the given key. If such an element is 
  2545. not contained add it. The cursor is set to the located or, respectively, added 
  2546. element. 
  2547. ReturnValue: True if an element with the given key was contained and could be 
  2548. located 
  2549. Side Effect: If the element was added, all cursors of this collection except 
  2550. the given cursor become undefined. 
  2551. Precondition: If BOUNDED and an element with the given key is not already 
  2552. contained then numberOfElements < maxNumberOfElements. 
  2553. The cursor must belong to the collection. 
  2554. Exceptions: 
  2555.  
  2556. o IMemoryExhaustedException 
  2557. o ICursorInvalidException 
  2558. o If BOUNDED: IFullException 
  2559.  
  2560.  
  2561. ΓòÉΓòÉΓòÉ 3.1.2.50. locatePrevious ΓòÉΓòÉΓòÉ
  2562.  
  2563.  Boolean locatePrevious (Element const&, ICursor&) const;
  2564. Locate the previous element in iteration order in the collection which is equal 
  2565. to the given element starting at the element previous to the one specified by 
  2566. the given cursor. Set the cursor to the located element. The cursor is 
  2567. invalidated if no such element was found. 
  2568. ReturnValue: True if an element was found. 
  2569. Precondition: The cursor must belong to the collection and the cursor must 
  2570. point to an element of the collection. 
  2571. Exceptions: ICursorInvalidException 
  2572.  
  2573.  
  2574. ΓòÉΓòÉΓòÉ 3.1.2.51. maxNumberOfElements ΓòÉΓòÉΓòÉ
  2575.  
  2576.  INumber maxNumberOfElements () const;
  2577. Return the number of elements the collection can contain at most. 
  2578. Precondition: The collection is bounded. 
  2579. Exceptions: INotBoundedException 
  2580.  
  2581.  
  2582. ΓòÉΓòÉΓòÉ 3.1.2.52. newCursor ΓòÉΓòÉΓòÉ
  2583.  
  2584.  ICursor* newCursor () const;
  2585. Create a cursor for the collection. The cursor is initially invalid. 
  2586. ReturnValue: Pointer to the cursor. 
  2587. Exceptions: IMemoryExhaustedException 
  2588.  
  2589.  
  2590. ΓòÉΓòÉΓòÉ 3.1.2.53. numberOfDifferentElements ΓòÉΓòÉΓòÉ
  2591.  
  2592.  INumber numberOfDifferentElements () const;
  2593. Return the number of different elements in the collection. 
  2594.  
  2595.  
  2596. ΓòÉΓòÉΓòÉ 3.1.2.54. numberOfDifferentKeys ΓòÉΓòÉΓòÉ
  2597.  
  2598.  INumber numberOfDifferentKeys () const;
  2599. Return the number of different keys in the collection. 
  2600.  
  2601.  
  2602. ΓòÉΓòÉΓòÉ 3.1.2.55. numberOfElements ΓòÉΓòÉΓòÉ
  2603.  
  2604.  INumber numberOfElements () const;
  2605. Return the number of elements the collection contains. 
  2606.  
  2607.  
  2608. ΓòÉΓòÉΓòÉ 3.1.2.56. numberOfElementsWithKey ΓòÉΓòÉΓòÉ
  2609.  
  2610.  INumber numberOfElementsWithKey (Key const&) const;
  2611. Return the number of elements in the collection with the given key. collection. 
  2612.  
  2613.  
  2614. ΓòÉΓòÉΓòÉ 3.1.2.57. numberOfOccurrences ΓòÉΓòÉΓòÉ
  2615.  
  2616.  INumber numberOfOccurrences (Element const&) const;
  2617. Return the number of occurrences of the given element in the collection. 
  2618.  
  2619.  
  2620. ΓòÉΓòÉΓòÉ 3.1.2.58. operator != ΓòÉΓòÉΓòÉ
  2621.  
  2622.  Boolean operator != (CLASS_NAME const&) const;
  2623. Return true if the given collection is not equal to the collection. (See 
  2624. description of operator ==) 
  2625.  
  2626.  
  2627. ΓòÉΓòÉΓòÉ 3.1.2.59. operator = ΓòÉΓòÉΓòÉ
  2628.  
  2629.  CLASS_NAME& operator = (CLASS_NAME const&);
  2630. Copy the given collection to the collection (that means reset the collection 
  2631. and add the elements from the given collection). 
  2632. ReturnValue: (A reference to) the collection. 
  2633. Side Effect: All cursors of this collection become undefined. 
  2634. Precondition: See preconditions of add. 
  2635. Exceptions: 
  2636.  
  2637. o IMemoryExhaustedException 
  2638. o If BOUNDED: IFullException 
  2639.  
  2640.  
  2641. ΓòÉΓòÉΓòÉ 3.1.2.60. operator == ΓòÉΓòÉΓòÉ
  2642.  
  2643.  Boolean operator == (CLASS_NAME const&) const;
  2644. Return true if the given collection is equal to the collection. Two collections 
  2645. are equal: 
  2646.  
  2647. If the number of elements in the collections are the same and ... 
  2648.  
  2649. If UNIQUE ELEMENTS: If an element occurs in the collection it must occur in the 
  2650.                given collection and vice versa. 
  2651. If NON UNIQUE ELEMENTS: If an element has N occurrences in the collection it 
  2652.                must have exactly N occurrences in the given collection and vice 
  2653.                versa. 
  2654. If SEQUENTIAL: the ordering of the elements is the same for both collections. 
  2655.  
  2656.  
  2657. ΓòÉΓòÉΓòÉ 3.1.2.61. pop ΓòÉΓòÉΓòÉ
  2658.  
  2659.  void pop ();
  2660.  void pop (Element&);
  2661. Copies the last element of the collection to the given element, if any, and 
  2662. removes it from the collection. 
  2663. Side Effect: All cursors of this collection become undefined. 
  2664. Precondition: The collection must not be empty 
  2665. Exceptions: IEmptyException 
  2666.  
  2667.  
  2668. ΓòÉΓòÉΓòÉ 3.1.2.62. push ΓòÉΓòÉΓòÉ
  2669.  
  2670.  void push (Element const&);
  2671.  void push (Element const&, ICursor&);
  2672. Add the element to the collection as the last element and set the cursor to the 
  2673. added element. 
  2674. Side Effect: All cursors of this collection except the given cursor become 
  2675. undefined. 
  2676. Precondition: 
  2677.  
  2678. o The cursor must belong to the collection.. 
  2679. o If BOUNDED: 
  2680.   numberOfElements < maxNumberOfElements. 
  2681.  
  2682. Exceptions: 
  2683.  
  2684. o IMemoryExhaustedException 
  2685. o ICursorInvalidException 
  2686. o If BOUNDED: IFullException 
  2687.  
  2688.  
  2689. ΓòÉΓòÉΓòÉ 3.1.2.63. remove ΓòÉΓòÉΓòÉ
  2690.  
  2691.  Boolean remove (Element const&);
  2692. Remove an element in the collection which is equal to the given element. In 
  2693. collections with NON UNIQUE ELEMENTS and arbitrary occurrence of the given 
  2694. element will be removed. 
  2695. ReturnValue: True if an element was actually removed 
  2696. Side Effect: If an element was actually removed, all cursors of this collection 
  2697. become undefined. 
  2698.  
  2699.  
  2700. ΓòÉΓòÉΓòÉ 3.1.2.64. removeAll ΓòÉΓòÉΓòÉ
  2701.  
  2702.  void removeAll ();
  2703. Removes all elements from the collection. 
  2704. Side Effect: All cursors of this collection become undefined. 
  2705.  
  2706.  
  2707. ΓòÉΓòÉΓòÉ 3.1.2.65. removeAll ΓòÉΓòÉΓòÉ
  2708.  
  2709.  INumber removeAll (Boolean (*property) (Element const&));
  2710. Removes all elements from this collection for which the given property function 
  2711. return True. 
  2712. ReturnValue: The number of actually removed elements. 
  2713. Side Effect: All cursors of this collection become undefined. 
  2714. Precondition: The cursor must belong to the collection and the cursor must 
  2715. point to an element of the collection. 
  2716. Exceptions: ICursorInvalidException 
  2717.  
  2718.  
  2719. ΓòÉΓòÉΓòÉ 3.1.2.66. removeAllElementsWithKey ΓòÉΓòÉΓòÉ
  2720.  
  2721.  INumber removeAllElementsWithKey (Key const&);
  2722. Removes all elements from the collection with the given key. 
  2723. ReturnValue: Number of elements removed 
  2724. Side Effect: If an element was actually removed all cursors of this collection 
  2725. become undefined. 
  2726.  
  2727.  
  2728. ΓòÉΓòÉΓòÉ 3.1.2.67. removeAllOccurrences ΓòÉΓòÉΓòÉ
  2729.  
  2730.  INumber removeAllOccurrences (Element const&);
  2731. Remove all occurrences of the given element in the collection. 
  2732. ReturnValue: Number of elements removed 
  2733. Side Effect: If an element was actually removed, all cursors of this collection 
  2734. become undefined. 
  2735.  
  2736.  
  2737. ΓòÉΓòÉΓòÉ 3.1.2.68. removeAt ΓòÉΓòÉΓòÉ
  2738.  
  2739.  void removeAt (ICursor const&);
  2740. Removes the element pointed to by the cursor. 
  2741. Side Effect: All cursors of this collection become undefined. 
  2742. Precondition: The cursor must belong to the collection and the cursor must 
  2743. point to an element of the collection. 
  2744. Exceptions: ICursorInvalidException 
  2745.  
  2746.  
  2747. ΓòÉΓòÉΓòÉ 3.1.2.69. removeAtPosition ΓòÉΓòÉΓòÉ
  2748.  
  2749.  void removeAtPosition (IPosition);
  2750. Removes the element from the collection, which is at the given position. The 
  2751. first element of the collection has position 1. 
  2752. Side Effect: All cursors of this collection become undefined. 
  2753. Precondition: Position must be a valid position in the collection, 
  2754. i.e. 1 <= position <= numberOfElements. 
  2755. Exceptions: IPositionInvalidException 
  2756.  
  2757.  
  2758. ΓòÉΓòÉΓòÉ 3.1.2.70. removeElementWithKey ΓòÉΓòÉΓòÉ
  2759.  
  2760.  Boolean removeElementWithKey (Key const&);
  2761. Removes an element from the collection with the given key. In collections with 
  2762. NON UNIQUE ELEMENTS and arbitrary occurrence of such an element will be 
  2763. removed. 
  2764. ReturnValue: True if an element was actually removed. 
  2765. Side Effect: If an element was actually removed, all cursors of this collection 
  2766. become undefined. 
  2767.  
  2768.  
  2769. ΓòÉΓòÉΓòÉ 3.1.2.71. removeFirst ΓòÉΓòÉΓòÉ
  2770.  
  2771.  void removeFirst ();
  2772. Removes the first element from the collection. 
  2773. Side Effect: All cursors of this collection become undefined. 
  2774. Precondition: The collection must not be empty 
  2775. Exceptions: IEmptyException 
  2776.  
  2777.  
  2778. ΓòÉΓòÉΓòÉ 3.1.2.72. removeLast ΓòÉΓòÉΓòÉ
  2779.  
  2780.  void removeLast ();
  2781. Removes the last element from the collection. 
  2782. Side Effect: All cursors of this collection become undefined. 
  2783. Precondition: The collection must not be empty 
  2784. Exceptions: IEmptyException 
  2785.  
  2786.  
  2787. ΓòÉΓòÉΓòÉ 3.1.2.73. replaceAt ΓòÉΓòÉΓòÉ
  2788.  
  2789.  void replaceAt (ICursor const&, Element const&);
  2790. Replaces the element pointed to by the cursor with the given element. 
  2791. Precondition: The cursor must belong to the collection and the cursor must 
  2792. point to an element of the collection. 
  2793. Exceptions: 
  2794.  
  2795. o ICursorInvalidException 
  2796.  
  2797.  
  2798. ΓòÉΓòÉΓòÉ 3.1.2.74. replaceElementWithKey ΓòÉΓòÉΓòÉ
  2799.  
  2800.  Boolean replaceElementWithKey (Element const&);
  2801.  Boolean replaceElementWithKey (Element const&, ICursor&);
  2802. If there is no element where the key is equal to the key of the given element 
  2803. in the collection invalidate the cursor. Otherwise replace the element and set 
  2804. the cursor to this element. In collections with NON UNIQUE ELEMENTS and 
  2805. arbitrary occurrence of such an element will be replaced. 
  2806. ReturnValue: True if an element was replaced. 
  2807. Precondition: The cursor must belong to the collection. 
  2808. Exceptions: IMemoryExhaustedException 
  2809. ICursorInvalidException 
  2810.  
  2811.  
  2812. ΓòÉΓòÉΓòÉ 3.1.2.75. setToFirst ΓòÉΓòÉΓòÉ
  2813.  
  2814.  Boolean setToFirst (ICursor&) const;
  2815. Set the cursor to the first element of the collection in iteration order. If 
  2816. the collection is empty (i.e. if no first element exists) the given cursor will 
  2817. become invalid. 
  2818. ReturnValue: True if the collection is not empty. 
  2819. Precondition: The cursor must belong to the collection. 
  2820. Exceptions: ICursorInvalidException 
  2821.  
  2822.  
  2823. ΓòÉΓòÉΓòÉ 3.1.2.76. setToLast ΓòÉΓòÉΓòÉ
  2824.  
  2825.  Boolean setToLast (ICursor&) const;
  2826. Set the cursor to the last element of the collection in iteration order. If the 
  2827. collection is empty (i.e. no last element exists) the given cursor will become 
  2828. invalid. 
  2829. ReturnValue: True if the collection was not empty. 
  2830. Precondition: The cursor must belong to the collection. 
  2831. Exceptions: ICursorInvalidException 
  2832.  
  2833.  
  2834. ΓòÉΓòÉΓòÉ 3.1.2.77. setToNext ΓòÉΓòÉΓòÉ
  2835.  
  2836.  Boolean setToNext (ICursor&) const;
  2837. Set the cursor to the next element in the collection in iteration order. If no 
  2838. more elements are left to be visited the given cursor will become invalid. 
  2839. ReturnValue: True if there was a next element. 
  2840. Precondition: The cursor must belong to the collection. 
  2841. Exceptions: ICursorInvalidException 
  2842.  
  2843.  
  2844. ΓòÉΓòÉΓòÉ 3.1.2.78. setToNextDifferentElement ΓòÉΓòÉΓòÉ
  2845.  
  2846.  Boolean setToNextDifferentElement (ICursor&) const;
  2847. Set the cursor to the next element in iteration order in the collection which 
  2848. is different to the given element. If no more elements are left to be visited. 
  2849. the given cursor will become invalid. 
  2850. ReturnValue: True if there was a next different element. 
  2851. Precondition: The cursor must belong to the collection. 
  2852. Exceptions: ICursorInvalidException 
  2853.  
  2854.  
  2855. ΓòÉΓòÉΓòÉ 3.1.2.79. setToNextWithDifferentKey ΓòÉΓòÉΓòÉ
  2856.  
  2857.  Boolean setToNextWithDifferentKey (ICursor&) const;
  2858. Set the cursor to the next element in the collection in iteration order with a 
  2859. different key. If there is no such element the given cursor will become 
  2860. invalid. 
  2861. ReturnValue: True if there was a next element with different key. 
  2862. Precondition: The cursor must belong to the collection and the cursor must 
  2863. point to an element of the collection. 
  2864. Exceptions: ICursorInvalidException 
  2865.  
  2866.  
  2867. ΓòÉΓòÉΓòÉ 3.1.2.80. setToPosition ΓòÉΓòÉΓòÉ
  2868.  
  2869.  void setToPosition (IPosition, ICursor&) const;
  2870. Set the cursor to the element at the given position. If the given position does 
  2871. not exist in the collection the given cursor will become invalid. 
  2872. ReturnValue: True if position was a valid position. 
  2873. Precondition: The cursor must belong to the collection. 
  2874. Position must be a valid position in the collection, 
  2875. i.e. 1 <= position <= numberOfElements. 
  2876. Exceptions: ICursorInvalidException 
  2877. IPositionInvalidException 
  2878.  
  2879.  
  2880. ΓòÉΓòÉΓòÉ 3.1.2.81. setToPrevious ΓòÉΓòÉΓòÉ
  2881.  
  2882.  Boolean setToPrevious (ICursor&) const;
  2883. Set the cursor to the previous (opposite of next) element in iteration order. 
  2884. If no such element exists, the given cursor will become invalid. 
  2885. ReturnValue: True if a previous element exists. 
  2886. Precondition: The cursor must belong to the collection and the cursor must 
  2887. point to an element of the collection. 
  2888. Exceptions: ICursorInvalidException 
  2889.  
  2890.  
  2891. ΓòÉΓòÉΓòÉ 3.1.2.82. sort ΓòÉΓòÉΓòÉ
  2892.  
  2893.  void sort (long (*comparisonFunction) (Element const&, Element const&));
  2894. Sort the collection. The relation of two elements is described by the 
  2895. comparisonFunction. 
  2896. Note: The comparisonFunction must deliver: >0 if element1 > element2, 0 if 
  2897. element1 == element2, <0 if element1 < element2. 
  2898. Side Effect: All cursors of this collection become undefined. 
  2899.  
  2900.  
  2901. ΓòÉΓòÉΓòÉ 3.1.2.83. top ΓòÉΓòÉΓòÉ
  2902.  
  2903.  Element const& top () const;
  2904. Returns (a constant reference to) the last element of the collection. 
  2905. Exceptions: IEmptyException 
  2906.  
  2907.  
  2908. ΓòÉΓòÉΓòÉ 3.1.2.84. unionWith ΓòÉΓòÉΓòÉ
  2909.  
  2910.  void unionWith (CLASS_NAME const&);
  2911. Make the collection the union of the collection and the given collection. 
  2912. Note: The union of A and B is the set of elements which are members of A or B 
  2913. or both. 
  2914.  
  2915. The following rules apply for Bags with duplicate elements: If bag P contains 
  2916. the element el-x m times and bag Q contains the element el-x n times, then the 
  2917. union of P and Q contains the element el-x m+n times. 
  2918. Side Effect: If some elements were added to the collection all cursors of this 
  2919. collection become undefined. 
  2920. Precondition: See preconditions of add. 
  2921. Exceptions: 
  2922.  
  2923. o IMemoryExhaustedException 
  2924. o If BOUNDED: IFullException 
  2925. o If MAPPING: IKeyAlreadyExistsException 
  2926.  
  2927.  
  2928. ΓòÉΓòÉΓòÉ 3.2. Heap ΓòÉΓòÉΓòÉ
  2929.  
  2930. A heap is an unordered collection of zero or more elements. 
  2931.  
  2932. The type and value of the heap elements are irrelevant and have no effect on 
  2933. the behavior of the heap. 
  2934.  
  2935. "Figure: Combination of collection properties" gives an overview of the 
  2936. properties and the position of a heap in respect to other flat collections. 
  2937.  
  2938.  
  2939. ΓòÉΓòÉΓòÉ 3.2.1. Customizing ΓòÉΓòÉΓòÉ
  2940.  
  2941.      To be completed .......... 
  2942.  
  2943.  
  2944. ΓòÉΓòÉΓòÉ 3.2.2. Declaration ΓòÉΓòÉΓòÉ
  2945.  
  2946. template < class Element >
  2947. class IHeap {
  2948. public:
  2949.   class Cursor : ICursor {
  2950.     Element& element ();
  2951.     Boolean operator== (Cursor const& cursor);
  2952.     Boolean operator!= (Cursor const& cursor);
  2953.   };
  2954.                   IHeap             (INumber
  2955.                                                numberOfElements = 100,
  2956.                                                IBoundIndicator =
  2957.                                                IUnbounded);
  2958.                   IHeap             (IHeap < Element > const&);
  2959.    IHeap < Element >&    operator =                  (IHeap < Element > const&);
  2960.                  ~IHeap             ();
  2961.    Boolean        add                         (Element const&);
  2962.    Boolean        add                         (Element const&,
  2963.                                                ICursor&);
  2964.    void           addAllFrom                  (IHeap < Element > const&);
  2965.    Element const& elementAt                   (ICursor const&) const;
  2966.    Element&       elementAt                   (ICursor const&);
  2967.    Element const& anyElement                  () const;
  2968.    void           removeAt                    (ICursor const&);
  2969.    INumber        removeAll                   (Boolean (*property)
  2970.                                                (Element const&, void*),
  2971.                                                void* additionalArgument = 0);
  2972.    void           replaceAt                   (ICursor const&,
  2973.                                                Element const&);
  2974.    void           removeAll                   ();
  2975.    Boolean        isBounded                   () const;
  2976.    INumber        maxNumberOfElements         () const;
  2977.    INumber        numberOfElements            () const;
  2978.    Boolean        isEmpty                     () const;
  2979.    Boolean        isFull                      () const;
  2980.    ICursor*       newCursor                   () const;
  2981.    Boolean        setToFirst                  (ICursor&) const;
  2982.    Boolean        setToNext                   (ICursor&) const;
  2983.    Boolean        allElementsDo               (Boolean (*function)
  2984.                                                   (Element&, void*),
  2985.                                                void* additionalArgument = 0);
  2986.    Boolean        allElementsDo               (IIterator <Element>&);
  2987.    Boolean        allElementsDo               (Boolean (*function)
  2988.                                                (Element const&, void*),
  2989.                                                void* additionalArgument = 0)
  2990.                                                const;
  2991.    Boolean        allElementsDo               (IConstantIterator
  2992.                                                   <Element>&) const;
  2993. };
  2994.  
  2995.  
  2996. ΓòÉΓòÉΓòÉ 3.3. Sequence ΓòÉΓòÉΓòÉ
  2997.  
  2998. A sequence is a collection of zero or more elements in which a linear order of 
  2999. succession is maintained, with a first and a last element. Each element but the 
  3000. first one has a predecessor, and each element but the last one has a successor. 
  3001.  
  3002. The type and value of the sequence elements are irrelevant and have no effect 
  3003. on the behavior of the sequence. Elements can be added and deleted from any 
  3004. position of the sequence. Elements can be retrieved, and they can be replaced. 
  3005.  
  3006. "Figure: Combination of collection properties" gives an overview of the 
  3007. properties and the position of a sequence in respect to other flat collections. 
  3008.  
  3009.  
  3010. ΓòÉΓòÉΓòÉ 3.3.1. Customizing ΓòÉΓòÉΓòÉ
  3011.  
  3012. This section describes the implementation variants supported by the Sequence 
  3013. Class and the generic parameters available for selecting these variants. 
  3014.  
  3015.  
  3016. ΓòÉΓòÉΓòÉ 3.3.1.1. Implementation Variants ΓòÉΓòÉΓòÉ
  3017.  
  3018. The basic selections of implementation variants are : 
  3019.  
  3020. doubly linked  and  unbounded or 
  3021. tabular  and  bounded 
  3022. If tabular and bounded is selected, further selections for implementation 
  3023. variants might be done with: 
  3024.  
  3025. wrapped  or  unwrapped and 
  3026. pointered  or  pointerless and 
  3027. undiluted  or  flag diluted  or  value diluted 
  3028.  
  3029. The implementation variants for the Sequence are independent from other Classs, 
  3030. i.e. it can not be based on other Classs. 
  3031.  
  3032. Time complexity for element lookup is O( N ), where N is the total number of 
  3033. elements in the list. This goes for both tabular and doubly linked lists. 
  3034.  
  3035.  
  3036. ΓòÉΓòÉΓòÉ 3.3.2. Usage Notes ΓòÉΓòÉΓòÉ
  3037.  
  3038. The use of the Sequence Class is illustrated in a  reftype=hd.coding example 
  3039. provided with the IBM Class Library: Collection Classes. 
  3040.  
  3041.  
  3042. ΓòÉΓòÉΓòÉ 3.3.3. Declarations ΓòÉΓòÉΓòÉ
  3043.  
  3044. template < class Element >
  3045. class ISequence {
  3046. public:
  3047.   class Cursor : ICursor {
  3048.     Element& element ();
  3049.     void setToLast ();
  3050.     void setToPrevious ();
  3051.     Boolean operator== (Cursor const& cursor);
  3052.     Boolean operator!= (Cursor const& cursor);
  3053.   };
  3054.                   ISequence             (INumber
  3055.                                                numberOfElements = 100,
  3056.                                                IBoundIndicator =
  3057.                                                IUnbounded);
  3058.                   ISequence             (ISequence < Element > const&);
  3059.    ISequence < Element >&    operator =                  (ISequence < Element > const&);
  3060.                  ~ISequence             ();
  3061.    Boolean        add                         (Element const&);
  3062.    Boolean        add                         (Element const&,
  3063.                                                ICursor&);
  3064.    void           addAllFrom                  (ISequence < Element > const&);
  3065.    Element const& elementAt                   (ICursor const&) const;
  3066.    Element&       elementAt                   (ICursor const&);
  3067.    Element const& anyElement                  () const;
  3068.    void           removeAt                    (ICursor const&);
  3069.    INumber        removeAll                   (Boolean (*property)
  3070.                                                (Element const&, void*),
  3071.                                                void* additionalArgument = 0);
  3072.    void           replaceAt                   (ICursor const&,
  3073.                                                Element const&);
  3074.    void           removeAll                   ();
  3075.    Boolean        isBounded                   () const;
  3076.    INumber        maxNumberOfElements         () const;
  3077.    INumber        numberOfElements            () const;
  3078.    Boolean        isEmpty                     () const;
  3079.    Boolean        isFull                      () const;
  3080.    ICursor*       newCursor                   () const;
  3081.    Boolean        setToFirst                  (ICursor&) const;
  3082.    Boolean        setToNext                   (ICursor&) const;
  3083.    Boolean        allElementsDo               (Boolean (*function)
  3084.                                                   (Element&, void*),
  3085.                                                void* additionalArgument = 0);
  3086.    Boolean        allElementsDo               (IIterator <Element>&);
  3087.    Boolean        allElementsDo               (Boolean (*function)
  3088.                                                (Element const&, void*),
  3089.                                                void* additionalArgument = 0)
  3090.                                                const;
  3091.    Boolean        allElementsDo               (IConstantIterator
  3092.                                                   <Element>&) const;
  3093.    void           removeFirst                 ();
  3094.    void           removeLast                  ();
  3095.    void           removeAtPosition            (IPosition);
  3096.    Element const& firstElement                () const;
  3097.    Element const& lastElement                 () const;
  3098.    Element const& elementAtPosition           (IPosition) const;
  3099.    Boolean        setToLast                   (ICursor&) const;
  3100.    Boolean        setToPrevious               (ICursor&) const;
  3101.    void           setToPosition               (IPosition,
  3102.                                                ICursor&) const;
  3103.    Boolean        isFirst                     (ICursor const&) const;
  3104.    Boolean        isLast                      (ICursor const&) const;
  3105.    long           compare                     (ISequence < Element > const&,
  3106.                                                long (*comparisonFunction)
  3107.                                                   (Element const&,
  3108.                                                   Element const&)) const;
  3109.    void           addAsFirst                  (Element const&);
  3110.    void           addAsFirst                  (Element const&,
  3111.                                                ICursor&);
  3112.    void           addAsLast                   (Element const&);
  3113.    void           addAsLast                   (Element const&,
  3114.                                                ICursor&);
  3115.    void           addAsNext                   (Element const&,
  3116.                                                ICursor&);
  3117.    void           addAsPrevious               (Element const&,
  3118.                                                ICursor&);
  3119.    void           addAtPosition               (IPosition,
  3120.                                                Element const&);
  3121.    void           addAtPosition               (IPosition,
  3122.                                                Element const&,
  3123.                                                ICursor&);
  3124.    void           sort                        (long (*comparisonFunction)
  3125.                                                (Element const&,
  3126.                                                Element const&));
  3127. };
  3128.  
  3129.  
  3130. ΓòÉΓòÉΓòÉ 3.3.4. Coding Example ΓòÉΓòÉΓòÉ
  3131.  
  3132. #include "iseq.h"
  3133. #include "xlist.h"
  3134.  
  3135. typedef ISequence <Word> WordSeq;
  3136. typedef IIterator <Word> WordIter;
  3137.  
  3138. long compare ( Word const& w1, Word const& w2) {
  3139.     return(strcmp(w1.GetElement(), w2.GetElement()));
  3140. }
  3141.  
  3142.  
  3143. /*--------------------------------------------------------------------------*\
  3144. * Test variables                                                             *
  3145. \*--------------------------------------------------------------------------*/
  3146.  
  3147. char *String[9] = {
  3148.    "the",
  3149.    "quick",
  3150.    "brown",
  3151.    "fox",
  3152.    "jumps",
  3153.    "over",
  3154.    "a",
  3155.    "lazy",
  3156.    "dog"
  3157. };
  3158.  
  3159. class PrintClass : public WordIter
  3160. {
  3161. public:
  3162.    Boolean applyTo(Word &w)
  3163.       {
  3164.       printf("%s\n",w.GetElement());    // Print the string
  3165.       return(True);
  3166.       }
  3167. };
  3168.  
  3169.  
  3170.  
  3171.  
  3172. /*--------------------------------------------------------------------------*\
  3173. * Main program                                                               *
  3174. \*--------------------------------------------------------------------------*/
  3175. int main()
  3176. {
  3177.    WordSeq WL;
  3178.    Word     aWord;
  3179.    WordSeq:: Cursor cursor(WL);
  3180.    PrintClass Print;
  3181.  
  3182.    int i;
  3183.  
  3184.    printf("\n*** Example of Sequence use ***\n");
  3185.  
  3186.    for (i = 0; i < 9; i ++) {                // Put all strings in the list
  3187.       aWord.Fill(String[i]);                 // Fill object with right value
  3188.       WL.addAsFirst(aWord);                  // Add it as first in the list
  3189.       }
  3190.    printf("\nList initial order:\n");        // Print the list in this order
  3191.    WL.allElementsDo(Print);
  3192.  
  3193.    WL.sort(compare);                       // Sort the list ascending
  3194.    printf("\nList sorted order:\n");         // Print the list in this order
  3195.    WL.allElementsDo(Print);
  3196.  
  3197.    /**/
  3198.    /**/
  3199.  
  3200.    printf("\nLook for \"fox\" in the list\n");
  3201.    aWord.Fill("fox");
  3202.    for (cursor.setToFirst();
  3203.       cursor.isValid(), (WL.elementAt(cursor) != aWord.GetElement());
  3204.       cursor.setToNext());
  3205.    if (WL.elementAt(cursor)==aWord.GetElement()) {
  3206.     printf("\n found Element \n");
  3207.     }
  3208.    else {
  3209.     printf("\n Element not found \n");
  3210.    }
  3211.    /**/
  3212.    /**/
  3213.  
  3214.    /**/
  3215.    /**/
  3216.  
  3217.  
  3218.    printf("\n*** End of example ***\n");
  3219.  
  3220.    return(0);
  3221. }
  3222.  
  3223. Header File: 
  3224.  
  3225. #include "iseq.h"
  3226. #include "xlist.h"
  3227.  
  3228. typedef ISequence <Word> WordSeq;
  3229. typedef IIterator <Word> WordIter;
  3230.  
  3231. long compare ( Word const& w1, Word const& w2) {
  3232.     return(strcmp(w1.GetElement(), w2.GetElement()));
  3233. }
  3234.  
  3235.  
  3236. /*--------------------------------------------------------------------------*\
  3237. * Test variables                                                             *
  3238. \*--------------------------------------------------------------------------*/
  3239.  
  3240. char *String[9] = {
  3241.    "the",
  3242.    "quick",
  3243.    "brown",
  3244.    "fox",
  3245.    "jumps",
  3246.    "over",
  3247.    "a",
  3248.    "lazy",
  3249.    "dog"
  3250. };
  3251.  
  3252. class PrintClass : public WordIter
  3253. {
  3254. public:
  3255.    Boolean applyTo(Word &w)
  3256.       {
  3257.       printf("%s\n",w.GetElement());    // Print the string
  3258.       return(True);
  3259.       }
  3260. };
  3261.  
  3262.  
  3263.  
  3264.  
  3265. /*--------------------------------------------------------------------------*\
  3266. * Main program                                                               *
  3267. \*--------------------------------------------------------------------------*/
  3268. int main()
  3269. {
  3270.    WordSeq WL;
  3271.    Word     aWord;
  3272.    WordSeq:: Cursor cursor(WL);
  3273.    PrintClass Print;
  3274.  
  3275.    int i;
  3276.  
  3277.    printf("\n*** Example of Sequence use ***\n");
  3278.  
  3279.    for (i = 0; i < 9; i ++) {                // Put all strings in the list
  3280.       aWord.Fill(String[i]);                 // Fill object with right value
  3281.       WL.addAsFirst(aWord);                  // Add it as first in the list
  3282.       }
  3283.    printf("\nList initial order:\n");        // Print the list in this order
  3284.    WL.allElementsDo(Print);
  3285.  
  3286.    WL.sort(compare);                       // Sort the list ascending
  3287.    printf("\nList sorted order:\n");         // Print the list in this order
  3288.    WL.allElementsDo(Print);
  3289.  
  3290.    /**/
  3291.    /**/
  3292.  
  3293.    printf("\nLook for \"fox\" in the list\n");
  3294.    aWord.Fill("fox");
  3295.    for (cursor.setToFirst();
  3296.       cursor.isValid(), (WL.elementAt(cursor) != aWord.GetElement());
  3297.       cursor.setToNext());
  3298.    if (WL.elementAt(cursor)==aWord.GetElement()) {
  3299.     printf("\n found Element \n");
  3300.     }
  3301.    else {
  3302.     printf("\n Element not found \n");
  3303.    }
  3304.    /**/
  3305.    /**/
  3306.  
  3307.    /**/
  3308.    /**/
  3309.  
  3310.  
  3311.    printf("\n*** End of example ***\n");
  3312.  
  3313.    return(0);
  3314. }
  3315.  
  3316.  
  3317. ΓòÉΓòÉΓòÉ 3.3.5. Coding Example ΓòÉΓòÉΓòÉ
  3318.  
  3319. /*--------------------------------------------------------------------------*\
  3320. *                                                                            *
  3321. | Example program of Building Block SEQUENCE.                               |
  3322. *                                                                            *
  3323. \*--------------------------------------------------------------------------*/
  3324.  
  3325. #include <stdio.h>
  3326. #include <string.h>
  3327. #include <iseq.h>
  3328.  
  3329. typedef ISequence <char> CharSeq;
  3330.  
  3331. typedef IIterator <char> CharIterator;
  3332.  
  3333. class PrintClass : public CharIterator
  3334. {
  3335. public:
  3336.    Boolean applyTo(char &c)
  3337.       {
  3338.       printf("%c",c);    // Print the character
  3339.       return(True);
  3340.       }
  3341. };
  3342.  
  3343.  
  3344. char * String = "BuildingBlocks";
  3345.  
  3346. /*--------------------------------------------------------------------------*\
  3347. * Main program                                                               *
  3348. \*--------------------------------------------------------------------------*/
  3349. int main() {
  3350.    CharSeq CS;
  3351.    CharSeq::Cursor cursor(CS);
  3352.  
  3353.    PrintClass Print;
  3354.    int i;
  3355.  
  3356.    printf("\n*** Example of SEQUENCE use ***\n");
  3357.  
  3358.    for (i = 0; String[i] != 0; i++)          // Put all characters in the
  3359.       {                                      // sequence.
  3360.       CS.add(String[i]);
  3361.       }
  3362.  
  3363.    printf("\nSequence contains:\n");         // Print the contents
  3364.    CS.allElementsDo(Print);
  3365.    printf("\nNumber of elements = %ld\n",CS.numberOfElements());
  3366.  
  3367.    while (CS.numberOfElements () >= 5) {
  3368.      CS.setToPosition(5, cursor);
  3369.      CS.allElementsDo(Print);
  3370.      printf("\n");
  3371.      CS.removeAt(cursor);
  3372.    }
  3373.  
  3374.    printf("\nSequence without the tail:\n"); // Print the contents again
  3375.    CS.allElementsDo(Print);
  3376.    printf("\nNumber of elements = %ld\n",CS.numberOfElements());
  3377.  
  3378.    printf("\n*** End of example ***\n");
  3379.  
  3380.    return(0);
  3381. }
  3382.  
  3383.  
  3384. ΓòÉΓòÉΓòÉ 3.3.6. Coding Example ΓòÉΓòÉΓòÉ
  3385.  
  3386.  
  3387. #include <iostream.h>
  3388.  
  3389. #include "people.h"
  3390. #include "iseq.h"
  3391.  
  3392.  
  3393. typedef ISequence <Person> People;
  3394.  
  3395.  
  3396. main() {
  3397.  
  3398.     People people;
  3399.     People::Cursor p_cursor(people);
  3400.  
  3401.     people.add(Person("M. Gorbatschow", True));
  3402.     people.add(Person("G. Bush", False));
  3403.     people.add(Person("R. Perot", True));
  3404.     people.add(Person("B. Jeltsin", False));
  3405.     people.add(Person("J. Major", False));
  3406.     people.add(Person("F. Castro", False));
  3407.     people.add(Person("Kojak", True));
  3408.     people.add(Person("A. Schwarzenegger", False));
  3409.     people.add(Person("H. Kohl", True));
  3410.     people.add(Person("F. Mitterand", True));
  3411.     people.add(Person("Magic Johnson", True));
  3412.     people.add(Person("B. Becker", False));
  3413.     people.add(Person("E. Presley", False));
  3414.     people.add(Person("Heino", True));
  3415.     people.add(Person("M. Gandhi", True));
  3416.     people.add(Person("Lenin", True));
  3417.  
  3418.     cout<<"\n";
  3419.  
  3420.     for(p_cursor.setToFirst(); p_cursor.isValid(); p_cursor.setToNext()) {
  3421.         cout<<"\n"<<people.elementAt(p_cursor).get_name();
  3422.     }
  3423.     cout<<"\n\nNumber of people : "<< people.numberOfElements()<<"\n";
  3424.  
  3425.     People bald;
  3426.     People::Cursor b_cursor(bald);
  3427.     for (p_cursor.setToFirst(); p_cursor.isValid(); p_cursor.setToNext()) {
  3428.         if(people.elementAt(p_cursor).is_bald()) {
  3429.             bald.add(people.elementAt(p_cursor));
  3430.         }
  3431.     }
  3432.     cout<<"\nBald people : \n";
  3433.     for (b_cursor.setToFirst(); b_cursor.isValid(); b_cursor.setToNext()) {
  3434.         cout<<"\n"<<bald.elementAt(b_cursor).get_name();
  3435.     }
  3436.     cout<<"\n\nNumber of bald people : "<<bald.numberOfElements()<<"\n";
  3437.  
  3438.     return 0;
  3439. }
  3440. Header File: 
  3441.  
  3442.  
  3443. #include <iostream.h>
  3444.  
  3445. #include "people.h"
  3446. #include "iseq.h"
  3447.  
  3448.  
  3449. typedef ISequence <Person> People;
  3450.  
  3451.  
  3452. main() {
  3453.  
  3454.     People people;
  3455.     People::Cursor p_cursor(people);
  3456.  
  3457.     people.add(Person("M. Gorbatschow", True));
  3458.     people.add(Person("G. Bush", False));
  3459.     people.add(Person("R. Perot", True));
  3460.     people.add(Person("B. Jeltsin", False));
  3461.     people.add(Person("J. Major", False));
  3462.     people.add(Person("F. Castro", False));
  3463.     people.add(Person("Kojak", True));
  3464.     people.add(Person("A. Schwarzenegger", False));
  3465.     people.add(Person("H. Kohl", True));
  3466.     people.add(Person("F. Mitterand", True));
  3467.     people.add(Person("Magic Johnson", True));
  3468.     people.add(Person("B. Becker", False));
  3469.     people.add(Person("E. Presley", False));
  3470.     people.add(Person("Heino", True));
  3471.     people.add(Person("M. Gandhi", True));
  3472.     people.add(Person("Lenin", True));
  3473.  
  3474.     cout<<"\n";
  3475.  
  3476.     for(p_cursor.setToFirst(); p_cursor.isValid(); p_cursor.setToNext()) {
  3477.         cout<<"\n"<<people.elementAt(p_cursor).get_name();
  3478.     }
  3479.     cout<<"\n\nNumber of people : "<< people.numberOfElements()<<"\n";
  3480.  
  3481.     People bald;
  3482.     People::Cursor b_cursor(bald);
  3483.     for (p_cursor.setToFirst(); p_cursor.isValid(); p_cursor.setToNext()) {
  3484.         if(people.elementAt(p_cursor).is_bald()) {
  3485.             bald.add(people.elementAt(p_cursor));
  3486.         }
  3487.     }
  3488.     cout<<"\nBald people : \n";
  3489.     for (b_cursor.setToFirst(); b_cursor.isValid(); b_cursor.setToNext()) {
  3490.         cout<<"\n"<<bald.elementAt(b_cursor).get_name();
  3491.     }
  3492.     cout<<"\n\nNumber of bald people : "<<bald.numberOfElements()<<"\n";
  3493.  
  3494.     return 0;
  3495. }
  3496.  
  3497.  
  3498. ΓòÉΓòÉΓòÉ 3.4. Equality Sequence ΓòÉΓòÉΓòÉ
  3499.  
  3500. A equality sequence is similar to a sequence. But unlike a sequence which has 
  3501. no knowledge of the value of its elements a equality sequence supports element 
  3502. equality as well. 
  3503.  
  3504. "Figure: Combination of collection properties" gives an overview of the 
  3505. properties and the position of a equality sequence in respect to other flat 
  3506. collections. 
  3507.  
  3508.  
  3509. ΓòÉΓòÉΓòÉ 3.4.1. Customizing ΓòÉΓòÉΓòÉ
  3510.  
  3511.      To be completed .......... 
  3512.  
  3513.  
  3514. ΓòÉΓòÉΓòÉ 3.4.2. Declarations ΓòÉΓòÉΓòÉ
  3515.  
  3516. template < class Element >
  3517. class IEqualitySequence {
  3518. public:
  3519.   class Cursor : ICursor {
  3520.     Element& element ();
  3521.     void setToLast ();
  3522.     void setToPrevious ();
  3523.     Boolean operator== (Cursor const& cursor);
  3524.     Boolean operator!= (Cursor const& cursor);
  3525.   };
  3526.                   IREqualitySequence             (INumber
  3527.                                                numberOfElements = 100,
  3528.                                                IBoundIndicator =
  3529.                                                IUnbounded);
  3530.                   IREqualitySequence             (IREqualitySequence < Element > const&);
  3531.    IREqualitySequence < Element >&    operator =   (IREqualitySequence < Element > const&);
  3532.                  ~IREqualitySequence             ();
  3533.    Boolean        add                         (Element const&);
  3534.    Boolean        add                         (Element const&,
  3535.                                                ICursor&);
  3536.    void           addAllFrom                  (IREqualitySequence < Element > const&);
  3537.    Element const& elementAt                   (ICursor const&) const;
  3538.    Element&       elementAt                   (ICursor const&);
  3539.    Element const& anyElement                  () const;
  3540.    void           removeAt                    (ICursor const&);
  3541.    INumber        removeAll                   (Boolean (*property)
  3542.                                                (Element const&, void*),
  3543.                                                void* additionalArgument = 0);
  3544.    void           replaceAt                   (ICursor const&,
  3545.                                                Element const&);
  3546.    void           removeAll                   ();
  3547.    Boolean        isBounded                   () const;
  3548.    INumber        maxNumberOfElements         () const;
  3549.    INumber        numberOfElements            () const;
  3550.    Boolean        isEmpty                     () const;
  3551.    Boolean        isFull                      () const;
  3552.    ICursor*       newCursor                   () const;
  3553.    Boolean        setToFirst                  (ICursor&) const;
  3554.    Boolean        setToNext                   (ICursor&) const;
  3555.    Boolean        allElementsDo               (Boolean (*function)
  3556.                                                   (Element&, void*),
  3557.                                                void* additionalArgument = 0);
  3558.    Boolean        allElementsDo               (IIterator <Element>&);
  3559.    Boolean        allElementsDo               (Boolean (*function)
  3560.                                                (Element const&, void*),
  3561.                                                void* additionalArgument = 0)
  3562.                                                const;
  3563.    Boolean        allElementsDo               (IConstantIterator
  3564.                                                   <Element>&) const;
  3565.    Boolean        contains                    (Element const&) const;
  3566.    Boolean        containsAllFrom             (IREqualitySequence < Element > const&) const;
  3567.    Boolean        locate                      (Element const&, ICursor&)
  3568.                                                const;
  3569.    Boolean        locateOrAdd                 (Element const&);
  3570.    Boolean        locateOrAdd                 (Element const&,
  3571.                                                ICursor&);
  3572.    Boolean        remove                      (Element const&);
  3573.    INumber        numberOfOccurrences         (Element const&) const;
  3574.    Boolean        locateNext                  (Element const&, ICursor&)
  3575.                                                const;
  3576.    INumber        removeAllOccurrences        (Element const&);
  3577.    Boolean        operator ==                 (IREqualitySequence < Element > const&) const;
  3578.    Boolean        operator !=                 (IREqualitySequence < Element > const&) const;
  3579.    void           unionWith                   (IREqualitySequence < Element > const&);
  3580.    void           intersectionWith            (IREqualitySequence < Element > const&);
  3581.    void           differenceWith              (IREqualitySequence < Element > const&);
  3582.    void           addUnion                    (IREqualitySequence < Element > const&,
  3583.                                                IREqualitySequence < Element > const&);
  3584.    void           addIntersection             (IREqualitySequence < Element > const&,
  3585.                                                IREqualitySequence < Element > const&);
  3586.    void           addDifference               (IREqualitySequence < Element > const&,
  3587.                                                IREqualitySequence < Element > const&);
  3588.    void           removeFirst                 ();
  3589.    void           removeLast                  ();
  3590.    void           removeAtPosition            (IPosition);
  3591.    Element const& firstElement                () const;
  3592.    Element const& lastElement                 () const;
  3593.    Element const& elementAtPosition           (IPosition) const;
  3594.    Boolean        setToLast                   (ICursor&) const;
  3595.    Boolean        setToPrevious               (ICursor&) const;
  3596.    void           setToPosition               (IPosition,
  3597.                                                ICursor&) const;
  3598.    Boolean        isFirst                     (ICursor const&) const;
  3599.    Boolean        isLast                      (ICursor const&) const;
  3600.    long           compare                     (IREqualitySequence < Element > const&,
  3601.                                                long (*comparisonFunction)
  3602.                                                   (Element const&,
  3603.                                                   Element const&)) const;
  3604.    void           addAsFirst                  (Element const&);
  3605.    void           addAsFirst                  (Element const&,
  3606.                                                ICursor&);
  3607.    void           addAsLast                   (Element const&);
  3608.    void           addAsLast                   (Element const&,
  3609.                                                ICursor&);
  3610.    void           addAsNext                   (Element const&,
  3611.                                                ICursor&);
  3612.    void           addAsPrevious               (Element const&,
  3613.                                                ICursor&);
  3614.    void           addAtPosition               (IPosition,
  3615.                                                Element const&);
  3616.    void           addAtPosition               (IPosition,
  3617.                                                Element const&,
  3618.                                                ICursor&);
  3619.    void           sort                        (long (*comparisonFunction)
  3620.                                                (Element const&,
  3621.                                                Element const&));
  3622. };
  3623.  
  3624.  
  3625. ΓòÉΓòÉΓòÉ 3.5. Deque ΓòÉΓòÉΓòÉ
  3626.  
  3627. A deque is a collection of zero or more elements in which a linear order of 
  3628. succession is maintained, with a first and a last element. Each element but the 
  3629. first one has a predecessor, and each element but the last one has a successor. 
  3630.  
  3631. The type and value of the deque elements are irrelevant and have no effect on 
  3632. the behavior of the deque. Elements can be added at and deleted from either end 
  3633. of the queue. 
  3634.  
  3635.  
  3636. ΓòÉΓòÉΓòÉ 3.5.1. Customizing ΓòÉΓòÉΓòÉ
  3637.  
  3638. This section describes the implementation variants supported by the Deque Class 
  3639. and the generic parameters available for selecting these variants. 
  3640.  
  3641.  
  3642. ΓòÉΓòÉΓòÉ 3.5.1.1. Implementation Variants ΓòÉΓòÉΓòÉ
  3643.  
  3644. The implementation variants that can be chosen for the Deque are depending on 
  3645. the Building Block on which the Deque is based on, i.e.: 
  3646.  
  3647. Sequence 
  3648.  
  3649. A Deque has the same performance behavior as the Sequence in terms of time 
  3650. complexities because it is based on it. 
  3651.  
  3652.  
  3653. ΓòÉΓòÉΓòÉ 3.5.2. Usage Notes ΓòÉΓòÉΓòÉ
  3654.  
  3655. The use of the Deque Class is illustrated in a  reftype=hd.coding example 
  3656. provided with the IBM Class Library: Collection Classes. 
  3657.  
  3658.  
  3659. ΓòÉΓòÉΓòÉ 3.5.3. Declarations ΓòÉΓòÉΓòÉ
  3660.  
  3661. template < class Element >
  3662. class IDeque  {
  3663. public:
  3664.   class Cursor : ICursor {
  3665.     Element& element ();
  3666.     void setToLast ();
  3667.     void setToPrevious ();
  3668.     Boolean operator== (Cursor const& cursor);
  3669.     Boolean operator!= (Cursor const& cursor);
  3670.   };
  3671.                   IDeque             (INumber
  3672.                                                numberOfElements = 100,
  3673.                                                IBoundIndicator =
  3674.                                                IUnbounded);
  3675.                   IDeque             (IDeque < Element > const&);
  3676.    IDeque < Element >&    operator =                  (IDeque < Element > const&);
  3677.                  ~IDeque             ();
  3678.    Boolean        add                         (Element const&);
  3679.    Boolean        add                         (Element const&,
  3680.                                                ICursor&);
  3681.    void           addAllFrom                  (IDeque < Element > const&);
  3682.    Element const& elementAt                   (ICursor const&) const;
  3683.    Element&       elementAt                   (ICursor const&);
  3684.    Element const& anyElement                  () const;
  3685.    void           removeAt                    (ICursor const&);
  3686.    INumber        removeAll                   (Boolean (*property)
  3687.                                                (Element const&, void*),
  3688.                                                void* additionalArgument = 0);
  3689.    void           replaceAt                   (ICursor const&,
  3690.                                                Element const&);
  3691.    void           removeAll                   ();
  3692.    Boolean        isBounded                   () const;
  3693.    INumber        maxNumberOfElements         () const;
  3694.    INumber        numberOfElements            () const;
  3695.    Boolean        isEmpty                     () const;
  3696.    Boolean        isFull                      () const;
  3697.    ICursor*       newCursor                   () const;
  3698.    Boolean        setToFirst                  (ICursor&) const;
  3699.    Boolean        setToNext                   (ICursor&) const;
  3700.    Boolean        allElementsDo               (Boolean (*function)
  3701.                                                   (Element&, void*),
  3702.                                                void* additionalArgument = 0);
  3703.    Boolean        allElementsDo               (IIterator <Element>&);
  3704.    Boolean        allElementsDo               (Boolean (*function)
  3705.                                                (Element const&, void*),
  3706.                                                void* additionalArgument = 0)
  3707.                                                const;
  3708.    Boolean        allElementsDo               (IConstantIterator
  3709.                                                   <Element>&) const;
  3710.    void           removeFirst                 ();
  3711.    void           removeLast                  ();
  3712.    void           removeAtPosition            (IPosition);
  3713.    Element const& firstElement                () const;
  3714.    Element const& lastElement                 () const;
  3715.    Element const& elementAtPosition           (IPosition) const;
  3716.    Boolean        setToLast                   (ICursor&) const;
  3717.    Boolean        setToPrevious               (ICursor&) const;
  3718.    void           setToPosition               (IPosition,
  3719.                                                ICursor&) const;
  3720.    Boolean        isFirst                     (ICursor const&) const;
  3721.    Boolean        isLast                      (ICursor const&) const;
  3722.    long           compare                     (IDeque < Element > const&,
  3723.                                                long (*comparisonFunction)
  3724.                                                   (Element const&,
  3725.                                                   Element const&)) const;
  3726.    void           addAsFirst                  (Element const&);
  3727.    void           addAsFirst                  (Element const&,
  3728.                                                ICursor&);
  3729.    void           addAsLast                   (Element const&);
  3730.    void           addAsLast                   (Element const&,
  3731.                                                ICursor&);
  3732.    void           addAsNext                   (Element const&,
  3733.                                                ICursor&);
  3734.    void           addAsPrevious               (Element const&,
  3735.                                                ICursor&);
  3736.    void           addAtPosition               (IPosition,
  3737.                                                Element const&);
  3738.    void           addAtPosition               (IPosition,
  3739.                                                Element const&,
  3740.                                                ICursor&);
  3741.    void           sort                        (long (*comparisonFunction)
  3742.                                                (Element const&,
  3743.                                                Element const&));
  3744. };
  3745.  
  3746.  
  3747. ΓòÉΓòÉΓòÉ 3.5.4. Coding Example ΓòÉΓòÉΓòÉ
  3748.  
  3749. /*--------------------------------------------------------------------------*\
  3750. *                                                                            *
  3751. | Example program of Building Block dequeue
  3752. *                                                                            *
  3753. \*--------------------------------------------------------------------------*/
  3754.  
  3755. #include <stdio.h>
  3756. #include <string.h>
  3757. #include <ideqseq.h>
  3758. #include <ideque.h>
  3759.  
  3760. /*---------------------- Building Block specification ----------------------*\
  3761. *                                                                            *
  3762. | A deque is specified,                                                      |
  3763. | It is to hold characters.                                                  |
  3764. *                                                                            *
  3765. \*--------------------------------------------------------------------------*/
  3766.  
  3767. typedef IDeque <char> Deque;
  3768. typedef IIterator <char> CharIterator;
  3769.  
  3770. class Print : public CharIterator
  3771. {
  3772. public:
  3773.    Boolean applyTo(char &c)
  3774.       {
  3775.       printf("Char in Deque == %c\n",c);
  3776.       return True;
  3777.       }
  3778. };
  3779.  
  3780. /*--------------------------------------------------------------------------*\
  3781. * Test variables                                                             *
  3782. \*--------------------------------------------------------------------------*/
  3783.  
  3784. char *String = "teqikbonfxjme vralz ogdya  eospu o wr cu h";
  3785.  
  3786. /*--------------------------------------------------------------------------*\
  3787. * Main program                                                               *
  3788. \*--------------------------------------------------------------------------*/
  3789. int main()
  3790. {
  3791.    Deque D;
  3792.    char  C;
  3793.    Boolean ReadFront = True;
  3794.  
  3795.    int i;
  3796.  
  3797.    // Put all characters in the deque,
  3798.    // Then read the Deque, switching from one side of
  3799.    // the Deque to the other side of the Deque.
  3800.  
  3801.  
  3802.    printf("\n*** Example of deque use ***\n");
  3803.  
  3804.    for (i = 0; String[i] != 0; i ++) {          // For all characters:
  3805.       D.addAsLast(String[i]);                   //    - put it in the deque
  3806.       printf("Add as Last [%c]\n",String[i]);   //    - and give feedback
  3807.       }
  3808.  
  3809.    Print Aprinter;
  3810.  
  3811.    D.allElementsDo(Aprinter);
  3812.  
  3813.    printf("Current number of elements in the deque: %lu\n",
  3814.            D.numberOfElements());
  3815.  
  3816.  
  3817.    while (!D.isEmpty())            // As long as deque not empty
  3818.       {
  3819.       if (ReadFront)             // Read from front of Deque
  3820.          {
  3821.          C=D.firstElement();          // Get the character
  3822.          D.removeFirst();        // Delete it from the deque
  3823.          }
  3824.       else
  3825.          {
  3826.          D.lastElement();           // Get the character
  3827.          D.removeLast();         // Delete it from the deque
  3828.          }
  3829.       printf("%c",C);
  3830.       ReadFront = !ReadFront;    // Switch to other end of Deque
  3831.       }
  3832.  
  3833.    printf("\n*** End of example ***\n");
  3834.  
  3835.    return(0);
  3836. }
  3837.  
  3838.  
  3839. ΓòÉΓòÉΓòÉ 3.6. Queue ΓòÉΓòÉΓòÉ
  3840.  
  3841. A queue is a collection of zero or more elements in which a linear order of 
  3842. succession is maintained, with a first and a last element. Each element but the 
  3843. first one has a predecessor, and each element but the last one has a successor. 
  3844.  
  3845. The type and value of the queue elements are irrelevant and have no effect on 
  3846. the behavior of the queue. 
  3847.  
  3848. Elements are added at one end (called back end or bottom).  Elements are 
  3849. deleted from the other end (called the front end or top).  Consequently, the 
  3850. elements of a queue are in chronological order. 
  3851.  
  3852. A queue is characterized by a "first-in, first-out" (FIFO) behavior. 
  3853.  
  3854.  
  3855. ΓòÉΓòÉΓòÉ 3.6.1. Customizing ΓòÉΓòÉΓòÉ
  3856.  
  3857. This section describes the implementation variants supported by the Queue Class 
  3858. and the generic parameters available for selecting these variants. 
  3859.  
  3860.  
  3861. ΓòÉΓòÉΓòÉ 3.6.1.1. Implementation Variants ΓòÉΓòÉΓòÉ
  3862.  
  3863. The Queue implementation bases on another Class: 
  3864.  
  3865. Deque 
  3866.  
  3867. The performance characteristics of the Queue are the same as those of the 
  3868. Deque. 
  3869.  
  3870.  
  3871. ΓòÉΓòÉΓòÉ 3.6.2. Usage Notes ΓòÉΓòÉΓòÉ
  3872.  
  3873. The use of the Queue Class is illustrated in a -- Link Reference QueueX not 
  3874. found -- reftype=hd.coding example provided with the IBM Class Library: 
  3875. Collection Classes. 
  3876.  
  3877.  
  3878. ΓòÉΓòÉΓòÉ 3.6.3. Declarations ΓòÉΓòÉΓòÉ
  3879.  
  3880. template < class Element >
  3881. class IQueue  {
  3882. public:
  3883.   class Cursor : ICursor {
  3884.     Element& element ();
  3885.     void setToLast ();
  3886.     void setToPrevious ();
  3887.     Boolean operator== (Cursor const& cursor);
  3888.     Boolean operator!= (Cursor const& cursor);
  3889.   };
  3890.                   IQueue             (INumber
  3891.                                                numberOfElements = 100,
  3892.                                                IBoundIndicator =
  3893.                                                IUnbounded);
  3894.                   IQueue             (IQueue < Element > const&);
  3895.    IQueue < Element >&    operator =                  (IQueue < Element > const&);
  3896.                  ~IQueue             ();
  3897.    Boolean        add                         (Element const&);
  3898.    Boolean        add                         (Element const&,
  3899.                                                ICursor&);
  3900.    void           addAllFrom                  (IQueue < Element > const&);
  3901.    Element const& elementAt                   (ICursor const&) const;
  3902.    Element&       elementAt                   (ICursor const&);
  3903.    Element const& anyElement                  () const;
  3904.    void           removeAt                    (ICursor const&);
  3905.    INumber        removeAll                   (Boolean (*property)
  3906.                                                (Element const&, void*),
  3907.                                                void* additionalArgument = 0);
  3908.    void           replaceAt                   (ICursor const&,
  3909.                                                Element const&);
  3910.    void           removeAll                   ();
  3911.    Boolean        isBounded                   () const;
  3912.    INumber        maxNumberOfElements         () const;
  3913.    INumber        numberOfElements            () const;
  3914.    Boolean        isEmpty                     () const;
  3915.    Boolean        isFull                      () const;
  3916.    ICursor*       newCursor                   () const;
  3917.    Boolean        setToFirst                  (ICursor&) const;
  3918.    Boolean        setToNext                   (ICursor&) const;
  3919.    Boolean        allElementsDo               (Boolean (*function)
  3920.                                                   (Element&, void*),
  3921.                                                void* additionalArgument = 0);
  3922.    Boolean        allElementsDo               (IIterator <Element>&);
  3923.    Boolean        allElementsDo               (Boolean (*function)
  3924.                                                (Element const&, void*),
  3925.                                                void* additionalArgument = 0)
  3926.                                                const;
  3927.    Boolean        allElementsDo               (IConstantIterator
  3928.                                                   <Element>&) const;
  3929.    void           removeFirst                 ();
  3930.    void           removeAtPosition            (IPosition);
  3931.    Element const& firstElement                () const;
  3932.    Element const& lastElement                 () const;
  3933.    Element const& elementAtPosition           (IPosition) const;
  3934.    Boolean        setToLast                   (ICursor&) const;
  3935.    Boolean        setToPrevious               (ICursor&) const;
  3936.    void           setToPosition               (IPosition,
  3937.                                                ICursor&) const;
  3938.    Boolean        isFirst                     (ICursor const&) const;
  3939.    Boolean        isLast                      (ICursor const&) const;
  3940.    long           compare                     (IQueue < Element > const&,
  3941.                                                long (*comparisonFunction)
  3942.                                                   (Element const&,
  3943.                                                   Element const&)) const;
  3944.    void           addAsLast                   (Element const&);
  3945.    void           addAsLast                   (Element const&,
  3946.                                                ICursor&);
  3947.    void           addAsNext                   (Element const&,
  3948.                                                ICursor&);
  3949.    void           addAsPrevious               (Element const&,
  3950.                                                ICursor&);
  3951.    void           addAtPosition               (IPosition,
  3952.                                                Element const&);
  3953.    void           addAtPosition               (IPosition,
  3954.                                                Element const&,
  3955.                                                ICursor&);
  3956.    void           sort                        (long (*comparisonFunction)
  3957.                                                (Element const&,
  3958.                                                Element const&));
  3959.    void           enqueue                     (Element const&);
  3960.    void           enqueue                     (Element const&,
  3961.                                                ICursor&);
  3962.    void           dequeue                     ();
  3963.    void           dequeue                     (Element&);
  3964. };
  3965.  
  3966.  
  3967. ΓòÉΓòÉΓòÉ 3.7. Stack ΓòÉΓòÉΓòÉ
  3968.  
  3969. A stack is a collection of zero or more elements in which a linear order of 
  3970. succession is maintained, with a first and a last element. Each element but the 
  3971. first one has a predecessor, and each element but the last one has a successor. 
  3972. The type and value of the stack elements are irrelevant and have no effect on 
  3973. the behavior of the stack. 
  3974.  
  3975. Elements are added at and deleted from the same end, which is called the top of 
  3976. the stack.  Consequently, the elements of a stack are in reverse chronological 
  3977. order. 
  3978.  
  3979. A stack is characterized by a "last-in, first-out" (LIFO) behavior. 
  3980.  
  3981.  
  3982. ΓòÉΓòÉΓòÉ 3.7.1. Customizing ΓòÉΓòÉΓòÉ
  3983.  
  3984. This section describes the implementation variants supported by the Stack Class 
  3985. and the generic parameters available for selecting these variants. 
  3986.  
  3987.  
  3988. ΓòÉΓòÉΓòÉ 3.7.1.1. Implementation Variants ΓòÉΓòÉΓòÉ
  3989.  
  3990. The Stack implementation bases on another Class: 
  3991.  
  3992. Deque 
  3993.  
  3994. The performance characteristics of the Stack are the same as those of the 
  3995. Deque. 
  3996.  
  3997.  
  3998. ΓòÉΓòÉΓòÉ 3.7.2. Usage Notes ΓòÉΓòÉΓòÉ
  3999.  
  4000. The use of the Stack Class is illustrated in a  reftype=hd.coding example 
  4001. provided with the IBM Class Library: Collection Classes. 
  4002.  
  4003.  
  4004. ΓòÉΓòÉΓòÉ 3.7.3. Declarations ΓòÉΓòÉΓòÉ
  4005.  
  4006. template < class Element >
  4007. class IStack  {
  4008. public:
  4009.   class Cursor : ICursor {
  4010.     Element& element ();
  4011.     void setToLast ();
  4012.     void setToPrevious ();
  4013.     Boolean operator== (Cursor const& cursor);
  4014.     Boolean operator!= (Cursor const& cursor);
  4015.   };
  4016.                   IStack             (INumber
  4017.                                                numberOfElements = 100,
  4018.                                                IBoundIndicator =
  4019.                                                IUnbounded);
  4020.                   IStack             (IStack < Element > const&);
  4021.    IStack < Element >&    operator =                  (IStack < Element > const&);
  4022.                  ~IStack             ();
  4023.    Boolean        add                         (Element const&);
  4024.    Boolean        add                         (Element const&,
  4025.                                                ICursor&);
  4026.    void           addAllFrom                  (IStack < Element > const&);
  4027.    Element const& elementAt                   (ICursor const&) const;
  4028.    Element&       elementAt                   (ICursor const&);
  4029.    Element const& anyElement                  () const;
  4030.    void           removeAt                    (ICursor const&);
  4031.    INumber        removeAll                   (Boolean (*property)
  4032.                                                (Element const&, void*),
  4033.                                                void* additionalArgument = 0);
  4034.    void           replaceAt                   (ICursor const&,
  4035.                                                Element const&);
  4036.    void           removeAll                   ();
  4037.    Boolean        isBounded                   () const;
  4038.    INumber        maxNumberOfElements         () const;
  4039.    INumber        numberOfElements            () const;
  4040.    Boolean        isEmpty                     () const;
  4041.    Boolean        isFull                      () const;
  4042.    ICursor*       newCursor                   () const;
  4043.    Boolean        setToFirst                  (ICursor&) const;
  4044.    Boolean        setToNext                   (ICursor&) const;
  4045.    Boolean        allElementsDo               (Boolean (*function)
  4046.                                                   (Element&, void*),
  4047.                                                void* additionalArgument = 0);
  4048.    Boolean        allElementsDo               (IIterator <Element>&);
  4049.    Boolean        allElementsDo               (Boolean (*function)
  4050.                                                (Element const&, void*),
  4051.                                                void* additionalArgument = 0)
  4052.                                                const;
  4053.    Boolean        allElementsDo               (IConstantIterator
  4054.                                                   <Element>&) const;
  4055.    void           removeLast                  ();
  4056.    void           removeAtPosition            (IPosition);
  4057.    Element const& firstElement                () const;
  4058.    Element const& lastElement                 () const;
  4059.    Element const& elementAtPosition           (IPosition) const;
  4060.    Boolean        setToLast                   (ICursor&) const;
  4061.    Boolean        setToPrevious               (ICursor&) const;
  4062.    void           setToPosition               (IPosition,
  4063.                                                ICursor&) const;
  4064.    Boolean        isFirst                     (ICursor const&) const;
  4065.    Boolean        isLast                      (ICursor const&) const;
  4066.    long           compare                     (IStack < Element > const&,
  4067.                                                long (*comparisonFunction)
  4068.                                                   (Element const&,
  4069.                                                   Element const&)) const;
  4070.    void           addAsLast                   (Element const&);
  4071.    void           addAsLast                   (Element const&,
  4072.                                                ICursor&);
  4073.    void           addAsNext                   (Element const&,
  4074.                                                ICursor&);
  4075.    void           addAsPrevious               (Element const&,
  4076.                                                ICursor&);
  4077.    void           addAtPosition               (IPosition,
  4078.                                                Element const&);
  4079.    void           addAtPosition               (IPosition,
  4080.                                                Element const&,
  4081.                                                ICursor&);
  4082.    void           sort                        (long (*comparisonFunction)
  4083.                                                (Element const&,
  4084.                                                Element const&));
  4085.    void           push                        (Element const&);
  4086.    void           push                        (Element const&,
  4087.                                                ICursor&);
  4088.    void           pop                         ();
  4089.    void           pop                         (Element&);
  4090.    Element const& top                         () const;
  4091. };
  4092.  
  4093.  
  4094. ΓòÉΓòÉΓòÉ 3.7.4. Coding Example ΓòÉΓòÉΓòÉ
  4095.  
  4096. /*--------------------------------------------------------------------------*\
  4097. *                                                                            *
  4098. | Example program of Building Block STACK.                                  |
  4099. *                                                                            *
  4100. \*--------------------------------------------------------------------------*/
  4101.  
  4102. #include <stdio.h>
  4103. #include <string.h>
  4104. #include <istack.h>
  4105. #include <istkseq.h>
  4106.  
  4107. /*---------------------- Building Block specification ----------------------*\
  4108. *                                                                            *
  4109. | A stack is specified,                                                      |
  4110. | It is to be linked, unbouded and contains pointers to character strings.   |
  4111. *                                                                            *
  4112. \*--------------------------------------------------------------------------*/
  4113.  
  4114.  
  4115. /*--------------------------------------------------------------------------*\
  4116. * Test variables                                                             *
  4117. \*--------------------------------------------------------------------------*/
  4118.  
  4119. char *String[9] = {
  4120.    "the",
  4121.    "quick",
  4122.    "brown",
  4123.    "fox",
  4124.    "jumps",
  4125.    "over",
  4126.    "a",
  4127.    "lazy",
  4128.    "dog"
  4129. };
  4130.  
  4131. typedef IStack <char*> SimpleStack;
  4132. typedef IIterator <char*> StackIterator;
  4133. class PrintClass : public StackIterator
  4134. {
  4135. public:
  4136.    Boolean applyTo(char *&w)
  4137.       {
  4138.       printf("%s\n",w);
  4139.       return(True);
  4140.       }
  4141. };
  4142.  
  4143. /*--------------------------------------------------------------------------*\
  4144. * Main program                                                               *
  4145. \*--------------------------------------------------------------------------*/
  4146. int main()
  4147. {
  4148.    SimpleStack Stack1, Stack2;
  4149.    char *S;
  4150.    PrintClass Print;
  4151.  
  4152.    // We specify two stacks.
  4153.    // First all the strings are pushed on the first stack,
  4154.    // Next, they are popped from the first and pushed on the second,
  4155.    // Finally they are popped from the second and printed
  4156.    // This results are the strings printed in the original order.
  4157.  
  4158.    int i;
  4159.  
  4160.    printf("\n*** Example of STACK use ***\n");
  4161.  
  4162.    for (i = 0; i < 9; i ++) {                // Put all strings in the stack
  4163.       Stack1.push(String[i]);                // Add it as top of the stack
  4164.       }
  4165.  
  4166.    while (!Stack1.isEmpty()) {
  4167.       Stack1.pop(S);                         // Pop from stack 1
  4168.       Stack2.push(S);                        // Add it on top of stack 2
  4169.       }
  4170.    printf("Output using AllElementsDo():\n");
  4171.    Stack2.allElementsDo(Print);
  4172.  
  4173.    printf("----------------------------\n");
  4174.  
  4175.    while (!Stack2.isEmpty()) {
  4176.       Stack2.pop(S);
  4177.       printf("Popped from Stack 2: [%s]\n",S);
  4178.       }
  4179.  
  4180.    printf("\n*** End of example ***\n");
  4181.  
  4182.    return(0);
  4183. }
  4184.  
  4185.  
  4186. ΓòÉΓòÉΓòÉ 3.8. Set ΓòÉΓòÉΓòÉ
  4187.  
  4188. A set is an unordered collection of zero or more elements. The values of the 
  4189. elements are relevant. 
  4190.  
  4191. Any two elements are equal if they have the same value, otherwise they are not 
  4192. equal (equal relation).  The elements of a set are unique, i.e. they are all of 
  4193. different values, that is, there are no duplicates.  A request to add an 
  4194. element which already exists, is ignored. 
  4195.  
  4196. "Figure: Combination of collection properties" gives an overview of the 
  4197. properties and the position of a set in respect to other flat collections. 
  4198.  
  4199. The elements of a set are also called the members of the set. 
  4200.  
  4201. If A and B are two sets, then B is called a subset of A or A a superset of B if 
  4202. and only if all members of B are also members of A.  The union of A and B is 
  4203. the set of elements which are members of A or B or both.  The intersection of A 
  4204. and B is the set of elements which are members of both A and B.  The difference 
  4205. of A and B (A minus B) is the set of elements which are members of A but not of 
  4206. B. 
  4207.  
  4208. Usually, elements are added to a set by means of the union operation.  Elements 
  4209. are deleted from a set by using the intersection or difference operation. 
  4210.  
  4211. It is convenient to offer additional operations, which allow adding a single 
  4212. element to a set and deleting a specified element from a set. 
  4213.  
  4214.  
  4215. ΓòÉΓòÉΓòÉ 3.8.1. Customizing ΓòÉΓòÉΓòÉ
  4216.  
  4217. This section describes the implementation variants supported by the Set Class 
  4218. and the generic parameters available for selecting these variants. 
  4219.  
  4220.  
  4221. ΓòÉΓòÉΓòÉ 3.8.1.1. Implementation Variants ΓòÉΓòÉΓòÉ
  4222.  
  4223. The implementation variants that can be chosen for the Set are depending on the 
  4224. Class on which the Set is based on, i.e.: 
  4225.  
  4226. KeySet 
  4227.  
  4228. A Set has the same performance characteristic as the KeySet it is based on. 
  4229.  
  4230.  
  4231. ΓòÉΓòÉΓòÉ 3.8.2. Usage Notes ΓòÉΓòÉΓòÉ
  4232.  
  4233. The use of the Set Class is illustrated in a  reftype=hd.coding example 
  4234. provided with the IBM Class Library: Collection Classes. 
  4235.  
  4236.  
  4237. ΓòÉΓòÉΓòÉ 3.8.3. Declarations ΓòÉΓòÉΓòÉ
  4238.  
  4239. template < class Element >
  4240. class ISet {
  4241. public:
  4242.   class Cursor : ICursor {
  4243.     Element& element ();
  4244.     Boolean operator== (Cursor const& cursor);
  4245.     Boolean operator!= (Cursor const& cursor);
  4246.   };
  4247.                   ISet             (INumber
  4248.                                                numberOfElements = 100,
  4249.                                                IBoundIndicator =
  4250.                                                IUnbounded);
  4251.                   ISet             (ISet < Element > const&);
  4252.    ISet < Element >&    operator =                  (ISet < Element > const&);
  4253.                  ~ISet             ();
  4254.    Boolean        add                         (Element const&);
  4255.    Boolean        add                         (Element const&,
  4256.                                                ICursor&);
  4257.    void           addAllFrom                  (ISet < Element > const&);
  4258.    Element const& elementAt                   (ICursor const&) const;
  4259.    Element&       elementAt                   (ICursor const&);
  4260.    Element const& anyElement                  () const;
  4261.    void           removeAt                    (ICursor const&);
  4262.    INumber        removeAll                   (Boolean (*property)
  4263.                                                (Element const&, void*),
  4264.                                                void* additionalArgument = 0);
  4265.    void           replaceAt                   (ICursor const&,
  4266.                                                Element const&);
  4267.    void           removeAll                   ();
  4268.    Boolean        isBounded                   () const;
  4269.    INumber        maxNumberOfElements         () const;
  4270.    INumber        numberOfElements            () const;
  4271.    Boolean        isEmpty                     () const;
  4272.    Boolean        isFull                      () const;
  4273.    ICursor*       newCursor                   () const;
  4274.    Boolean        setToFirst                  (ICursor&) const;
  4275.    Boolean        setToNext                   (ICursor&) const;
  4276.    Boolean        allElementsDo               (Boolean (*function)
  4277.                                                   (Element&, void*),
  4278.                                                void* additionalArgument = 0);
  4279.    Boolean        allElementsDo               (IIterator <Element>&);
  4280.    Boolean        allElementsDo               (Boolean (*function)
  4281.                                                (Element const&, void*),
  4282.                                                void* additionalArgument = 0)
  4283.                                                const;
  4284.    Boolean        allElementsDo               (IConstantIterator
  4285.                                                   <Element>&) const;
  4286.    Boolean        contains                    (Element const&) const;
  4287.    Boolean        containsAllFrom             (ISet < Element > const&) const;
  4288.    Boolean        locate                      (Element const&, ICursor&)
  4289.                                                const;
  4290.    Boolean        locateOrAdd                 (Element const&);
  4291.    Boolean        locateOrAdd                 (Element const&,
  4292.                                                ICursor&);
  4293.    Boolean        remove                      (Element const&);
  4294.    Boolean        operator ==                 (ISet < Element > const&) const;
  4295.    Boolean        operator !=                 (ISet < Element > const&) const;
  4296.    void           unionWith                   (ISet < Element > const&);
  4297.    void           intersectionWith            (ISet < Element > const&);
  4298.    void           differenceWith              (ISet < Element > const&);
  4299.    void           addUnion                    (ISet < Element > const&,
  4300.                                                ISet < Element > const&);
  4301.    void           addIntersection             (ISet < Element > const&,
  4302.                                                ISet < Element > const&);
  4303.    void           addDifference               (ISet < Element > const&,
  4304.                                                ISet < Element > const&);
  4305. };
  4306.  
  4307.  
  4308. ΓòÉΓòÉΓòÉ 3.8.4. Coding Example ΓòÉΓòÉΓòÉ
  4309.  
  4310. /*--------------------------------------------------------------------------*\
  4311. *                                                                            *
  4312. | Example of using the Building Block ISet.                                  |
  4313. *                                                                            *
  4314. \*--------------------------------------------------------------------------*/
  4315.  
  4316. #include <iostream.h>
  4317.  
  4318. /*---------------------- Building Block specification ----------------------*\
  4319. *                                                                            *
  4320. | A Set is specified.                                                        |
  4321. | It is based on a Sorted Mapping.                                           |
  4322. | The Sorted Mapping is based on a Linked Sequence.                          |
  4323. | The elements stored in the Set are integers.                               |
  4324. *                                                                            *
  4325. \*--------------------------------------------------------------------------*/
  4326.  
  4327. #include <iset.h>              //  ISetOnSortedMapping
  4328.  
  4329. typedef ISet <int> IntSet;
  4330.  
  4331. /*--------------------------------------------------------------------------*\
  4332. * Iterator                                                                   *
  4333. \*--------------------------------------------------------------------------*/
  4334. class PrintClass : public IIterator<int>
  4335. {
  4336.   public:
  4337.     virtual Boolean applyTo(int& i)
  4338.       { cout << " " << i << " "; return True;}
  4339. };
  4340.  
  4341.  
  4342. /*--------------------------------------------------------------------------*\
  4343. * Local prototype                                                            *
  4344. \*--------------------------------------------------------------------------*/
  4345. void    List(char *, IntSet &);
  4346.  
  4347. /*--------------------------------------------------------------------------*\
  4348. * Main program                                                               *
  4349. \*--------------------------------------------------------------------------*/
  4350. int main ()
  4351. {
  4352.    IntSet odd, prime;
  4353.    IntSet oddPrime, evenPrime;
  4354.  
  4355.    int One = 1, Two = 2, Three = 3, Five = 5, Seven = 7, Nine = 9;
  4356.  
  4357.    cout << "\n*** Example of ISet use ***\n";
  4358.  
  4359. // Fill odd set with odd integers < 10
  4360.    odd.add( One );
  4361.    odd.add( Three );
  4362.    odd.add( Five );
  4363.    odd.add( Seven );
  4364.    odd.add( Nine );
  4365.    List("Odds less than 10:", odd);
  4366.  
  4367. // Fill prime set with primes < 10
  4368.    prime.add( Two );
  4369.    prime.add( Three );
  4370.    prime.add( Five );
  4371.    prime.add( Seven );
  4372.    List("Primes less than 10:", prime);
  4373.  
  4374. // Intersect 'Odd' and 'Prime' to give 'OddPrime'
  4375.    oddPrime.addIntersection( odd, prime);
  4376.    List("Odd primes less than 10:", oddPrime);
  4377.  
  4378. // Subtract all 'Odd' from 'Prime' giving 'EvenPrime'
  4379.    evenPrime.addDifference( prime, oddPrime);
  4380.    List("Even primes less than 10:", evenPrime);
  4381.  
  4382.    cout << "\n*** End of example ***\n";
  4383.  
  4384.    return(0);
  4385. }
  4386.  
  4387. /*--------------------------------------------------------------------------*\
  4388. * Local function                                                             *
  4389. \*--------------------------------------------------------------------------*/
  4390.  
  4391. void List(char *Message, IntSet &anIntSet)
  4392. {
  4393.    PrintClass Print;
  4394.  
  4395.    cout << Message;
  4396.    anIntSet.allElementsDo(Print);
  4397.    cout << "\n";
  4398. }
  4399.  
  4400.  
  4401. ΓòÉΓòÉΓòÉ 3.8.5. Coding Example ΓòÉΓòÉΓòÉ
  4402.  
  4403. #include <iset.h>
  4404.  
  4405. #include "cocktail.h"
  4406. #include <iostream.h>
  4407.  
  4408. typedef ISet <Cocktail> Cocktails;
  4409.  
  4410. void list_ingredients(Cocktails const&);
  4411.  
  4412. main() {
  4413.     Cocktails cocktail;
  4414.  
  4415.     Cocktail TS("Tequila Sunrise");
  4416.     TS.add_ingredient(Ingdt("Tequila"));
  4417.     TS.add_ingredient(Ingdt("Grenadine Sirup"));
  4418.     TS.add_ingredient(Ingdt("Orange Juice"));
  4419.     cocktail.add(TS);
  4420.     Cocktail SD("Screw Driver");
  4421.     SD.add_ingredient(Ingdt("Wodka"));
  4422.     SD.add_ingredient(Ingdt("Orange Juice"));
  4423.     cocktail.add(SD);
  4424.     Cocktail BD("Bull Dog");
  4425.     BD.add_ingredient(Ingdt("Rum"));
  4426.     BD.add_ingredient(Ingdt("Wodka"));
  4427.     BD.add_ingredient(Ingdt("Bitter Lemon"));
  4428.     cocktail.add(BD);
  4429.  
  4430.     list_ingredients(cocktail);
  4431.  
  4432.     Cocktails::Cursor ctailcursor(cocktail);
  4433.  
  4434.     cocktail.locate(BD, ctailcursor);
  4435.     cocktail.elementAt(ctailcursor).set_make(False);
  4436.     list_ingredients(cocktail);
  4437.  
  4438.     cocktail.locate(BD,ctailcursor);
  4439.     cocktail.elementAt(ctailcursor).set_make(True);
  4440.     cocktail.locate(TS, ctailcursor);
  4441.     cocktail.elementAt(ctailcursor).set_make(False);
  4442.     list_ingredients(cocktail);
  4443.  
  4444.  
  4445.     return 0;
  4446. }
  4447.  
  4448. void list_ingredients(Cocktails const& cocktail) {
  4449.     Cocktails::Cursor ctailcursor(cocktail);
  4450.     IngSet neededIngdt;
  4451.     IngSet::Cursor ingcursor(neededIngdt);
  4452.     cout<<"\n\nTo make  : ";
  4453.     for(ctailcursor.setToFirst(); ctailcursor.isValid(); ctailcursor.setToNext()) {
  4454.         if (cocktail.elementAt(ctailcursor).get_make()) {
  4455.             cout<<"   "<<cocktail.elementAt(ctailcursor).get_name();
  4456.             neededIngdt.unionWith(cocktail.elementAt(ctailcursor).get_ingredients());
  4457.         }
  4458.     }
  4459.     cout<<"\nyou need : ";
  4460.     for (ingcursor.setToFirst(); ingcursor.isValid(); ingcursor.setToNext()) {
  4461.         cout<<"   "<<neededIngdt.elementAt(ingcursor).get_name();
  4462.     }
  4463.     cout<<"\n\n\n";
  4464. }
  4465.  
  4466. Header File: 
  4467.  
  4468. #include <iset.h>
  4469.  
  4470. #include "cocktail.h"
  4471. #include <iostream.h>
  4472.  
  4473. typedef ISet <Cocktail> Cocktails;
  4474.  
  4475. void list_ingredients(Cocktails const&);
  4476.  
  4477. main() {
  4478.     Cocktails cocktail;
  4479.  
  4480.     Cocktail TS("Tequila Sunrise");
  4481.     TS.add_ingredient(Ingdt("Tequila"));
  4482.     TS.add_ingredient(Ingdt("Grenadine Sirup"));
  4483.     TS.add_ingredient(Ingdt("Orange Juice"));
  4484.     cocktail.add(TS);
  4485.     Cocktail SD("Screw Driver");
  4486.     SD.add_ingredient(Ingdt("Wodka"));
  4487.     SD.add_ingredient(Ingdt("Orange Juice"));
  4488.     cocktail.add(SD);
  4489.     Cocktail BD("Bull Dog");
  4490.     BD.add_ingredient(Ingdt("Rum"));
  4491.     BD.add_ingredient(Ingdt("Wodka"));
  4492.     BD.add_ingredient(Ingdt("Bitter Lemon"));
  4493.     cocktail.add(BD);
  4494.  
  4495.     list_ingredients(cocktail);
  4496.  
  4497.     Cocktails::Cursor ctailcursor(cocktail);
  4498.  
  4499.     cocktail.locate(BD, ctailcursor);
  4500.     cocktail.elementAt(ctailcursor).set_make(False);
  4501.     list_ingredients(cocktail);
  4502.  
  4503.     cocktail.locate(BD,ctailcursor);
  4504.     cocktail.elementAt(ctailcursor).set_make(True);
  4505.     cocktail.locate(TS, ctailcursor);
  4506.     cocktail.elementAt(ctailcursor).set_make(False);
  4507.     list_ingredients(cocktail);
  4508.  
  4509.  
  4510.     return 0;
  4511. }
  4512.  
  4513. void list_ingredients(Cocktails const& cocktail) {
  4514.     Cocktails::Cursor ctailcursor(cocktail);
  4515.     IngSet neededIngdt;
  4516.     IngSet::Cursor ingcursor(neededIngdt);
  4517.     cout<<"\n\nTo make  : ";
  4518.     for(ctailcursor.setToFirst(); ctailcursor.isValid(); ctailcursor.setToNext()) {
  4519.         if (cocktail.elementAt(ctailcursor).get_make()) {
  4520.             cout<<"   "<<cocktail.elementAt(ctailcursor).get_name();
  4521.             neededIngdt.unionWith(cocktail.elementAt(ctailcursor).get_ingredients());
  4522.         }
  4523.     }
  4524.     cout<<"\nyou need : ";
  4525.     for (ingcursor.setToFirst(); ingcursor.isValid(); ingcursor.setToNext()) {
  4526.         cout<<"   "<<neededIngdt.elementAt(ingcursor).get_name();
  4527.     }
  4528.     cout<<"\n\n\n";
  4529. }
  4530.  
  4531.  
  4532. ΓòÉΓòÉΓòÉ 3.9. KeySet ΓòÉΓòÉΓòÉ
  4533.  
  4534. KeySet is similar to a set, except that the elements can be accessed by key. 
  4535.  
  4536. A KeySet is an unordered collection of zero or more elements which have a key. 
  4537. The values of the elements are relevant. The value of the element is defined as 
  4538. the value of its key. Any two elements are equal if they have the same key, 
  4539. otherwise they are not equal.  The keys of a KeySet are unique, i.e. they are 
  4540. all of different values, that is, there are no duplicates.  A request to add an 
  4541. element whose key already exists, is rejected. "Figure: Behavior of add for 
  4542. unique and multiple collections" illustrates the different behaviour for map, 
  4543. relation, key set, and key bag when adding identical elements and elements with 
  4544. the same key. 
  4545.  
  4546. "Figure: Combination of collection properties" gives an overview of the 
  4547. properties and the position of a KeySet in respect to other flat collections. 
  4548.  
  4549. The key can be any part of the element, but must be the same part for all 
  4550. elements of a KeySet.  The remainder of the element is called the element body. 
  4551. The element body is not relevant for the behavior of the KeySet. Nevertheless, 
  4552. it can be replaced with new information.  The key of an element can not be 
  4553. changed. 
  4554.  
  4555. The set terminology applies to KeySets as well. 
  4556.  
  4557. Besides the set operations a KeySet allows addition, retrieval, replacement and 
  4558. deletion of single elements using the key, and it is possible to check whether 
  4559. an element with a specified key is contained in the KeySet. 
  4560.  
  4561.  
  4562. ΓòÉΓòÉΓòÉ 3.9.1. Customizing ΓòÉΓòÉΓòÉ
  4563.  
  4564. This section describes the implementation variants supported by the KeySet 
  4565. Class and the generic parameters available for selecting these variants. 
  4566.  
  4567.  
  4568. ΓòÉΓòÉΓòÉ 3.9.1.1. Implementation Variants ΓòÉΓòÉΓòÉ
  4569.  
  4570. The KeySet implementation can base on one of the following Classs: 
  4571.  
  4572. AVL Tree  This is the default. 
  4573.  
  4574. B* Tree 
  4575.  
  4576. Hash Table 
  4577.  
  4578. Key-Sorted Set 
  4579.  
  4580. The performance characteristics of the KeySet depend on the Class on which the 
  4581. KeySet is based. 
  4582.  
  4583.  
  4584. ΓòÉΓòÉΓòÉ 3.9.2. Usage Notes ΓòÉΓòÉΓòÉ
  4585.  
  4586. The use of the KeySet Class is illustrated in a -- Link Reference DictX not 
  4587. found -- reftype=hd.coding example provided with the IBM Class Library: 
  4588. Collection Classes. 
  4589.  
  4590.  
  4591. ΓòÉΓòÉΓòÉ 3.9.3. Declarations ΓòÉΓòÉΓòÉ
  4592.  
  4593. template < class Element, class Key >
  4594. class IKeySet {
  4595. public:
  4596.   class Cursor : ICursor {
  4597.     Element& element ();
  4598.     Boolean operator== (Cursor const& cursor);
  4599.     Boolean operator!= (Cursor const& cursor);
  4600.   };
  4601.                   IKeySet             (INumber
  4602.                                                numberOfElements = 100,
  4603.                                                IBoundIndicator =
  4604.                                                IUnbounded);
  4605.                   IKeySet             (IKeySet < Element, Key > const&);
  4606.    IKeySet < Element, Key >&    operator =                  (IKeySet < Element, Key > const&);
  4607.                  ~IKeySet             ();
  4608.    Boolean        add                         (Element const&);
  4609.    Boolean        add                         (Element const&,
  4610.                                                ICursor&);
  4611.    void           addAllFrom                  (IKeySet < Element, Key > const&);
  4612.    Element const& elementAt                   (ICursor const&) const;
  4613.    Element&       elementAt                   (ICursor const&);
  4614.    Element const& anyElement                  () const;
  4615.    void           removeAt                    (ICursor const&);
  4616.    INumber        removeAll                   (Boolean (*property)
  4617.                                                (Element const&, void*),
  4618.                                                void* additionalArgument = 0);
  4619.    void           replaceAt                   (ICursor const&,
  4620.                                                Element const&);
  4621.    void           removeAll                   ();
  4622.    Boolean        isBounded                   () const;
  4623.    INumber        maxNumberOfElements         () const;
  4624.    INumber        numberOfElements            () const;
  4625.    Boolean        isEmpty                     () const;
  4626.    Boolean        isFull                      () const;
  4627.    ICursor*       newCursor                   () const;
  4628.    Boolean        setToFirst                  (ICursor&) const;
  4629.    Boolean        setToNext                   (ICursor&) const;
  4630.    Boolean        allElementsDo               (Boolean (*function)
  4631.                                                   (Element&, void*),
  4632.                                                void* additionalArgument = 0);
  4633.    Boolean        allElementsDo               (IIterator <Element>&);
  4634.    Boolean        allElementsDo               (Boolean (*function)
  4635.                                                (Element const&, void*),
  4636.                                                void* additionalArgument = 0)
  4637.                                                const;
  4638.    Boolean        allElementsDo               (IConstantIterator
  4639.                                                   <Element>&) const;
  4640.    Key const&     key                         (Element const&) const;
  4641.    Boolean        containsElementWithKey      (Key const&) const;
  4642.    Boolean        containsAllKeysFrom         (IKeySet < Element, Key > const&) const;
  4643.    Boolean        locateElementWithKey        (Key const&, ICursor&)
  4644.                                                const;
  4645.    Boolean        replaceElementWithKey       (Element const&);
  4646.    Boolean        replaceElementWithKey       (Element const&,
  4647.                                                ICursor&);
  4648.    Boolean        locateOrAddElementWithKey   (Element const&);
  4649.    Boolean        locateOrAddElementWithKey   (Element const&,
  4650.                                                ICursor&);
  4651.    Boolean        addOrReplaceElementWithKey  (Element const&);
  4652.    Boolean        addOrReplaceElementWithKey  (Element const&,
  4653.                                                ICursor&);
  4654.    Boolean        removeElementWithKey        (Key const&);
  4655.    Element const& elementWithKey              (Key const&) const;
  4656.    Element&       elementWithKey              (Key const&);
  4657. };
  4658.  
  4659.  
  4660. ΓòÉΓòÉΓòÉ 3.10. Sorted Set ΓòÉΓòÉΓòÉ
  4661.  
  4662. A sorted set is a collection of zero or more elements in which a linear order 
  4663. of succession is maintained, with a first and a last element. Each element but 
  4664. the first one has a predecessor, and each element but the last one has a 
  4665. successor. The values of the elements are relevant. 
  4666.  
  4667. The elements appear in an order in such a way that the value of each element is 
  4668. less than or equal to the value of its successor, if any. 
  4669.  
  4670. The element with the smallest value currently in a sorted set, is called the 
  4671. first element.  The element with the largest value is called the last element. 
  4672.  
  4673. When an element is added, it is placed in the sorted set according to the 
  4674. defined ordering relation. 
  4675.  
  4676. "Figure: Combination of collection properties" gives an overview of the 
  4677. properties and the position of a sorted set in respect to other flat 
  4678. collections. 
  4679.  
  4680.  
  4681. ΓòÉΓòÉΓòÉ 3.10.1. Declarations ΓòÉΓòÉΓòÉ
  4682.  
  4683. template < class Element >
  4684. class ISortedSet {
  4685. public:
  4686.   class Cursor : ICursor {
  4687.     Element& element ();
  4688.     void setToLast ();
  4689.     void setToPrevious ();
  4690.     Boolean operator== (Cursor const& cursor);
  4691.     Boolean operator!= (Cursor const& cursor);
  4692.   };
  4693.                   ISortedSet             (INumber
  4694.                                                numberOfElements = 100,
  4695.                                                IBoundIndicator =
  4696.                                                IUnbounded);
  4697.                   ISortedSet             (ISortedSet < Element > const&);
  4698.    ISortedSet < Element >&    operator =                  (ISortedSet < Element > const&);
  4699.                  ~ISortedSet             ();
  4700.    Boolean        add                         (Element const&);
  4701.    Boolean        add                         (Element const&,
  4702.                                                ICursor&);
  4703.    void           addAllFrom                  (ISortedSet < Element > const&);
  4704.    Element const& elementAt                   (ICursor const&) const;
  4705.    Element&       elementAt                   (ICursor const&);
  4706.    Element const& anyElement                  () const;
  4707.    void           removeAt                    (ICursor const&);
  4708.    INumber        removeAll                   (Boolean (*property)
  4709.                                                (Element const&, void*),
  4710.                                                void* additionalArgument = 0);
  4711.    void           replaceAt                   (ICursor const&,
  4712.                                                Element const&);
  4713.    void           removeAll                   ();
  4714.    Boolean        isBounded                   () const;
  4715.    INumber        maxNumberOfElements         () const;
  4716.    INumber        numberOfElements            () const;
  4717.    Boolean        isEmpty                     () const;
  4718.    Boolean        isFull                      () const;
  4719.    ICursor*       newCursor                   () const;
  4720.    Boolean        setToFirst                  (ICursor&) const;
  4721.    Boolean        setToNext                   (ICursor&) const;
  4722.    Boolean        allElementsDo               (Boolean (*function)
  4723.                                                   (Element&, void*),
  4724.                                                void* additionalArgument = 0);
  4725.    Boolean        allElementsDo               (IIterator <Element>&);
  4726.    Boolean        allElementsDo               (Boolean (*function)
  4727.                                                (Element const&, void*),
  4728.                                                void* additionalArgument = 0)
  4729.                                                const;
  4730.    Boolean        allElementsDo               (IConstantIterator
  4731.                                                   <Element>&) const;
  4732.    Boolean        contains                    (Element const&) const;
  4733.    Boolean        containsAllFrom             (ISortedSet < Element > const&) const;
  4734.    Boolean        locate                      (Element const&, ICursor&)
  4735.                                                const;
  4736.    Boolean        locateOrAdd                 (Element const&);
  4737.    Boolean        locateOrAdd                 (Element const&,
  4738.                                                ICursor&);
  4739.    Boolean        remove                      (Element const&);
  4740.    Boolean        operator ==                 (ISortedSet < Element > const&) const;
  4741.    Boolean        operator !=                 (ISortedSet < Element > const&) const;
  4742.    void           unionWith                   (ISortedSet < Element > const&);
  4743.    void           intersectionWith            (ISortedSet < Element > const&);
  4744.    void           differenceWith              (ISortedSet < Element > const&);
  4745.    void           addUnion                    (ISortedSet < Element > const&,
  4746.                                                ISortedSet < Element > const&);
  4747.    void           addIntersection             (ISortedSet < Element > const&,
  4748.                                                ISortedSet < Element > const&);
  4749.    void           addDifference               (ISortedSet < Element > const&,
  4750.                                                ISortedSet < Element > const&);
  4751.    void           removeFirst                 ();
  4752.    void           removeLast                  ();
  4753.    void           removeAtPosition            (IPosition);
  4754.    Element const& firstElement                () const;
  4755.    Element const& lastElement                 () const;
  4756.    Element const& elementAtPosition           (IPosition) const;
  4757.    Boolean        setToLast                   (ICursor&) const;
  4758.    Boolean        setToPrevious               (ICursor&) const;
  4759.    void           setToPosition               (IPosition,
  4760.                                                ICursor&) const;
  4761.    Boolean        isFirst                     (ICursor const&) const;
  4762.    Boolean        isLast                      (ICursor const&) const;
  4763.    long           compare                     (ISortedSet < Element > const&,
  4764.                                                long (*comparisonFunction)
  4765.                                                   (Element const&,
  4766.                                                   Element const&)) const;
  4767. };
  4768.  
  4769.  
  4770. ΓòÉΓòÉΓòÉ 3.11. Key-Sorted Set ΓòÉΓòÉΓòÉ
  4771.  
  4772. A key-sorted set is a collection of zero or more elements with key. in which a 
  4773. linear order of succession is maintained, with a first and a last element. Each 
  4774. element but the first one has a predecessor, and each element but the last one 
  4775. has a successor. The values of the elements are relevant. The value of the 
  4776. element is defined as the value of its key. 
  4777.  
  4778. The elements have a key, which can be used to access the elements, and there is 
  4779. an ordering relation defined on the set of key values. The elements appear in 
  4780. an order in such a way that the key of each element is less than or equal to 
  4781. the key of its successor, if any. 
  4782.  
  4783. The element with the smallest key currently in a key-sorted set, is called the 
  4784. first element.  The element with the largest key is called the last element. 
  4785.  
  4786. The key can be any part of the element, but must be the same part for all 
  4787. elements of a key-sorted set.  The remainder of the element is called the 
  4788. element body. The element body is not relevant for the behavior of the 
  4789. key-sorted set. Nevertheless, it can be replaced with new information.  The key 
  4790. of an element can not be changed. 
  4791.  
  4792. When an element is added, it is placed in the key-sorted set according to the 
  4793. defined ordering relation. 
  4794.  
  4795. "Figure: Combination of collection properties" gives an overview of the 
  4796. properties and the position of a key-sorted set in respect to other flat 
  4797. collections. 
  4798.  
  4799.  
  4800. ΓòÉΓòÉΓòÉ 3.11.1. Customizing ΓòÉΓòÉΓòÉ
  4801.  
  4802. This section describes the implementation variants supported by the Key-Sorted 
  4803. Set Class and the generic parameters available for selecting these variants. 
  4804.  
  4805.  
  4806. ΓòÉΓòÉΓòÉ 3.11.1.1. Implementation Variants ΓòÉΓòÉΓòÉ
  4807.  
  4808. The implementation variants for the Key-Sorted Set are depending on the Class 
  4809. on which the Key-Sorted Set is based. 
  4810.  
  4811. The Key-Sorted Set implementation can base on one of the following Classs: 
  4812.  
  4813. AVL Tree 
  4814.  
  4815. B* Tree 
  4816.  
  4817. Sequence 
  4818.  
  4819. The performance characteristics of the Key-Sorted Set depend on the Class on 
  4820. which the Key-Sorted Set is based. 
  4821.  
  4822.  
  4823. ΓòÉΓòÉΓòÉ 3.11.2. Usage Notes ΓòÉΓòÉΓòÉ
  4824.  
  4825. The use of the Key-Sorted Set Class is illustrated in a -- Link Reference 
  4826. KslistX not found -- reftype=hd.coding example provided with the IBM Class 
  4827. Library: Collection Classes. 
  4828.  
  4829.  
  4830. ΓòÉΓòÉΓòÉ 3.11.3. Declarations ΓòÉΓòÉΓòÉ
  4831.  
  4832. template < class Element, class Key >
  4833. class IKeySortedSet {
  4834. public:
  4835.   class Cursor : ICursor {
  4836.     Element& element ();
  4837.     void setToLast ();
  4838.     void setToPrevious ();
  4839.     Boolean operator== (Cursor const& cursor);
  4840.     Boolean operator!= (Cursor const& cursor);
  4841.   };
  4842.                   IKeySortedSet             (INumber
  4843.                                                numberOfElements = 100,
  4844.                                                IBoundIndicator =
  4845.                                                IUnbounded);
  4846.                   IKeySortedSet             (IKeySortedSet < Element, Key > const&);
  4847.    IKeySortedSet < Element, Key >&    operator =    (IKeySortedSet < Element, Key > const&);
  4848.                  ~IKeySortedSet             ();
  4849.    Boolean        add                         (Element const&);
  4850.    Boolean        add                         (Element const&,
  4851.                                                ICursor&);
  4852.    void           addAllFrom                  (IKeySortedSet < Element, Key > const&);
  4853.    Element const& elementAt                   (ICursor const&) const;
  4854.    Element&       elementAt                   (ICursor const&);
  4855.    Element const& anyElement                  () const;
  4856.    void           removeAt                    (ICursor const&);
  4857.    INumber        removeAll                   (Boolean (*property)
  4858.                                                (Element const&, void*),
  4859.                                                void* additionalArgument = 0);
  4860.    void           replaceAt                   (ICursor const&,
  4861.                                                Element const&);
  4862.    void           removeAll                   ();
  4863.    Boolean        isBounded                   () const;
  4864.    INumber        maxNumberOfElements         () const;
  4865.    INumber        numberOfElements            () const;
  4866.    Boolean        isEmpty                     () const;
  4867.    Boolean        isFull                      () const;
  4868.    ICursor*       newCursor                   () const;
  4869.    Boolean        setToFirst                  (ICursor&) const;
  4870.    Boolean        setToNext                   (ICursor&) const;
  4871.    Boolean        allElementsDo               (Boolean (*function)
  4872.                                                   (Element&, void*),
  4873.                                                void* additionalArgument = 0);
  4874.    Boolean        allElementsDo               (IIterator <Element>&);
  4875.    Boolean        allElementsDo               (Boolean (*function)
  4876.                                                (Element const&, void*),
  4877.                                                void* additionalArgument = 0)
  4878.                                                const;
  4879.    Boolean        allElementsDo               (IConstantIterator
  4880.                                                   <Element>&) const;
  4881.    Key const&     key                         (Element const&) const;
  4882.    Boolean        containsElementWithKey      (Key const&) const;
  4883.    Boolean        containsAllKeysFrom         (IKeySortedSet < Element, Key > const&) const;
  4884.    Boolean        locateElementWithKey        (Key const&, ICursor&)
  4885.                                                const;
  4886.    Boolean        replaceElementWithKey       (Element const&);
  4887.    Boolean        replaceElementWithKey       (Element const&,
  4888.                                                ICursor&);
  4889.    Boolean        locateOrAddElementWithKey   (Element const&);
  4890.    Boolean        locateOrAddElementWithKey   (Element const&,
  4891.                                                ICursor&);
  4892.    Boolean        addOrReplaceElementWithKey  (Element const&);
  4893.    Boolean        addOrReplaceElementWithKey  (Element const&,
  4894.                                                ICursor&);
  4895.    Boolean        removeElementWithKey        (Key const&);
  4896.    Element const& elementWithKey              (Key const&) const;
  4897.    Element&       elementWithKey              (Key const&);
  4898.    void           removeFirst                 ();
  4899.    void           removeLast                  ();
  4900.    void           removeAtPosition            (IPosition);
  4901.    Element const& firstElement                () const;
  4902.    Element const& lastElement                 () const;
  4903.    Element const& elementAtPosition           (IPosition) const;
  4904.    Boolean        setToLast                   (ICursor&) const;
  4905.    Boolean        setToPrevious               (ICursor&) const;
  4906.    void           setToPosition               (IPosition,
  4907.                                                ICursor&) const;
  4908.    Boolean        isFirst                     (ICursor const&) const;
  4909.    Boolean        isLast                      (ICursor const&) const;
  4910.    long           compare                     (IKeySortedSet < Element, Key > const&,
  4911.                                                long (*comparisonFunction)
  4912.                                                   (Element const&,
  4913.                                                   Element const&)) const;
  4914. };
  4915.  
  4916.  
  4917. ΓòÉΓòÉΓòÉ 3.12. Priority Queue ΓòÉΓòÉΓòÉ
  4918.  
  4919. A priority queue is a collection of zero or more elements in which a linear 
  4920. order of succession is maintained, with a first and a last element. The 
  4921. priority of the elements is relevant. The priority is any part of the element, 
  4922. but it must be the same part for all elements. 
  4923.  
  4924. When an element is added, it is placed in the queue according to its priority. 
  4925. For access or deletion, the element with the largest priority is identified and 
  4926. deleted from the queue. 
  4927.  
  4928. A priority queue has a "largest-in, first-out" behavior. 
  4929.  
  4930. A variant of the priority queue is obtained by replacing the term "largest" by 
  4931. the term "smallest". 
  4932.  
  4933.  
  4934. ΓòÉΓòÉΓòÉ 3.12.1. Customizing ΓòÉΓòÉΓòÉ
  4935.  
  4936. This section describes the implementation variants supported by the Priority 
  4937. Queue Class and the generic parameters available for selecting these variants. 
  4938.  
  4939.  
  4940. ΓòÉΓòÉΓòÉ 3.12.1.1. Implementation Variants ΓòÉΓòÉΓòÉ
  4941.  
  4942. The implementation variants that can be chosen for the Priority Queue are 
  4943. depending on the Class on which the Priority Queue is based on, i.e.: 
  4944.  
  4945. Key-Sorted Set 
  4946.  
  4947. A Priority Queue has the same performance characteristic as the Key-Sorted Set 
  4948. it is based on. 
  4949.  
  4950.  
  4951. ΓòÉΓòÉΓòÉ 3.12.2. Usage Notes ΓòÉΓòÉΓòÉ
  4952.  
  4953. The use of the Priority Queue Class is illustrated in a -- Link Reference 
  4954. PrtyqX not found -- reftype=hd.coding example provided with the IBM Class 
  4955. Library: Collection Classes. 
  4956.  
  4957.  
  4958. ΓòÉΓòÉΓòÉ 3.12.3. Declarations ΓòÉΓòÉΓòÉ
  4959.  
  4960.  
  4961.  
  4962. to be completed
  4963.  
  4964.  
  4965. ΓòÉΓòÉΓòÉ 3.13. Bag ΓòÉΓòÉΓòÉ
  4966.  
  4967. A bag is similar to a set, except that the collection of elements may contain 
  4968. duplicates.  A request to add an element which already exists is not ignored. 
  4969.  
  4970. "Figure: Combination of collection properties" gives an overview of the 
  4971. properties and the position of a bag in respect to other flat collections. 
  4972.  
  4973. The set terminology applies to bags as well. 
  4974.  
  4975. The following rules apply for duplicates: If bag P contains the element el-x m 
  4976. times and bag Q contains the element el-x n times, then the union of P and Q 
  4977. contains the element el-x m+n times, the intersection of P and Q contains the 
  4978. element el-x MIN(m,n) times, and the difference of P and Q contains the element 
  4979. el-x m-n times if m is greater than n, and zero times if m is equal to or 
  4980. smaller than n. 
  4981.  
  4982. Usually elements are added to a bag by means of the union operation.  Elements 
  4983. are deleted from a bag using the intersection or difference operation. 
  4984. However, it is convenient to offer operations which allow adding a single 
  4985. element to a bag, or deleting a specified element from a bag. 
  4986.  
  4987.  
  4988. ΓòÉΓòÉΓòÉ 3.13.1. Customizing ΓòÉΓòÉΓòÉ
  4989.  
  4990.      To be completed .......... 
  4991.  
  4992.  
  4993. ΓòÉΓòÉΓòÉ 3.13.2. Declarations ΓòÉΓòÉΓòÉ
  4994.  
  4995. template < class Element >
  4996. class IBag {
  4997. public:
  4998.   class Cursor : ICursor {
  4999.     Element& element ();
  5000.     Boolean operator== (Cursor const& cursor);
  5001.     Boolean operator!= (Cursor const& cursor);
  5002.   };
  5003.                   IBag             (INumber
  5004.                                                numberOfElements = 100,
  5005.                                                IBoundIndicator =
  5006.                                                IUnbounded);
  5007.                   IBag             (IBag < Element > const&);
  5008.    IBag < Element >&    operator =                  (IBag < Element > const&);
  5009.                  ~IBag             ();
  5010.    Boolean        add                         (Element const&);
  5011.    Boolean        add                         (Element const&,
  5012.                                                ICursor&);
  5013.    void           addAllFrom                  (IBag < Element > const&);
  5014.    Element const& elementAt                   (ICursor const&) const;
  5015.    Element&       elementAt                   (ICursor const&);
  5016.    Element const& anyElement                  () const;
  5017.    void           removeAt                    (ICursor const&);
  5018.    INumber        removeAll                   (Boolean (*property)
  5019.                                                (Element const&, void*),
  5020.                                                void* additionalArgument = 0);
  5021.    void           replaceAt                   (ICursor const&,
  5022.                                                Element const&);
  5023.    void           removeAll                   ();
  5024.    Boolean        isBounded                   () const;
  5025.    INumber        maxNumberOfElements         () const;
  5026.    INumber        numberOfElements            () const;
  5027.    Boolean        isEmpty                     () const;
  5028.    Boolean        isFull                      () const;
  5029.    ICursor*       newCursor                   () const;
  5030.    Boolean        setToFirst                  (ICursor&) const;
  5031.    Boolean        setToNext                   (ICursor&) const;
  5032.    Boolean        allElementsDo               (Boolean (*function)
  5033.                                                   (Element&, void*),
  5034.                                                void* additionalArgument = 0);
  5035.    Boolean        allElementsDo               (IIterator <Element>&);
  5036.    Boolean        allElementsDo               (Boolean (*function)
  5037.                                                (Element const&, void*),
  5038.                                                void* additionalArgument = 0)
  5039.                                                const;
  5040.    Boolean        allElementsDo               (IConstantIterator
  5041.                                                   <Element>&) const;
  5042.    Boolean        contains                    (Element const&) const;
  5043.    Boolean        containsAllFrom             (IBag < Element > const&) const;
  5044.    Boolean        locate                      (Element const&, ICursor&)
  5045.                                                const;
  5046.    Boolean        locateOrAdd                 (Element const&);
  5047.    Boolean        locateOrAdd                 (Element const&,
  5048.                                                ICursor&);
  5049.    Boolean        remove                      (Element const&);
  5050.    INumber        numberOfOccurrences         (Element const&) const;
  5051.    Boolean        locateNext                  (Element const&, ICursor&)
  5052.                                                const;
  5053.    INumber        removeAllOccurrences        (Element const&);
  5054.    INumber        numberOfDifferentElements   () const;
  5055.    Boolean        setToNextDifferentElement   (ICursor&) const;
  5056.    Boolean        operator ==                 (IBag < Element > const&) const;
  5057.    Boolean        operator !=                 (IBag < Element > const&) const;
  5058.    void           unionWith                   (IBag < Element > const&);
  5059.    void           intersectionWith            (IBag < Element > const&);
  5060.    void           differenceWith              (IBag < Element > const&);
  5061.    void           addUnion                    (IBag < Element > const&,
  5062.                                                IBag < Element > const&);
  5063.    void           addIntersection             (IBag < Element > const&,
  5064.                                                IBag < Element > const&);
  5065.    void           addDifference               (IBag < Element > const&,
  5066.                                                IBag < Element > const&);
  5067. };
  5068.  
  5069.  
  5070. ΓòÉΓòÉΓòÉ 3.14. Key Bag ΓòÉΓòÉΓòÉ
  5071.  
  5072. A key bag is similar to a bag except that all elements have a key. 
  5073.  
  5074. "Figure: Behavior of add for unique and multiple collections" illustrates the 
  5075. different behaviour for map, relation, key set, and key bag when adding 
  5076. identical elements and elements with the same key. 
  5077.  
  5078. "Figure: Combination of collection properties" gives an overview of the 
  5079. properties and the position of a key bag in respect to other flat collections. 
  5080.  
  5081.  
  5082. ΓòÉΓòÉΓòÉ 3.14.1. Customizing ΓòÉΓòÉΓòÉ
  5083.  
  5084.      To be completed .......... 
  5085.  
  5086.  
  5087. ΓòÉΓòÉΓòÉ 3.14.2. Declarations ΓòÉΓòÉΓòÉ
  5088.  
  5089. template  <class Element, class Key >
  5090. class IKeyBag {
  5091. public:
  5092.   class Cursor : ICursor {
  5093.     Element& element ();
  5094.     Boolean operator== (Cursor const& cursor);
  5095.     Boolean operator!= (Cursor const& cursor);
  5096.   };
  5097.                   IKeyBag             (INumber
  5098.                                                numberOfElements = 100,
  5099.                                                IBoundIndicator =
  5100.                                                IUnbounded);
  5101.                   IKeyBag             (IKeyBag < Element, Key > const&);
  5102.    IKeyBag < Element, Key >&    operator =                  (IKeyBag < Element, Key > const&);
  5103.                  ~IKeyBag             ();
  5104.    Boolean        add                         (Element const&);
  5105.    Boolean        add                         (Element const&,
  5106.                                                ICursor&);
  5107.    void           addAllFrom                  (IKeyBag < Element, Key > const&);
  5108.    Element const& elementAt                   (ICursor const&) const;
  5109.    Element&       elementAt                   (ICursor const&);
  5110.    Element const& anyElement                  () const;
  5111.    void           removeAt                    (ICursor const&);
  5112.    INumber        removeAll                   (Boolean (*property)
  5113.                                                (Element const&, void*),
  5114.                                                void* additionalArgument = 0);
  5115.    void           replaceAt                   (ICursor const&,
  5116.                                                Element const&);
  5117.    void           removeAll                   ();
  5118.    Boolean        isBounded                   () const;
  5119.    INumber        maxNumberOfElements         () const;
  5120.    INumber        numberOfElements            () const;
  5121.    Boolean        isEmpty                     () const;
  5122.    Boolean        isFull                      () const;
  5123.    ICursor*       newCursor                   () const;
  5124.    Boolean        setToFirst                  (ICursor&) const;
  5125.    Boolean        setToNext                   (ICursor&) const;
  5126.    Boolean        allElementsDo               (Boolean (*function)
  5127.                                                   (Element&, void*),
  5128.                                                void* additionalArgument = 0);
  5129.    Boolean        allElementsDo               (IIterator <Element>&);
  5130.    Boolean        allElementsDo               (Boolean (*function)
  5131.                                                (Element const&, void*),
  5132.                                                void* additionalArgument = 0)
  5133.                                                const;
  5134.    Boolean        allElementsDo               (IConstantIterator
  5135.                                                   <Element>&) const;
  5136.    Key const&     key                         (Element const&) const;
  5137.    Boolean        containsElementWithKey      (Key const&) const;
  5138.    Boolean        containsAllKeysFrom         (IKeyBag < Element, Key > const&) const;
  5139.    Boolean        locateElementWithKey        (Key const&, ICursor&)
  5140.                                                const;
  5141.    Boolean        replaceElementWithKey       (Element const&);
  5142.    Boolean        replaceElementWithKey       (Element const&,
  5143.                                                ICursor&);
  5144.    Boolean        locateOrAddElementWithKey   (Element const&);
  5145.    Boolean        locateOrAddElementWithKey   (Element const&,
  5146.                                                ICursor&);
  5147.    Boolean        addOrReplaceElementWithKey  (Element const&);
  5148.    Boolean        addOrReplaceElementWithKey  (Element const&,
  5149.                                                ICursor&);
  5150.    Boolean        removeElementWithKey        (Key const&);
  5151.    Element const& elementWithKey              (Key const&) const;
  5152.    Element&       elementWithKey              (Key const&);
  5153.    INumber        numberOfElementsWithKey     (Key const&) const;
  5154.    Boolean        locateNextElementWithKey    (Key const&,
  5155.                                                ICursor&) const;
  5156.    INumber        removeAllElementsWithKey    (Key const&);
  5157.    INumber        numberOfDifferentKeys       () const;
  5158.    Boolean        setToNextWithDifferentKey   (ICursor&) const;
  5159. };
  5160.  
  5161.  
  5162. ΓòÉΓòÉΓòÉ 3.15. Sorted Bag ΓòÉΓòÉΓòÉ
  5163.  
  5164. A sorted bag is similar to a bag except that all elements are sorted. 
  5165.  
  5166. "Figure: Combination of collection properties" gives an overview of the 
  5167. properties and the position of a sorted bag in respect to other flat 
  5168. collections. 
  5169.  
  5170.  
  5171. ΓòÉΓòÉΓòÉ 3.15.1. Customizing ΓòÉΓòÉΓòÉ
  5172.  
  5173.      To be completed .......... 
  5174.  
  5175.  
  5176. ΓòÉΓòÉΓòÉ 3.15.2. Declarations ΓòÉΓòÉΓòÉ
  5177.  
  5178. template < class Element >
  5179. class ISortedBag {
  5180. public:
  5181.   class Cursor : ICursor {
  5182.     Element& element ();
  5183.     void setToLast ();
  5184.     void setToPrevious ();
  5185.     Boolean operator== (Cursor const& cursor);
  5186.     Boolean operator!= (Cursor const& cursor);
  5187.   };
  5188.                   ISortedBag             (INumber
  5189.                                                numberOfElements = 100,
  5190.                                                IBoundIndicator =
  5191.                                                IUnbounded);
  5192.                   ISortedBag             (ISortedBag < Element > const&);
  5193.    ISortedBag < Element >&    operator =                  (ISortedBag < Element > const&);
  5194.                  ~ISortedBag             ();
  5195.    Boolean        add                         (Element const&);
  5196.    Boolean        add                         (Element const&,
  5197.                                                ICursor&);
  5198.    void           addAllFrom                  (ISortedBag < Element > const&);
  5199.    Element const& elementAt                   (ICursor const&) const;
  5200.    Element&       elementAt                   (ICursor const&);
  5201.    Element const& anyElement                  () const;
  5202.    void           removeAt                    (ICursor const&);
  5203.    INumber        removeAll                   (Boolean (*property)
  5204.                                                (Element const&, void*),
  5205.                                                void* additionalArgument = 0);
  5206.    void           replaceAt                   (ICursor const&,
  5207.                                                Element const&);
  5208.    void           removeAll                   ();
  5209.    Boolean        isBounded                   () const;
  5210.    INumber        maxNumberOfElements         () const;
  5211.    INumber        numberOfElements            () const;
  5212.    Boolean        isEmpty                     () const;
  5213.    Boolean        isFull                      () const;
  5214.    ICursor*       newCursor                   () const;
  5215.    Boolean        setToFirst                  (ICursor&) const;
  5216.    Boolean        setToNext                   (ICursor&) const;
  5217.    Boolean        allElementsDo               (Boolean (*function)
  5218.                                                   (Element&, void*),
  5219.                                                void* additionalArgument = 0);
  5220.    Boolean        allElementsDo               (IIterator <Element>&);
  5221.    Boolean        allElementsDo               (Boolean (*function)
  5222.                                                (Element const&, void*),
  5223.                                                void* additionalArgument = 0)
  5224.                                                const;
  5225.    Boolean        allElementsDo               (IConstantIterator
  5226.                                                   <Element>&) const;
  5227.    Boolean        contains                    (Element const&) const;
  5228.    Boolean        containsAllFrom             (ISortedBag < Element > const&) const;
  5229.    Boolean        locate                      (Element const&, ICursor&)
  5230.                                                const;
  5231.    Boolean        locateOrAdd                 (Element const&);
  5232.    Boolean        locateOrAdd                 (Element const&,
  5233.                                                ICursor&);
  5234.    Boolean        remove                      (Element const&);
  5235.    INumber        numberOfOccurrences         (Element const&) const;
  5236.    Boolean        locateNext                  (Element const&, ICursor&)
  5237.                                                const;
  5238.    INumber        removeAllOccurrences        (Element const&);
  5239.    INumber        numberOfDifferentElements   () const;
  5240.    Boolean        setToNextDifferentElement   (ICursor&) const;
  5241.    Boolean        operator ==                 (ISortedBag < Element > const&) const;
  5242.    Boolean        operator !=                 (ISortedBag < Element > const&) const;
  5243.    void           unionWith                   (ISortedBag < Element > const&);
  5244.    void           intersectionWith            (ISortedBag < Element > const&);
  5245.    void           differenceWith              (ISortedBag < Element > const&);
  5246.    void           addUnion                    (ISortedBag < Element > const&,
  5247.                                                ISortedBag < Element > const&);
  5248.    void           addIntersection             (ISortedBag < Element > const&,
  5249.                                                ISortedBag < Element > const&);
  5250.    void           addDifference               (ISortedBag < Element > const&,
  5251.                                                ISortedBag < Element > const&);
  5252.    void           removeFirst                 ();
  5253.    void           removeLast                  ();
  5254.    void           removeAtPosition            (IPosition);
  5255.    Element const& firstElement                () const;
  5256.    Element const& lastElement                 () const;
  5257.    Element const& elementAtPosition           (IPosition) const;
  5258.    Boolean        setToLast                   (ICursor&) const;
  5259.    Boolean        setToPrevious               (ICursor&) const;
  5260.    void           setToPosition               (IPosition,
  5261.                                                ICursor&) const;
  5262.    Boolean        isFirst                     (ICursor const&) const;
  5263.    Boolean        isLast                      (ICursor const&) const;
  5264.    long           compare                     (ISortedBag < Element > const&,
  5265.                                                long (*comparisonFunction)
  5266.                                                   (Element const&,
  5267.                                                   Element const&)) const;
  5268. };
  5269.  
  5270.  
  5271. ΓòÉΓòÉΓòÉ 3.16. Key Sorted Bag ΓòÉΓòÉΓòÉ
  5272.  
  5273. A key sorted bag is similar to a sorted bag except that all elements have a 
  5274. key. 
  5275.  
  5276. "Figure: Combination of collection properties" gives an overview of the 
  5277. properties and the position of a key sorted bag in respect to other flat 
  5278. collections. 
  5279.  
  5280.  
  5281. ΓòÉΓòÉΓòÉ 3.16.1. Customizing ΓòÉΓòÉΓòÉ
  5282.  
  5283.      To be completed .......... 
  5284.  
  5285.  
  5286. ΓòÉΓòÉΓòÉ 3.16.2. Declarations ΓòÉΓòÉΓòÉ
  5287.  
  5288. template < class Element, class Key >
  5289. class IKeySortedBag {
  5290. public:
  5291.   class Cursor : ICursor {
  5292.     Element& element ();
  5293.     void setToLast ();
  5294.     void setToPrevious ();
  5295.     Boolean operator== (Cursor const& cursor);
  5296.     Boolean operator!= (Cursor const& cursor);
  5297.   };
  5298.                   IKeySortedBag             (INumber
  5299.                                                numberOfElements = 100,
  5300.                                                IBoundIndicator =
  5301.                                                IUnbounded);
  5302.                   IKeySortedBag             (IKeySortedBag < Element, Key > const&);
  5303.    IKeySortedBag < Element, Key >&    operator =    (IKeySortedBag < Element, Key > const&);
  5304.                  ~IKeySortedBag             ();
  5305.    Boolean        add                         (Element const&);
  5306.    Boolean        add                         (Element const&,
  5307.                                                ICursor&);
  5308.    void           addAllFrom                  (IKeySortedBag < Element, Key > const&);
  5309.    Element const& elementAt                   (ICursor const&) const;
  5310.    Element&       elementAt                   (ICursor const&);
  5311.    Element const& anyElement                  () const;
  5312.    void           removeAt                    (ICursor const&);
  5313.    INumber        removeAll                   (Boolean (*property)
  5314.                                                (Element const&, void*),
  5315.                                                void* additionalArgument = 0);
  5316.    void           replaceAt                   (ICursor const&,
  5317.                                                Element const&);
  5318.    void           removeAll                   ();
  5319.    Boolean        isBounded                   () const;
  5320.    INumber        maxNumberOfElements         () const;
  5321.    INumber        numberOfElements            () const;
  5322.    Boolean        isEmpty                     () const;
  5323.    Boolean        isFull                      () const;
  5324.    ICursor*       newCursor                   () const;
  5325.    Boolean        setToFirst                  (ICursor&) const;
  5326.    Boolean        setToNext                   (ICursor&) const;
  5327.    Boolean        allElementsDo               (Boolean (*function)
  5328.                                                   (Element&, void*),
  5329.                                                void* additionalArgument = 0);
  5330.    Boolean        allElementsDo               (IIterator <Element>&);
  5331.    Boolean        allElementsDo               (Boolean (*function)
  5332.                                                (Element const&, void*),
  5333.                                                void* additionalArgument = 0)
  5334.                                                const;
  5335.    Boolean        allElementsDo               (IConstantIterator
  5336.                                                   <Element>&) const;
  5337.    Key const&     key                         (Element const&) const;
  5338.    Boolean        containsElementWithKey      (Key const&) const;
  5339.    Boolean        containsAllKeysFrom         (IKeySortedBag < Element, Key > const&) const;
  5340.    Boolean        locateElementWithKey        (Key const&, ICursor&)
  5341.                                                const;
  5342.    Boolean        replaceElementWithKey       (Element const&);
  5343.    Boolean        replaceElementWithKey       (Element const&,
  5344.                                                ICursor&);
  5345.    Boolean        locateOrAddElementWithKey   (Element const&);
  5346.    Boolean        locateOrAddElementWithKey   (Element const&,
  5347.                                                ICursor&);
  5348.    Boolean        addOrReplaceElementWithKey  (Element const&);
  5349.    Boolean        addOrReplaceElementWithKey  (Element const&,
  5350.                                                ICursor&);
  5351.    Boolean        removeElementWithKey        (Key const&);
  5352.    Element const& elementWithKey              (Key const&) const;
  5353.    Element&       elementWithKey              (Key const&);
  5354.    INumber        numberOfElementsWithKey     (Key const&) const;
  5355.    Boolean        locateNextElementWithKey    (Key const&,
  5356.                                                ICursor&) const;
  5357.    INumber        removeAllElementsWithKey    (Key const&);
  5358.    INumber        numberOfDifferentKeys       () const;
  5359.    Boolean        setToNextWithDifferentKey   (ICursor&) const;
  5360.    void           removeFirst                 ();
  5361.    void           removeLast                  ();
  5362.    void           removeAtPosition            (IPosition);
  5363.    Element const& firstElement                () const;
  5364.    Element const& lastElement                 () const;
  5365.    Element const& elementAtPosition           (IPosition) const;
  5366.    Boolean        setToLast                   (ICursor&) const;
  5367.    Boolean        setToPrevious               (ICursor&) const;
  5368.    void           setToPosition               (IPosition,
  5369.                                                ICursor&) const;
  5370.    Boolean        isFirst                     (ICursor const&) const;
  5371.    Boolean        isLast                      (ICursor const&) const;
  5372.    long           compare                     (IKeySortedBag < Element, Key > const&,
  5373.                                                long (*comparisonFunction)
  5374.                                                   (Element const&,
  5375.                                                   Element const&)) const;
  5376. };
  5377.  
  5378.  
  5379. ΓòÉΓòÉΓòÉ 3.17. Map ΓòÉΓòÉΓòÉ
  5380.  
  5381. A map is an unordered collection of zero or more elements which have a key. The 
  5382. values of the elements are relevant. 
  5383.  
  5384. The keys of the elements are unique. That is you can't add an element if there 
  5385. is already an element in the map with the same key. "Figure: Behavior of add 
  5386. for unique and multiple collections" illustrates the different behaviour for 
  5387. map, relation, key set, and key bag when adding identical elements and elements 
  5388. with the same key. 
  5389.  
  5390. "Figure: Combination of collection properties" gives an overview of the 
  5391. properties and the position of a map in respect to other flat collections. 
  5392.  
  5393.  
  5394. ΓòÉΓòÉΓòÉ 3.17.1. Customizing ΓòÉΓòÉΓòÉ
  5395.  
  5396.      To be completed .......... 
  5397.  
  5398.  
  5399. ΓòÉΓòÉΓòÉ 3.17.2. Declarations ΓòÉΓòÉΓòÉ
  5400.  
  5401. template < class Element, class Key >
  5402. class IMap {
  5403. public:
  5404.   class Cursor : ICursor {
  5405.     Element& element ();
  5406.     Boolean operator== (Cursor const& cursor);
  5407.     Boolean operator!= (Cursor const& cursor);
  5408.   };
  5409.                   IMap             (INumber
  5410.                                                numberOfElements = 100,
  5411.                                                IBoundIndicator =
  5412.                                                IUnbounded);
  5413.                   IMap             (IMap < Element, Key > const&);
  5414.    IMap < Element, Key >&    operator =                  (IMap < Element, Key > const&);
  5415.                  ~IMap             ();
  5416.    Boolean        add                         (Element const&);
  5417.    Boolean        add                         (Element const&,
  5418.                                                ICursor&);
  5419.    void           addAllFrom                  (IMap < Element, Key > const&);
  5420.    Element const& elementAt                   (ICursor const&) const;
  5421.    Element&       elementAt                   (ICursor const&);
  5422.    Element const& anyElement                  () const;
  5423.    void           removeAt                    (ICursor const&);
  5424.    INumber        removeAll                   (Boolean (*property)
  5425.                                                (Element const&, void*),
  5426.                                                void* additionalArgument = 0);
  5427.    void           replaceAt                   (ICursor const&,
  5428.                                                Element const&);
  5429.    void           removeAll                   ();
  5430.    Boolean        isBounded                   () const;
  5431.    INumber        maxNumberOfElements         () const;
  5432.    INumber        numberOfElements            () const;
  5433.    Boolean        isEmpty                     () const;
  5434.    Boolean        isFull                      () const;
  5435.    ICursor*       newCursor                   () const;
  5436.    Boolean        setToFirst                  (ICursor&) const;
  5437.    Boolean        setToNext                   (ICursor&) const;
  5438.    Boolean        allElementsDo               (Boolean (*function)
  5439.                                                   (Element&, void*),
  5440.                                                void* additionalArgument = 0);
  5441.    Boolean        allElementsDo               (IIterator <Element>&);
  5442.    Boolean        allElementsDo               (Boolean (*function)
  5443.                                                (Element const&, void*),
  5444.                                                void* additionalArgument = 0)
  5445.                                                const;
  5446.    Boolean        allElementsDo               (IConstantIterator
  5447.                                                   <Element>&) const;
  5448.    Boolean        contains                    (Element const&) const;
  5449.    Boolean        containsAllFrom             (IMap < Element, Key > const&) const;
  5450.    Boolean        locate                      (Element const&, ICursor&)
  5451.                                                const;
  5452.    Boolean        locateOrAdd                 (Element const&);
  5453.    Boolean        locateOrAdd                 (Element const&,
  5454.                                                ICursor&);
  5455.    Boolean        remove                      (Element const&);
  5456.    Boolean        operator ==                 (IMap < Element, Key > const&) const;
  5457.    Boolean        operator !=                 (IMap < Element, Key > const&) const;
  5458.    void           unionWith                   (IMap < Element, Key > const&);
  5459.    void           intersectionWith            (IMap < Element, Key > const&);
  5460.    void           differenceWith              (IMap < Element, Key > const&);
  5461.    void           addUnion                    (IMap < Element, Key > const&,
  5462.                                                IMap < Element, Key > const&);
  5463.    void           addIntersection             (IMap < Element, Key > const&,
  5464.                                                IMap < Element, Key > const&);
  5465.    void           addDifference               (IMap < Element, Key > const&,
  5466.                                                IMap < Element, Key > const&);
  5467.    Key const&     key                         (Element const&) const;
  5468.    Boolean        containsElementWithKey      (Key const&) const;
  5469.    Boolean        containsAllKeysFrom         (IMap < Element, Key > const&) const;
  5470.    Boolean        locateElementWithKey        (Key const&, ICursor&)
  5471.                                                const;
  5472.    Boolean        replaceElementWithKey       (Element const&);
  5473.    Boolean        replaceElementWithKey       (Element const&,
  5474.                                                ICursor&);
  5475.    Boolean        locateOrAddElementWithKey   (Element const&);
  5476.    Boolean        locateOrAddElementWithKey   (Element const&,
  5477.                                                ICursor&);
  5478.    Boolean        addOrReplaceElementWithKey  (Element const&);
  5479.    Boolean        addOrReplaceElementWithKey  (Element const&,
  5480.                                                ICursor&);
  5481.    Boolean        removeElementWithKey        (Key const&);
  5482.    Element const& elementWithKey              (Key const&) const;
  5483.    Element&       elementWithKey              (Key const&);
  5484. };
  5485.  
  5486.  
  5487. ΓòÉΓòÉΓòÉ 3.18. Sorted Map ΓòÉΓòÉΓòÉ
  5488.  
  5489. A sorted map is similar to a map except that all elements are sorted by the 
  5490. value of the key. 
  5491.  
  5492. "Figure: Combination of collection properties" gives an overview of the 
  5493. properties and the position of a sorted map in respect to other flat 
  5494. collections. 
  5495.  
  5496.  
  5497. ΓòÉΓòÉΓòÉ 3.18.1. Customizing ΓòÉΓòÉΓòÉ
  5498.  
  5499.      To be completed .......... 
  5500.  
  5501.  
  5502. ΓòÉΓòÉΓòÉ 3.18.2. Declarations ΓòÉΓòÉΓòÉ
  5503.  
  5504. template < class Element, class Key >
  5505. class ISortedMap {
  5506. public:
  5507.   class Cursor : ICursor {
  5508.     Element& element ();
  5509.     void setToLast ();
  5510.     void setToPrevious ();
  5511.     Boolean operator== (Cursor const& cursor);
  5512.     Boolean operator!= (Cursor const& cursor);
  5513.   };
  5514.                   ISortedMap             (INumber
  5515.                                                numberOfElements = 100,
  5516.                                                IBoundIndicator =
  5517.                                                IUnbounded);
  5518.                   ISortedMap             (ISortedMap < Element, Key > const&);
  5519.    ISortedMap < Element, Key >&    operator =   (ISortedMap < Element, Key > const&);
  5520.                  ~ISortedMap             ();
  5521.    Boolean        add                         (Element const&);
  5522.    Boolean        add                         (Element const&,
  5523.                                                ICursor&);
  5524.    void           addAllFrom                  (ISortedMap < Element, Key > const&);
  5525.    Element const& elementAt                   (ICursor const&) const;
  5526.    Element&       elementAt                   (ICursor const&);
  5527.    Element const& anyElement                  () const;
  5528.    void           removeAt                    (ICursor const&);
  5529.    INumber        removeAll                   (Boolean (*property)
  5530.                                                (Element const&, void*),
  5531.                                                void* additionalArgument = 0);
  5532.    void           replaceAt                   (ICursor const&,
  5533.                                                Element const&);
  5534.    void           removeAll                   ();
  5535.    Boolean        isBounded                   () const;
  5536.    INumber        maxNumberOfElements         () const;
  5537.    INumber        numberOfElements            () const;
  5538.    Boolean        isEmpty                     () const;
  5539.    Boolean        isFull                      () const;
  5540.    ICursor*       newCursor                   () const;
  5541.    Boolean        setToFirst                  (ICursor&) const;
  5542.    Boolean        setToNext                   (ICursor&) const;
  5543.    Boolean        allElementsDo               (Boolean (*function)
  5544.                                                   (Element&, void*),
  5545.                                                void* additionalArgument = 0);
  5546.    Boolean        allElementsDo               (IIterator <Element>&);
  5547.    Boolean        allElementsDo               (Boolean (*function)
  5548.                                                (Element const&, void*),
  5549.                                                void* additionalArgument = 0)
  5550.                                                const;
  5551.    Boolean        allElementsDo               (IConstantIterator
  5552.                                                   <Element>&) const;
  5553.    Boolean        contains                    (Element const&) const;
  5554.    Boolean        containsAllFrom             (ISortedMap < Element, Key > const&) const;
  5555.    Boolean        locate                      (Element const&, ICursor&)
  5556.                                                const;
  5557.    Boolean        locateOrAdd                 (Element const&);
  5558.    Boolean        locateOrAdd                 (Element const&,
  5559.                                                ICursor&);
  5560.    Boolean        remove                      (Element const&);
  5561.    Boolean        operator ==                 (ISortedMap < Element, Key > const&) const;
  5562.    Boolean        operator !=                 (ISortedMap < Element, Key > const&) const;
  5563.    void           unionWith                   (ISortedMap < Element, Key > const&);
  5564.    void           intersectionWith            (ISortedMap < Element, Key > const&);
  5565.    void           differenceWith              (ISortedMap < Element, Key > const&);
  5566.    void           addUnion                    (ISortedMap < Element, Key > const&,
  5567.                                                ISortedMap < Element, Key > const&);
  5568.    void           addIntersection             (ISortedMap < Element, Key > const&,
  5569.                                                ISortedMap < Element, Key > const&);
  5570.    void           addDifference               (ISortedMap < Element, Key > const&,
  5571.                                                ISortedMap < Element, Key > const&);
  5572.    Key const&     key                         (Element const&) const;
  5573.    Boolean        containsElementWithKey      (Key const&) const;
  5574.    Boolean        containsAllKeysFrom         (ISortedMap < Element, Key > const&) const;
  5575.    Boolean        locateElementWithKey        (Key const&, ICursor&)
  5576.                                                const;
  5577.    Boolean        replaceElementWithKey       (Element const&);
  5578.    Boolean        replaceElementWithKey       (Element const&,
  5579.                                                ICursor&);
  5580.    Boolean        locateOrAddElementWithKey   (Element const&);
  5581.    Boolean        locateOrAddElementWithKey   (Element const&,
  5582.                                                ICursor&);
  5583.    Boolean        addOrReplaceElementWithKey  (Element const&);
  5584.    Boolean        addOrReplaceElementWithKey  (Element const&,
  5585.                                                ICursor&);
  5586.    Boolean        removeElementWithKey        (Key const&);
  5587.    Element const& elementWithKey              (Key const&) const;
  5588.    Element&       elementWithKey              (Key const&);
  5589.    void           removeFirst                 ();
  5590.    void           removeLast                  ();
  5591.    void           removeAtPosition            (IPosition);
  5592.    Element const& firstElement                () const;
  5593.    Element const& lastElement                 () const;
  5594.    Element const& elementAtPosition           (IPosition) const;
  5595.    Boolean        setToLast                   (ICursor&) const;
  5596.    Boolean        setToPrevious               (ICursor&) const;
  5597.    void           setToPosition               (IPosition,
  5598.                                                ICursor&) const;
  5599.    Boolean        isFirst                     (ICursor const&) const;
  5600.    Boolean        isLast                      (ICursor const&) const;
  5601.    long           compare                     (ISortedMap < Element, Key > const&,
  5602.                                                long (*comparisonFunction)
  5603.                                                   (Element const&,
  5604.                                                   Element const&)) const;
  5605. };
  5606.  
  5607.  
  5608. ΓòÉΓòÉΓòÉ 3.18.3. Coding Example ΓòÉΓòÉΓòÉ
  5609.  
  5610. #include "parcel.h"
  5611.  
  5612. #include <isrtmap.h>
  5613. #include <iostream.h>
  5614.  
  5615. ostream& operator<<(ostream& s, Parcel p) {
  5616.     if (p.now().getPlace()!=p.dest().getPlace()) {
  5617.         return s<< p.getID()<<": From "<<p.orig().getPlace()<<"("
  5618.          <<p.orig().getTime()<<") to "<<p.dest().getPlace()<<" is now at "
  5619.          <<p.now().getPlace()<<"("<<p.now().getTime()<<")";
  5620.     }
  5621.     else {
  5622.         return s<<p.getID()<<": From "<<p.orig().getPlace()<<"("
  5623.          <<p.orig().getTime()<<") to "<<p.now().getPlace()<<"("
  5624.          <<p.now().getTime()<<") delivered.";
  5625.     }
  5626. }
  5627.  
  5628. typedef ISortedMap<Parcel, char*> ParcelService;
  5629.  
  5630. void list(ParcelService const& p);
  5631.  
  5632. void update(ParcelService const& p, ParcelService& d);
  5633.  
  5634. main() {
  5635.  
  5636.     ParcelService ps;
  5637.     ParcelService delivered;
  5638.  
  5639.     ps.add(Parcel("Lobito", "Athen", 26.02, "26LoAt"));
  5640.     ps.add(Parcel("Angusta", "Canberra", 27.02, "27AnCa"));
  5641.     ps.add(Parcel("Wassenaar", "Shinagawa", 25.02, "25WaSh"));
  5642.     ps.add(Parcel("Kanpur", "Uster", 25.03, "25KaUs"));
  5643.     update(ps, delivered);
  5644.     list(ps);
  5645.  
  5646.     ps.elementWithKey("26LoAt").arrivedAt("Luanda", 28.02);
  5647.     ps.elementWithKey("27AnCa").arrivedAt("Atlanta", 28.02);
  5648.     ps.elementWithKey("25WaSh").arrivedAt("Amsterdam", 25.02);
  5649.     ps.elementWithKey("25KaUs").arrivedAt("Delhi", 25.03);
  5650.     update(ps, delivered);
  5651.     list(ps);
  5652.  
  5653.     ps.elementWithKey("26LoAt").arrivedAt("Athen", 28.02);
  5654.     ps.elementWithKey("25KaUs").arrivedAt("Zuerich", 26.03);
  5655.     update(ps, delivered);
  5656.     list(ps);
  5657.     list(delivered);
  5658.  
  5659.     ps.removeElementWithKey("26LoAt");
  5660.  
  5661.     ps.add(Parcel("Kanpur", "Uster", 27.04, "27KaUs"));
  5662.     ps.add(Parcel("Wassenaar","Shinagawa", 15.02, "25WaSh"));
  5663.     ps.elementWithKey("25KaUs").arrivedAt("Uster", 29.03);
  5664.     update(ps, delivered);
  5665.     list(ps);
  5666.  
  5667.  
  5668.     ParcelService::Cursor pscursor(ps);
  5669.  
  5670.     for (pscursor.setToFirst(); pscursor.isValid(); pscursor.setToNext()) {
  5671.         ps.elementAt(pscursor).arrivedAt(ps.elementAt(pscursor).dest().getPlace(), 30.02);
  5672.     }
  5673.     update(ps, delivered);
  5674.     list(ps);
  5675.     if (delivered.containsAllFrom(ps)) {
  5676.         cout<<"All delivered \n";
  5677.     }
  5678.     else {
  5679.         cout<<"Something very wrong is happening here \n";
  5680.     }
  5681.         return 0;
  5682. }
  5683.  
  5684.  
  5685. void list(ParcelService const& p) {
  5686.     ParcelService::Cursor pcursor(p);
  5687.     for(pcursor.setToFirst(); pcursor.isValid(); pcursor.setToNext()) {
  5688.         cout<<p.elementAt(pcursor)<<"\n";
  5689.     }
  5690.     cout<<"\n";
  5691. }
  5692.  
  5693. void update(ParcelService const& p, ParcelService& d) {
  5694.     ParcelService::Cursor pc(p);
  5695.  
  5696.     for (pc.setToFirst(); pc.isValid(); pc.setToNext()) {
  5697.         if (!d.contains(p.elementAt(pc))) {
  5698.             if (p.elementAt(pc).now().getPlace()==p.elementAt(pc).dest().getPlace()) {
  5699.                 d.add(p.elementAt(pc));
  5700.             }
  5701.         }
  5702.     }
  5703. }
  5704. Header File: 
  5705.  
  5706. #include "parcel.h"
  5707.  
  5708. #include <isrtmap.h>
  5709. #include <iostream.h>
  5710.  
  5711. ostream& operator<<(ostream& s, Parcel p) {
  5712.     if (p.now().getPlace()!=p.dest().getPlace()) {
  5713.         return s<< p.getID()<<": From "<<p.orig().getPlace()<<"("
  5714.          <<p.orig().getTime()<<") to "<<p.dest().getPlace()<<" is now at "
  5715.          <<p.now().getPlace()<<"("<<p.now().getTime()<<")";
  5716.     }
  5717.     else {
  5718.         return s<<p.getID()<<": From "<<p.orig().getPlace()<<"("
  5719.          <<p.orig().getTime()<<") to "<<p.now().getPlace()<<"("
  5720.          <<p.now().getTime()<<") delivered.";
  5721.     }
  5722. }
  5723.  
  5724. typedef ISortedMap<Parcel, char*> ParcelService;
  5725.  
  5726. void list(ParcelService const& p);
  5727.  
  5728. void update(ParcelService const& p, ParcelService& d);
  5729.  
  5730. main() {
  5731.  
  5732.     ParcelService ps;
  5733.     ParcelService delivered;
  5734.  
  5735.     ps.add(Parcel("Lobito", "Athen", 26.02, "26LoAt"));
  5736.     ps.add(Parcel("Angusta", "Canberra", 27.02, "27AnCa"));
  5737.     ps.add(Parcel("Wassenaar", "Shinagawa", 25.02, "25WaSh"));
  5738.     ps.add(Parcel("Kanpur", "Uster", 25.03, "25KaUs"));
  5739.     update(ps, delivered);
  5740.     list(ps);
  5741.  
  5742.     ps.elementWithKey("26LoAt").arrivedAt("Luanda", 28.02);
  5743.     ps.elementWithKey("27AnCa").arrivedAt("Atlanta", 28.02);
  5744.     ps.elementWithKey("25WaSh").arrivedAt("Amsterdam", 25.02);
  5745.     ps.elementWithKey("25KaUs").arrivedAt("Delhi", 25.03);
  5746.     update(ps, delivered);
  5747.     list(ps);
  5748.  
  5749.     ps.elementWithKey("26LoAt").arrivedAt("Athen", 28.02);
  5750.     ps.elementWithKey("25KaUs").arrivedAt("Zuerich", 26.03);
  5751.     update(ps, delivered);
  5752.     list(ps);
  5753.     list(delivered);
  5754.  
  5755.     ps.removeElementWithKey("26LoAt");
  5756.  
  5757.     ps.add(Parcel("Kanpur", "Uster", 27.04, "27KaUs"));
  5758.     ps.add(Parcel("Wassenaar","Shinagawa", 15.02, "25WaSh"));
  5759.     ps.elementWithKey("25KaUs").arrivedAt("Uster", 29.03);
  5760.     update(ps, delivered);
  5761.     list(ps);
  5762.  
  5763.  
  5764.     ParcelService::Cursor pscursor(ps);
  5765.  
  5766.     for (pscursor.setToFirst(); pscursor.isValid(); pscursor.setToNext()) {
  5767.         ps.elementAt(pscursor).arrivedAt(ps.elementAt(pscursor).dest().getPlace(), 30.02);
  5768.     }
  5769.     update(ps, delivered);
  5770.     list(ps);
  5771.     if (delivered.containsAllFrom(ps)) {
  5772.         cout<<"All delivered \n";
  5773.     }
  5774.     else {
  5775.         cout<<"Something very wrong is happening here \n";
  5776.     }
  5777.         return 0;
  5778. }
  5779.  
  5780.  
  5781. void list(ParcelService const& p) {
  5782.     ParcelService::Cursor pcursor(p);
  5783.     for(pcursor.setToFirst(); pcursor.isValid(); pcursor.setToNext()) {
  5784.         cout<<p.elementAt(pcursor)<<"\n";
  5785.     }
  5786.     cout<<"\n";
  5787. }
  5788.  
  5789. void update(ParcelService const& p, ParcelService& d) {
  5790.     ParcelService::Cursor pc(p);
  5791.  
  5792.     for (pc.setToFirst(); pc.isValid(); pc.setToNext()) {
  5793.         if (!d.contains(p.elementAt(pc))) {
  5794.             if (p.elementAt(pc).now().getPlace()==p.elementAt(pc).dest().getPlace()) {
  5795.                 d.add(p.elementAt(pc));
  5796.             }
  5797.         }
  5798.     }
  5799. }
  5800.  
  5801.  
  5802. ΓòÉΓòÉΓòÉ 3.19. Relation ΓòÉΓòÉΓòÉ
  5803.  
  5804. A relation is an unordered collection of zero or more elements which have a 
  5805. key. The values of the elements are relevant. 
  5806.  
  5807. The keys of the elements are non unique. That is you can add an element if 
  5808. there is already an element in the relation with the same key. "Figure: 
  5809. Behavior of add for unique and multiple collections" illustrates the different 
  5810. behaviour for map, relation, key set, and key bag when adding identical 
  5811. elements and elements with the same key. 
  5812.  
  5813. "Figure: Combination of collection properties" gives an overview of the 
  5814. properties and the position of a relation in respect to other flat collections. 
  5815.  
  5816.  
  5817. ΓòÉΓòÉΓòÉ 3.19.1. Customizing ΓòÉΓòÉΓòÉ
  5818.  
  5819.      To be completed .......... 
  5820.  
  5821.  
  5822. ΓòÉΓòÉΓòÉ 3.19.2. Declarations ΓòÉΓòÉΓòÉ
  5823.  
  5824. template < class Element, class Key >
  5825. class IRelation {
  5826. public:
  5827.   class Cursor : ICursor {
  5828.     Element& element ();
  5829.     Boolean operator== (Cursor const& cursor);
  5830.     Boolean operator!= (Cursor const& cursor);
  5831.   };
  5832.                   IRelation             (INumber
  5833.                                                numberOfElements = 100,
  5834.                                                IBoundIndicator =
  5835.                                                IUnbounded);
  5836.                   IRelation             (IRelation < Element, Key > const&);
  5837.    IRelation < Element, Key >&    operator =  (IRelation < Element, Key > const&);
  5838.                  ~IRelation             ();
  5839.    Boolean        add                         (Element const&);
  5840.    Boolean        add                         (Element const&,
  5841.                                                ICursor&);
  5842.    void           addAllFrom                  (IRelation < Element, Key > const&);
  5843.    Element const& elementAt                   (ICursor const&) const;
  5844.    Element&       elementAt                   (ICursor const&);
  5845.    Element const& anyElement                  () const;
  5846.    void           removeAt                    (ICursor const&);
  5847.    INumber        removeAll                   (Boolean (*property)
  5848.                                                (Element const&, void*),
  5849.                                                void* additionalArgument = 0);
  5850.    void           replaceAt                   (ICursor const&,
  5851.                                                Element const&);
  5852.    void           removeAll                   ();
  5853.    Boolean        isBounded                   () const;
  5854.    INumber        maxNumberOfElements         () const;
  5855.    INumber        numberOfElements            () const;
  5856.    Boolean        isEmpty                     () const;
  5857.    Boolean        isFull                      () const;
  5858.    ICursor*       newCursor                   () const;
  5859.    Boolean        setToFirst                  (ICursor&) const;
  5860.    Boolean        setToNext                   (ICursor&) const;
  5861.    Boolean        allElementsDo               (Boolean (*function)
  5862.                                                   (Element&, void*),
  5863.                                                void* additionalArgument = 0);
  5864.    Boolean        allElementsDo               (IIterator <Element>&);
  5865.    Boolean        allElementsDo               (Boolean (*function)
  5866.                                                (Element const&, void*),
  5867.                                                void* additionalArgument = 0)
  5868.                                                const;
  5869.    Boolean        allElementsDo               (IConstantIterator
  5870.                                                   <Element>&) const;
  5871.    Boolean        contains                    (Element const&) const;
  5872.    Boolean        containsAllFrom             (IRelation < Element, Key > const&) const;
  5873.    Boolean        locate                      (Element const&, ICursor&)
  5874.                                                const;
  5875.    Boolean        locateOrAdd                 (Element const&);
  5876.    Boolean        locateOrAdd                 (Element const&,
  5877.                                                ICursor&);
  5878.    Boolean        remove                      (Element const&);
  5879.    Boolean        operator ==                 (IRelation < Element, Key > const&) const;
  5880.    Boolean        operator !=                 (IRelation < Element, Key > const&) const;
  5881.    void           unionWith                   (IRelation < Element, Key > const&);
  5882.    void           intersectionWith            (IRelation < Element, Key > const&);
  5883.    void           differenceWith              (IRelation < Element, Key > const&);
  5884.    void           addUnion                    (IRelation < Element, Key > const&,
  5885.                                                IRelation < Element, Key > const&);
  5886.    void           addIntersection             (IRelation < Element, Key > const&,
  5887.                                                IRelation < Element, Key > const&);
  5888.    void           addDifference               (IRelation < Element, Key > const&,
  5889.                                                IRelation < Element, Key > const&);
  5890.    Key const&     key                         (Element const&) const;
  5891.    Boolean        containsElementWithKey      (Key const&) const;
  5892.    Boolean        containsAllKeysFrom         (IRelation < Element, Key > const&) const;
  5893.    Boolean        locateElementWithKey        (Key const&, ICursor&)
  5894.                                                const;
  5895.    Boolean        replaceElementWithKey       (Element const&);
  5896.    Boolean        replaceElementWithKey       (Element const&,
  5897.                                                ICursor&);
  5898.    Boolean        locateOrAddElementWithKey   (Element const&);
  5899.    Boolean        locateOrAddElementWithKey   (Element const&,
  5900.                                                ICursor&);
  5901.    Boolean        addOrReplaceElementWithKey  (Element const&);
  5902.    Boolean        addOrReplaceElementWithKey  (Element const&,
  5903.                                                ICursor&);
  5904.    Boolean        removeElementWithKey        (Key const&);
  5905.    Element const& elementWithKey              (Key const&) const;
  5906.    Element&       elementWithKey              (Key const&);
  5907.    INumber        numberOfElementsWithKey     (Key const&) const;
  5908.    Boolean        locateNextElementWithKey    (Key const&,
  5909.                                                ICursor&) const;
  5910.    INumber        removeAllElementsWithKey    (Key const&);
  5911.    INumber        numberOfDifferentKeys       () const;
  5912.    Boolean        setToNextWithDifferentKey   (ICursor&) const;
  5913. };
  5914.  
  5915.  
  5916. ΓòÉΓòÉΓòÉ 3.20. Sorted Relation ΓòÉΓòÉΓòÉ
  5917.  
  5918. A sorted relation is similar to a relation except that all elements are sorted 
  5919. by the value of the key. 
  5920.  
  5921. "Figure: Combination of collection properties" gives an overview of the 
  5922. properties and the position of a sorted relation in respect to other flat 
  5923. collections. 
  5924.  
  5925.  
  5926. ΓòÉΓòÉΓòÉ 3.20.1. Customizing ΓòÉΓòÉΓòÉ
  5927.  
  5928.      To be completed .......... 
  5929.  
  5930.  
  5931. ΓòÉΓòÉΓòÉ 3.20.2. Declarations ΓòÉΓòÉΓòÉ
  5932.  
  5933. template < class Element, class Key >
  5934. class ISortedRelation {
  5935. public:
  5936.   class Cursor : ICursor {
  5937.     Element& element ();
  5938.     void setToLast ();
  5939.     void setToPrevious ();
  5940.     Boolean operator== (Cursor const& cursor);
  5941.     Boolean operator!= (Cursor const& cursor);
  5942.   };
  5943.                   ISortedRelation             (INumber
  5944.                                                numberOfElements = 100,
  5945.                                                IBoundIndicator =
  5946.                                                IUnbounded);
  5947.                   ISortedRelation             (ISortedRelation < Element, Key > const&);
  5948.    ISortedRelation < Element, Key >&  operator = (ISortedRelation < Element, Key > const&);
  5949.                  ~ISortedRelation             ();
  5950.    Boolean        add                         (Element const&);
  5951.    Boolean        add                         (Element const&,
  5952.                                                ICursor&);
  5953.    void           addAllFrom                  (ISortedRelation < Element, Key > const&);
  5954.    Element const& elementAt                   (ICursor const&) const;
  5955.    Element&       elementAt                   (ICursor const&);
  5956.    Element const& anyElement                  () const;
  5957.    void           removeAt                    (ICursor const&);
  5958.    INumber        removeAll                   (Boolean (*property)
  5959.                                                (Element const&, void*),
  5960.                                                void* additionalArgument = 0);
  5961.    void           replaceAt                   (ICursor const&,
  5962.                                                Element const&);
  5963.    void           removeAll                   ();
  5964.    Boolean        isBounded                   () const;
  5965.    INumber        maxNumberOfElements         () const;
  5966.    INumber        numberOfElements            () const;
  5967.    Boolean        isEmpty                     () const;
  5968.    Boolean        isFull                      () const;
  5969.    ICursor*       newCursor                   () const;
  5970.    Boolean        setToFirst                  (ICursor&) const;
  5971.    Boolean        setToNext                   (ICursor&) const;
  5972.    Boolean        allElementsDo               (Boolean (*function)
  5973.                                                   (Element&, void*),
  5974.                                                void* additionalArgument = 0);
  5975.    Boolean        allElementsDo               (IIterator <Element>&);
  5976.    Boolean        allElementsDo               (Boolean (*function)
  5977.                                                (Element const&, void*),
  5978.                                                void* additionalArgument = 0)
  5979.                                                const;
  5980.    Boolean        allElementsDo               (IConstantIterator
  5981.                                                   <Element>&) const;
  5982.    Boolean        contains                    (Element const&) const;
  5983.    Boolean        containsAllFrom             (ISortedRelation < Element, Key > const&) const;
  5984.    Boolean        locate                      (Element const&, ICursor&)
  5985.                                                const;
  5986.    Boolean        locateOrAdd                 (Element const&);
  5987.    Boolean        locateOrAdd                 (Element const&,
  5988.                                                ICursor&);
  5989.    Boolean        remove                      (Element const&);
  5990.    Boolean        operator ==                 (ISortedRelation < Element, Key > const&) const;
  5991.    Boolean        operator !=                 (ISortedRelation < Element, Key > const&) const;
  5992.    void           unionWith                   (ISortedRelation < Element, Key > const&);
  5993.    void           intersectionWith            (ISortedRelation < Element, Key > const&);
  5994.    void           differenceWith              (ISortedRelation < Element, Key > const&);
  5995.    void           addUnion                    (ISortedRelation < Element, Key > const&,
  5996.                                                ISortedRelation < Element, Key > const&);
  5997.    void           addIntersection             (ISortedRelation < Element, Key > const&,
  5998.                                                ISortedRelation < Element, Key > const&);
  5999.    void           addDifference               (ISortedRelation < Element, Key > const&,
  6000.                                                ISortedRelation < Element, Key > const&);
  6001.    Key const&     key                         (Element const&) const;
  6002.    Boolean        containsElementWithKey      (Key const&) const;
  6003.    Boolean        containsAllKeysFrom         (ISortedRelation < Element, Key > const&) const;
  6004.    Boolean        locateElementWithKey        (Key const&, ICursor&)
  6005.                                                const;
  6006.    Boolean        replaceElementWithKey       (Element const&);
  6007.    Boolean        replaceElementWithKey       (Element const&,
  6008.                                                ICursor&);
  6009.    Boolean        locateOrAddElementWithKey   (Element const&);
  6010.    Boolean        locateOrAddElementWithKey   (Element const&,
  6011.                                                ICursor&);
  6012.    Boolean        addOrReplaceElementWithKey  (Element const&);
  6013.    Boolean        addOrReplaceElementWithKey  (Element const&,
  6014.                                                ICursor&);
  6015.    Boolean        removeElementWithKey        (Key const&);
  6016.    Element const& elementWithKey              (Key const&) const;
  6017.    Element&       elementWithKey              (Key const&);
  6018.    INumber        numberOfElementsWithKey     (Key const&) const;
  6019.    Boolean        locateNextElementWithKey    (Key const&,
  6020.                                                ICursor&) const;
  6021.    INumber        removeAllElementsWithKey    (Key const&);
  6022.    INumber        numberOfDifferentKeys       () const;
  6023.    Boolean        setToNextWithDifferentKey   (ICursor&) const;
  6024.    void           removeFirst                 ();
  6025.    void           removeLast                  ();
  6026.    void           removeAtPosition            (IPosition);
  6027.    Element const& firstElement                () const;
  6028.    Element const& lastElement                 () const;
  6029.    Element const& elementAtPosition           (IPosition) const;
  6030.    Boolean        setToLast                   (ICursor&) const;
  6031.    Boolean        setToPrevious               (ICursor&) const;
  6032.    void           setToPosition               (IPosition,
  6033.                                                ICursor&) const;
  6034.    Boolean        isFirst                     (ICursor const&) const;
  6035.    Boolean        isLast                      (ICursor const&) const;
  6036.    long           compare                     (ISortedRelation < Element, Key > const&,
  6037.                                                long (*comparisonFunction)
  6038.                                                   (Element const&,
  6039.                                                   Element const&)) const;
  6040. };
  6041.  
  6042.  
  6043. ΓòÉΓòÉΓòÉ 4. subj='Tree Classes'.Reference Manual - Tree Classes ΓòÉΓòÉΓòÉ
  6044.  
  6045. The following chapters describe the tree classes of the library. 
  6046.  
  6047. As for flat collections you will find all function described in a separate 
  6048. chapter (List of Functions) separeted from the decsriptions for the tree 
  6049. classes. 
  6050.  
  6051.  
  6052. ΓòÉΓòÉΓòÉ 4.1. List of Functions ΓòÉΓòÉΓòÉ
  6053.  
  6054.  
  6055. ΓòÉΓòÉΓòÉ 4.1.1. addAsChild ΓòÉΓòÉΓòÉ
  6056.  
  6057.  void addAsChild (ITreeCursor const&
  6058.                       IPosition,
  6059.                       Element const&) = 0;
  6060.  
  6061. Add the given element as child with the given position of the node (of this 
  6062. tree) denoted by the given cursor. 
  6063. Precondition: 
  6064.  
  6065. o The cursor must belong to the collection and the cursor must point to an 
  6066.   element of the collection.. 
  6067. o 1 <= position <= children. 
  6068. o The node denoted by the given cursor (of this tree) must not have a child at 
  6069.   the given position. 
  6070.  
  6071. Exceptions: 
  6072.  
  6073. o IMemoryExhaustedException 
  6074. o ICursorInvalidException 
  6075. o IPositionInvalidException 
  6076. o IChildAlreadyExistsException 
  6077.  
  6078.  
  6079. ΓòÉΓòÉΓòÉ 4.1.2. addAsRoot ΓòÉΓòÉΓòÉ
  6080.  
  6081.  void addAsRoot (Element const&) = 0;
  6082.  
  6083. Add the given element as root of the tree. 
  6084. Precondition: The tree must not have a root, that means it must be empty. 
  6085. Exceptions: 
  6086.  
  6087. o IMemoryExhaustedException 
  6088. o IRootAlreadyExistsException 
  6089.  
  6090.  
  6091. ΓòÉΓòÉΓòÉ 4.1.3. allElementsDo, allSubtreeElementsDo ΓòÉΓòÉΓòÉ
  6092.  
  6093.  Boolean allElementsDo (IConstantIterator <Element>&,
  6094.                      ITreeIterationOrder) const = 0; 
  6095.  
  6096.  Boolean allSubtreeElementsDo (ITreeCursor const&,
  6097.                      IConstantIterator <Element>&,                      ITreeIterationOrder) const = 0; 
  6098.  
  6099. Call the applyTo function of the given iterator for all elements of the subtree 
  6100. denoted by the given cursor (of this tree) until the applyTo function returns 
  6101. false. The elements are visited in the given iteration order. The allElementsDo 
  6102. function (without a subtree cursor argument) iterates over all elements of the 
  6103. tree. 
  6104. Note: The applyTo function must not remove or add elements of the tree. 
  6105. ReturnValue: True if the applyTo function returns true for every element it is 
  6106. applied to. 
  6107.  
  6108.  
  6109. ΓòÉΓòÉΓòÉ 4.1.4. allElementsDo, allSubtreeElementsDo ΓòÉΓòÉΓòÉ
  6110.  
  6111.  Boolean allElementsDo (Boolean (*function)
  6112.                          (Element const&, void*),                      ITreeIterationOrder, void* 
  6113. additionalArgument = 0)                          const = 0; 
  6114.  
  6115.  Boolean allSubtreeElementsDo (ITreeCursor const&,
  6116.                      Boolean (*function)                          (Element const&, void*),                      
  6117. ITreeIterationOrder, void* additionalArgument = 0)                          const = 0; 
  6118.  
  6119. Call the given function for all elements of the subtree denoted by the given 
  6120. cursor (of this tree) until the given function returns false. The elements are 
  6121. visited in the given iteration order. Additional arguments can be passed to the 
  6122. given function using additionalArgument. The allElementsDo function (without a 
  6123. subtree cursor argument) iterates over all elements of the tree. 
  6124. Note: The given function may not remove or add elements to the tree. 
  6125. ReturnValue: True if the given function returns true for every element it is 
  6126. applied to. 
  6127.  
  6128.  
  6129. ΓòÉΓòÉΓòÉ 4.1.5. allElementsDo, allSubtreeElementsDo ΓòÉΓòÉΓòÉ
  6130.  
  6131.  Boolean allElementsDo (IIterator <Element>&,
  6132.                      ITreeIterationOrder) = 0; 
  6133.  
  6134.  Boolean allSubtreeElementsDo (ITreeCursor const&,
  6135.                      IIterator <Element>&,                      ITreeIterationOrder) = 0; 
  6136.  
  6137. Call the applyTo function of the given iterator for all elements of the subtree 
  6138. denoted by the given cursor (of this tree) until the applyTo function returns 
  6139. false. The elements are visited in the given iteration order. The allElementsDo 
  6140. function (without a subtree cursor argument) iterates over all elements of the 
  6141. tree. 
  6142. Additional arguments can be passed to the applyTo function using the 
  6143. additionalArgument. 
  6144. Note: The applyTo function may not remove or add elements from or to the tree. 
  6145. ReturnValue: True if the applyTo function returns true for every element it is 
  6146. applied to. 
  6147.  
  6148.  
  6149. ΓòÉΓòÉΓòÉ 4.1.6. allElementsDo, allSubtreeElementsDo ΓòÉΓòÉΓòÉ
  6150.  
  6151.  Boolean allElementsDo (Boolean (*function)
  6152. (Element&, void*),                      ITreeIterationOrder, void* additionalArgument = 0) = 
  6153. 0; 
  6154.  
  6155.  Boolean allSubtreeElementsDo (ITreeCursor const&,
  6156.                      Boolean (*function) (Element&, void*),                      ITreeIterationOrder, void* 
  6157. additionalArgument = 0) = 0; 
  6158.  
  6159. Call the given function for all elements of the subtree denoted by the given 
  6160. cursor (of this tree) until the given function returns false. The elements are 
  6161. visited in the given iteration order. Additional arguments can be passed to the 
  6162. given function using the additionalArgument. The allElementsDo function 
  6163. (without a subtree cursor argument) iterates over all elements of the tree. 
  6164. Note: The given function may not remove or add elements from or to the tree. 
  6165. ReturnValue: True if the given function returns true for every element it is 
  6166. applied to. 
  6167.  
  6168.  
  6169. ΓòÉΓòÉΓòÉ 4.1.7. attachAsChild, attachSubtreeAsChild ΓòÉΓòÉΓòÉ
  6170.  
  6171.  void attachAsChild (ITreeCursor const&,
  6172.                      IPosition,                      ITree < Element,                          children >&) = 0; 
  6173.  
  6174.  void attachSubtreeAsChild (ITreeCursor const&,
  6175.                      IPosition,                      ITree < Element,                          children >&                      ITreeCursor 
  6176. const& subtree) = 0; 
  6177.  
  6178. Copy the subtree denoted by the given subtree cursor of the given tree as child 
  6179. with the given position of the node (of this tree) denoted by the given cursor 
  6180. and remove this subtree from the given tree. The attachAsChild function 
  6181. (without a subtree cursor argument) copies and removes the whole given tree. 
  6182. Precondition: 
  6183.  
  6184. o The cursor must belong to the collection and the cursor must point to an 
  6185.   element of the collection.. 
  6186. o The subtree cursor must point to an element of the given tree. 
  6187. o 1 <= position <= children. 
  6188. o The node denoted by the given cursor (of this tree) must not have a child at 
  6189.   the given position. 
  6190.  
  6191. Exceptions: 
  6192.  
  6193. o IMemoryExhaustedException 
  6194. o ICursorInvalidException 
  6195. o IPositionInvalidException 
  6196. o IChildAlreadyExistsException 
  6197.  
  6198.  
  6199. ΓòÉΓòÉΓòÉ 4.1.8. attachAsRoot, attachSubtreeAsRoot ΓòÉΓòÉΓòÉ
  6200.  
  6201.  void attachAsRoot (ITree < Element,
  6202.                          children >&) = 0; 
  6203.  
  6204.  void attachSubtreeAsRoot (ITree < Element,
  6205.                          children >&                      ITreeCursor const&) = 0; 
  6206.  
  6207. Copy the subtree denoted by the given cursor of the given tree to (the root of) 
  6208. this tree and remove this subtree from the given tree. The attachAsRoot 
  6209. function (without a cursor argument) copies and removes the whole given tree. 
  6210. Precondition: 
  6211.  
  6212. o The cursor must belong to the collection and the cursor must point to an 
  6213.   element of the collection.. 
  6214. o The tree must not have a root, that means it must be empty. 
  6215.  
  6216. Exceptions: 
  6217.  
  6218. o IMemoryExhaustedException 
  6219. o ICursorInvalidException 
  6220. o IRootAlreadyExistsException 
  6221.  
  6222.  
  6223. ΓòÉΓòÉΓòÉ 4.1.9. Constructor ΓòÉΓòÉΓòÉ
  6224.  
  6225.  ITree ();
  6226.  
  6227. Construct a tree. The tree is initially empty, that means it contains no node. 
  6228.  
  6229.  
  6230. ΓòÉΓòÉΓòÉ 4.1.10. Copy Constructor ΓòÉΓòÉΓòÉ
  6231.  
  6232.  ITree (ITree < Element, children > const&);
  6233.  
  6234. Construct a tree by copying all elements from the given tree. 
  6235. Exceptions: IMemoryExhaustedException 
  6236.  
  6237.  
  6238. ΓòÉΓòÉΓòÉ 4.1.11. copy, copySubtree ΓòÉΓòÉΓòÉ
  6239.  
  6240.  void copy (ITree < Element,
  6241.                          children > const&) = 0; 
  6242.  
  6243.  void copySubtree (ITree < Element,
  6244.                          children > const&                      ITreeCursor const&) = 0; 
  6245.  
  6246. Remove all elements from this tree and copy the subtree denoted by the given 
  6247. cursor of the given tree to (the root of) this tree. The copy function (without 
  6248. a cursor argument) copies the whole given tree. 
  6249. Precondition: The cursor must point to an element of the given tree. 
  6250. Exceptions: IMemoryExhaustedException 
  6251.  
  6252.  
  6253. ΓòÉΓòÉΓòÉ 4.1.12. Destructor ΓòÉΓòÉΓòÉ
  6254.  
  6255.  ~ITree ();
  6256.  
  6257. Remove all elements from this tree. 
  6258. Side Effect: All cursors of the tree become undefined. 
  6259.  
  6260.  
  6261. ΓòÉΓòÉΓòÉ 4.1.13. elementAt ΓòÉΓòÉΓòÉ
  6262.  
  6263.  Element& elementAt (ITreeCursor const&) = 0;
  6264.  
  6265. Returns (a reference to) the element pointed to by the given cursor. 
  6266. Precondition: The cursor must belong to the collection and the cursor must 
  6267. point to an element of the collection.. 
  6268. Exceptions: ICursorInvalidException 
  6269.  
  6270.  
  6271. ΓòÉΓòÉΓòÉ 4.1.14. elementAt ΓòÉΓòÉΓòÉ
  6272.  
  6273.  Element const& elementAt (ITreeCursor const&) const = 0;
  6274.  
  6275. Returns (a constant reference to) the element pointed to by the given cursor. 
  6276. Precondition: The cursor must belong to the collection and the cursor must 
  6277. point to an element of the collection.. 
  6278. Exceptions: ICursorInvalidException 
  6279.  
  6280.  
  6281. ΓòÉΓòÉΓòÉ 4.1.15. hasChild ΓòÉΓòÉΓòÉ
  6282.  
  6283.  Boolean hasChild (IPosition,
  6284.                      ITreeCursor const&) const = 0; 
  6285.  
  6286. Return true if the node pointed to by the given cursor has a child child at the 
  6287. given position. 
  6288. Precondition: 
  6289.  
  6290. o The cursor must belong to the collection and the cursor must point to an 
  6291.   element of the collection.. 
  6292. o 1 <= position <= children. 
  6293.  
  6294. Exceptions: 
  6295.  
  6296. o ICursorInvalidException 
  6297. o IPositionInvalidException 
  6298.  
  6299.  
  6300. ΓòÉΓòÉΓòÉ 4.1.16. isEmpty ΓòÉΓòÉΓòÉ
  6301.  
  6302.  Boolean isEmpty () const = 0;
  6303.  
  6304. Return true if the tree is empty. 
  6305.  
  6306.  
  6307. ΓòÉΓòÉΓòÉ 4.1.17. isLeaf ΓòÉΓòÉΓòÉ
  6308.  
  6309.  Boolean isLeaf (ITreeCursor const&) const = 0;
  6310.  
  6311. Return true if the node pointed to by the given cursor is a leaf node of the 
  6312. tree, that means it has no children. 
  6313. Precondition: The cursor must belong to the collection and the cursor must 
  6314. point to an element of the collection.. 
  6315. Exceptions: ICursorInvalidException 
  6316.  
  6317.  
  6318. ΓòÉΓòÉΓòÉ 4.1.18. isRoot ΓòÉΓòÉΓòÉ
  6319.  
  6320.  Boolean isRoot (ITreeCursor const&) const = 0;
  6321.  
  6322. Return true if the node pointed to by the given cursor is the root node of the 
  6323. tree. 
  6324. Precondition: The cursor must belong to the collection and the cursor must 
  6325. point to an element of the collection.. 
  6326. Exceptions: ICursorInvalidException 
  6327.  
  6328.  
  6329. ΓòÉΓòÉΓòÉ 4.1.19. newCursor ΓòÉΓòÉΓòÉ
  6330.  
  6331.  ITreeCursor* newCursor () const = 0;
  6332.  
  6333. Create a cursor for the tree. The cursor is initially invalid. 
  6334. ReturnValue: Pointer to the cursor. 
  6335. Exceptions: IMemoryExhaustedException 
  6336.  
  6337.  
  6338. ΓòÉΓòÉΓòÉ 4.1.20. numberOfChildren ΓòÉΓòÉΓòÉ
  6339.  
  6340.  INumber numberOfChildren () const = 0;
  6341.  
  6342. Return the number of children a node can possibly have. The actual number of 
  6343. children of any node will always be less or equal to this number. 
  6344.  
  6345.  
  6346. ΓòÉΓòÉΓòÉ 4.1.21. numberOfElements, numberOfSubtreeElements ΓòÉΓòÉΓòÉ
  6347.  
  6348.  INumber numberOfElements () const = 0;
  6349.  INumber numberOfSubtreeElements (ITreeCursor const&) const = 0;
  6350.  
  6351. Return the number of elements which the subtree denoted by the given cursor 
  6352. contains. The subtree root and inner as well as leaf nodes are counted. The 
  6353. numberOfElements function (without a cursor argument) counts the number of 
  6354. elements in the whole tree. 
  6355.  
  6356.  
  6357. ΓòÉΓòÉΓòÉ 4.1.22. numberOfLeaves, numberOfSubtreeLeaves ΓòÉΓòÉΓòÉ
  6358.  
  6359.  INumber numberOfLeaves () const = 0;
  6360.  INumber numberOfSubtreeLeaves (ITreeCursor const&) const = 0;
  6361.  
  6362. Return the number of leaf elements which the subtree denoted by the given 
  6363. cursor contains. Leaves are nodes that have no children. The numberOfLeaves 
  6364. function (without a cursor argument) counts the number of leaves in the whole 
  6365. tree. 
  6366.  
  6367.  
  6368. ΓòÉΓòÉΓòÉ 4.1.23. operator = ΓòÉΓòÉΓòÉ
  6369.  
  6370.  ITree < Element, children >&
  6371. operator = (ITree < Element,                          children > const&); 
  6372.  
  6373. Remove all elements from this tree and copy the given tree to (the root of) 
  6374. this tree. 
  6375. ReturnValue: (A reference to) this tree. 
  6376. Side Effect: All cursors of this tree become undefined. 
  6377. Precondition: none. 
  6378. Exceptions: IMemoryExhaustedException 
  6379.  
  6380.  
  6381. ΓòÉΓòÉΓòÉ 4.1.24. position ΓòÉΓòÉΓòÉ
  6382.  
  6383.  INumber position (ITreeCursor const&) const = 0;
  6384.  
  6385. Return the position of the node pointed to by the given cursor as child with 
  6386. respect to its parent node. The position of the root node is 1. 
  6387. Precondition: The cursor must belong to the collection and the cursor must 
  6388. point to an element of the collection.. 
  6389. Exceptions: ICursorInvalidException 
  6390.  
  6391.  
  6392. ΓòÉΓòÉΓòÉ 4.1.25. removeAll, removeSubtree ΓòÉΓòÉΓòÉ
  6393.  
  6394.  void removeAll () = 0;
  6395.  void removeSubtree (ITreeCursor const&) = 0;
  6396.  
  6397. Remove the subtree denoted by the given cursor (of this tree). The removeAll 
  6398. function (without a cursor argument) removes all elements from this tree. 
  6399. Precondition: The cursor must belong to the collection and the cursor must 
  6400. point to an element of the collection.. 
  6401. Exceptions: ICursorInvalidException 
  6402.  
  6403.  
  6404. ΓòÉΓòÉΓòÉ 4.1.26. replaceAt ΓòÉΓòÉΓòÉ
  6405.  
  6406.  void replaceAt (ITreeCursor const&,
  6407. Element const&) = 0; 
  6408.  
  6409. Replaces the element pointed to by the cursor with the given element. 
  6410. Precondition: The cursor must belong to the collection and the cursor must 
  6411. point to an element of the collection.. 
  6412. Exceptions: ICursorInvalidException 
  6413.  
  6414.  
  6415. ΓòÉΓòÉΓòÉ 4.1.27. setToChild ΓòÉΓòÉΓòÉ
  6416.  
  6417.  Boolean setToChild (IPosition,
  6418.                      ITreeCursor&) const = 0; 
  6419.  
  6420. Set the cursor to the child with the given position of the node denoted by the 
  6421. given cursor (of this tree). If this child does not exist, the given cursor 
  6422. will become invalid. 
  6423. ReturnValue: True if the child exists. 
  6424. Precondition: 
  6425.  
  6426. o The cursor must belong to the collection and the cursor must point to an 
  6427.   element of the collection.. 
  6428. o 1 <= position <= children. 
  6429.  
  6430. Exceptions: 
  6431.  
  6432. o ICursorInvalidException 
  6433. o IPositionInvalidException 
  6434.  
  6435.  
  6436. ΓòÉΓòÉΓòÉ 4.1.28. setToFirst ΓòÉΓòÉΓòÉ
  6437.  
  6438.  Boolean setToFirst (ITreeCursor&,
  6439.                      ITreeIterationOrder) const = 0; 
  6440.  
  6441. Set the cursor to the first node in the given iteration order. If the tree is 
  6442. empty, the given cursor will become invalid. 
  6443. ReturnValue: True if the tree is not empty. 
  6444. Precondition: The cursor must belong to this tree. 
  6445. Exceptions: ICursorInvalidException 
  6446.  
  6447.  
  6448. ΓòÉΓòÉΓòÉ 4.1.29. setToFirstExistingChild ΓòÉΓòÉΓòÉ
  6449.  
  6450.  Boolean setToFirstExistingChild (ITreeCursor&) const = 0;
  6451.  
  6452. Set the cursor to the first child of the node denoted by the given cursor (of 
  6453. this tree). If the node has no child (that means the node denotes a leaf node 
  6454. of this tree), the given cursor will become invalid. 
  6455. ReturnValue: True if the node has a child. 
  6456. Precondition: The cursor must belong to the collection and the cursor must 
  6457. point to an element of the collection.. 
  6458. Exceptions: ICursorInvalidException 
  6459.  
  6460.  
  6461. ΓòÉΓòÉΓòÉ 4.1.30. setToLast ΓòÉΓòÉΓòÉ
  6462.  
  6463.  Boolean setToLast (ITreeCursor&,
  6464.                      ITreeIterationOrder) const = 0; 
  6465.  
  6466. Set the cursor to the last node in the given iteration order. If the tree is 
  6467. empty, the given cursor will become invalid. 
  6468. ReturnValue: True if the tree is not empty. 
  6469. Precondition: The cursor must belong to this tree. 
  6470. Exceptions: ICursorInvalidException 
  6471.  
  6472.  
  6473. ΓòÉΓòÉΓòÉ 4.1.31. setToLastExistingChild ΓòÉΓòÉΓòÉ
  6474.  
  6475.  Boolean setToLastExistingChild (ITreeCursor&) const = 0;
  6476.  
  6477. Set the cursor to the last child of the node denoted by the given cursor (of 
  6478. this tree). If the node has no child (that means the node denotes a leaf node 
  6479. of this tree), the given cursor will become invalid. 
  6480. ReturnValue: True if the node has a child. 
  6481. Precondition: The cursor must belong to the collection and the cursor must 
  6482. point to an element of the collection.. 
  6483. Exceptions: ICursorInvalidException 
  6484.  
  6485.  
  6486. ΓòÉΓòÉΓòÉ 4.1.32. setToNext ΓòÉΓòÉΓòÉ
  6487.  
  6488.  Boolean setToNext (ITreeCursor&,
  6489.                      ITreeIterationOrder) const = 0; 
  6490.  
  6491. Set the cursor to the next node in the given iteration order. If there is no 
  6492. next node, the given cursor will become invalid. 
  6493. ReturnValue: True if the given cursor does not point to the last node (in 
  6494. iteration order). 
  6495. Precondition: The cursor must belong to the collection and the cursor must 
  6496. point to an element of the collection.. 
  6497. Exceptions: ICursorInvalidException 
  6498.  
  6499.  
  6500. ΓòÉΓòÉΓòÉ 4.1.33. setToNextExistingChild ΓòÉΓòÉΓòÉ
  6501.  
  6502.  Boolean setToNextExistingChild (ITreeCursor&) const = 0;
  6503.  
  6504. Set the cursor to the next existing sibling of the node denoted by the given 
  6505. cursor (of this tree). If the node has no next sibling (that means the node is 
  6506. the last existing child of its parent), the given cursor will become invalid. 
  6507. ReturnValue: True if the node has a next sibling. 
  6508. Precondition: The cursor must belong to the collection and the cursor must 
  6509. point to an element of the collection.. 
  6510. Exceptions: ICursorInvalidException 
  6511.  
  6512.  
  6513. ΓòÉΓòÉΓòÉ 4.1.34. setToParent ΓòÉΓòÉΓòÉ
  6514.  
  6515.  Boolean setToParent (ITreeCursor&) const = 0;
  6516.  
  6517. Set the cursor to the parent of the node denoted by the given cursor (of this 
  6518. tree). If the node has no parent (that means the node denotes the root node of 
  6519. this tree), the given cursor will become invalid. 
  6520. ReturnValue: True if the node has a parent. 
  6521. Precondition: The cursor must belong to the collection and the cursor must 
  6522. point to an element of the collection.. 
  6523. Exceptions: ICursorInvalidException 
  6524.  
  6525.  
  6526. ΓòÉΓòÉΓòÉ 4.1.35. setToPrevious ΓòÉΓòÉΓòÉ
  6527.  
  6528.  Boolean setToPrevious (ITreeCursor&,
  6529.                      ITreeIterationOrder) const = 0; 
  6530.  
  6531. Set the cursor to the previous node in the given iteration order. If there is 
  6532. no previous node, the given cursor will become invalid. 
  6533. ReturnValue: True if the given cursor does not point to the first node (in 
  6534. iteration order). 
  6535. Precondition: The cursor must belong to the collection and the cursor must 
  6536. point to an element of the collection.. 
  6537. Exceptions: ICursorInvalidException 
  6538.  
  6539.  
  6540. ΓòÉΓòÉΓòÉ 4.1.36. setToPreviousExistingChild ΓòÉΓòÉΓòÉ
  6541.  
  6542.  Boolean setToPreviousExistingChild (ITreeCursor&) const = 0;
  6543.  
  6544. Set the cursor to the previous existing sibling of the node denoted by the 
  6545. given cursor (of this tree). If the node has no previous sibling (that means 
  6546. the node is the first existing child of its parent), the given cursor will 
  6547. become invalid. 
  6548. ReturnValue: True if the node has a previous sibling. 
  6549. Precondition: The cursor must belong to the collection and the cursor must 
  6550. point to an element of the collection.. 
  6551. Exceptions: ICursorInvalidException 
  6552.  
  6553.  
  6554. ΓòÉΓòÉΓòÉ 4.1.37. setToRoot ΓòÉΓòÉΓòÉ
  6555.  
  6556.  Boolean setToRoot (ITreeCursor&) const = 0;
  6557.  
  6558. Set the cursor to the root node of the tree. If the tree is empty (i.e. if no 
  6559. root node exists) the given cursor will become invalid. 
  6560. ReturnValue: True if the tree is not empty. 
  6561. Precondition: The cursor must belong to this tree. 
  6562. Exceptions: ICursorInvalidException 
  6563.  
  6564.  
  6565. ΓòÉΓòÉΓòÉ 4.2. N-ary Tree ΓòÉΓòÉΓòÉ
  6566.  
  6567. An n-ary tree is a special tree where each node can have up to n children. 
  6568.  
  6569. A tree is a collection of  nodes that can have an arbitrary number of 
  6570. references to other nodes.  There can be no cycles or short-circuit references. 
  6571. For every two nodes there exists a unique path connecting them.  One node is 
  6572. designated as the root of the tree. 
  6573.  
  6574. Formally, a tree can be defined recursively in the following manner: 
  6575.  
  6576.  1. A single node by itself is a tree.  This node is also the root of the tree. 
  6577.  
  6578.  2. Suppose N is a node and T-1, T-2, R-2, ..., R-k, respectively.  We can 
  6579.     construct a new tree by making N the parent of the nodes R-1, R-2, ..., 
  6580.     R-k. In this new tree, N is the root and T-1, T-2, ..., T-k are the 
  6581.     subtrees of the root N.  Nodes R-1, R-2, N. 
  6582.  
  6583. Associated with each node is a data item called element. 
  6584.  
  6585. Nodes without children are called leaves or terminals.  The number of children 
  6586. of a node is called the degree of that node.  The level of a given node is the 
  6587. number of steps in the path from the root to the given node. The root is at 
  6588. level 0 by definition.  The height of a tree is the length of the longest path 
  6589. from the root to any node. 
  6590.  
  6591. Each node of an n-ary tree can have up to "n" children. 
  6592.  
  6593. For most trees used in practice, the children of a node are ordered from 
  6594. "left-to-right".  If two siblings in such a tree exchange their place, the tree 
  6595. as it was before is different from the tree as it is after the exchange, 
  6596. because the children of that node appear in a different order. 
  6597.  
  6598.  
  6599. ΓòÉΓòÉΓòÉ 4.2.1. Customizing ΓòÉΓòÉΓòÉ
  6600.  
  6601. This section describes the implementation variants supported by the N-ary Tree 
  6602. Class and the generic parameters available for selecting these variants. 
  6603.  
  6604.  
  6605. ΓòÉΓòÉΓòÉ 4.2.1.1. Implementation Variants ΓòÉΓòÉΓòÉ
  6606.  
  6607. The N-ary Tree Class implements a linked and unbounded data structure  (also 
  6608. known as Arbitrary Tree) or a tabular and bounded data structure. No other 
  6609. implementation variants can be selected. 
  6610.  
  6611.  
  6612. ΓòÉΓòÉΓòÉ 4.2.2. Usage Notes ΓòÉΓòÉΓòÉ
  6613.  
  6614. The use of the N-ary Tree Class is illustrated in a -- Link Reference NarytrX 
  6615. not found -- reftype=hd.coding example provided with the IBM Class Library: 
  6616. Collection Classes. 
  6617.  
  6618.  
  6619. ΓòÉΓòÉΓòÉ 4.2.3. Declarations ΓòÉΓòÉΓòÉ
  6620.  
  6621.  
  6622.  
  6623.  
  6624. to be completed ......
  6625.  
  6626.  
  6627.  
  6628. ΓòÉΓòÉΓòÉ 4.3. Binary Tree ΓòÉΓòÉΓòÉ
  6629.  
  6630. A binary tree is a special tree where each node can have at most two children. 
  6631.  
  6632. A tree is a collection of  nodes that can have an arbitrary number of 
  6633. references to other nodes.  There can be no cycles or short-circuit references. 
  6634. For every two nodes there exists a unique path connecting them.  One node is 
  6635. designated as the root of the tree. 
  6636.  
  6637. Formally, a tree can be defined recursively in the following manner: 
  6638.  
  6639.  1. A single node by itself is a tree.  This node is also the root of the tree. 
  6640.  
  6641.  2. Suppose N is a node and T-1, T-2 are trees with roots R-1, R-2, 
  6642.     respectively.  We can construct a new tree by making N the parent of the 
  6643.     nodes R-1, R-2.  In this new tree, N is the root and T-1, T-2 are the 
  6644.     subtrees of the root N.  Nodes R-1, R-2 are called children of node N. 
  6645.  
  6646. Associated with each node is a data item called element. 
  6647.  
  6648. Nodes without children are called leaves or terminals.  The number of children 
  6649. of a node is called the degree of that node.  The level of a given node is the 
  6650. number of steps in the path from the root to the given node. The root is at 
  6651. level 0 by definition.  The height of a tree is the length of the longest path 
  6652. from the root to any node. 
  6653.  
  6654. Each node of a binary tree can have at most "two" children. 
  6655.  
  6656. For most trees used in practice, the children of a node are ordered from 
  6657. "left-to-right". The children of a node are called the left and the right 
  6658. child.  If the left and the right child exchange their place, the tree after 
  6659. the exchange is different from the tree as it was before, because the children 
  6660. of that node appear in a different order. 
  6661.  
  6662.  
  6663. ΓòÉΓòÉΓòÉ 4.3.1. Customizing ΓòÉΓòÉΓòÉ
  6664.  
  6665. This section describes the implementation variants supported by the Binary Tree 
  6666. Class and the generic parameters available for selecting these variants. 
  6667.  
  6668.  
  6669. ΓòÉΓòÉΓòÉ 4.3.1.1. Implementation Variants ΓòÉΓòÉΓòÉ
  6670.  
  6671. The Binary Tree Class always implements a linked and unbounded data structure. 
  6672. No other implementation variants can be selected. 
  6673.  
  6674. Time complexity for element lookup is O( N ), where N is the total number of 
  6675. elements in the tree. 
  6676.  
  6677.  
  6678. ΓòÉΓòÉΓòÉ 4.3.2. Usage Notes ΓòÉΓòÉΓòÉ
  6679.  
  6680. The use of the Binary Tree Class is illustrated in a -- Link Reference BintreX 
  6681. not found -- reftype=hd.coding example provided with the IBM Class Library: 
  6682. Collection Classes. 
  6683.  
  6684.  
  6685. ΓòÉΓòÉΓòÉ 4.3.3. Declarations ΓòÉΓòÉΓòÉ
  6686.  
  6687.  
  6688.  
  6689.  
  6690. to be completed ......
  6691.  
  6692.  
  6693.  
  6694. ΓòÉΓòÉΓòÉ 5. subj='Auxiliary Classes'.Reference Manual - Auxiliary Classes ΓòÉΓòÉΓòÉ
  6695.  
  6696. The following chapters describe the auxiliary classes of the library. 
  6697.  
  6698.  
  6699. ΓòÉΓòÉΓòÉ 5.1. Cursor ΓòÉΓòÉΓòÉ
  6700.  
  6701. The cursor class is the base class for the cursor classes in each collection. 
  6702.  
  6703. Cursors explains the concepts and usage of cursors. 
  6704.  
  6705.  
  6706. ΓòÉΓòÉΓòÉ 5.1.1. Declarations ΓòÉΓòÉΓòÉ
  6707.  
  6708. class ICursor {
  6709. public:
  6710.   virtual        Boolean setToFirst () = 0;
  6711.   virtual        Boolean setToNext  () = 0;
  6712.   virtual        Boolean isValid    () const = 0;
  6713.   virtual        void    invalidate () = 0;
  6714. };
  6715.  
  6716.  
  6717. ΓòÉΓòÉΓòÉ 5.2. Iterator Class ΓòÉΓòÉΓòÉ
  6718.  
  6719. The &iter. provides one possibility to iterate over all elements in a 
  6720. collection. 
  6721.  
  6722. Using Iterators explains the concepts and usage of iterations. 
  6723.  
  6724.  
  6725. ΓòÉΓòÉΓòÉ 5.2.1. Declarations ΓòÉΓòÉΓòÉ
  6726.  
  6727. template < class Element >
  6728. class IIterator {
  6729. public:
  6730.   virtual Boolean applyTo (Element&) = 0;
  6731. };
  6732. template < class Element >
  6733. class IConstantIterator {
  6734. public:
  6735.   virtual Boolean applyTo (Element const&) = 0;
  6736. };
  6737.  
  6738.  
  6739. ΓòÉΓòÉΓòÉ 5.3. Reference Class ΓòÉΓòÉΓòÉ
  6740.  
  6741. The reference class provides the means to manage objects and garbage 
  6742. collection. 
  6743.  
  6744. Values vs. (Managed) Objects and hdref refid=garb. explain the concepts and 
  6745. usage in detail. 
  6746.  
  6747.  
  6748. ΓòÉΓòÉΓòÉ 5.3.1. Declarations ΓòÉΓòÉΓòÉ
  6749.  
  6750. template < class Element >
  6751. class IRef {
  6752. protected:
  6753.   Element *ivPtr;
  6754. public:
  6755.   IRef () : ivPtr (0) {}
  6756.   IRef (Element *ptr) : ivPtr (ptr) {}
  6757.   operator Element&       ()       { return *ivPtr; }
  6758.   operator Element const& () const { return *ivPtr; }
  6759.   Element*       operator & ()       { return ivPtr; }
  6760.   Element const* operator & () const { return ivPtr; }
  6761.   friend inline Element&       elementForOps (IRef < Element > &     ref)
  6762.   { return *ref.ivPtr; }
  6763.   friend inline Element const& elementForOps (IRef < Element > const&ref)
  6764.   { return *ref.ivPtr; }
  6765. };
  6766. template < class Element >
  6767. class IMgRef {
  6768. protected:
  6769.   struct PtrRc {
  6770.     Element *ivPtr;
  6771.     unsigned int ivRc;
  6772.     PtrRc (Element *ptr) : ivPtr (ptr), ivRc (1) {}
  6773.     ~PtrRc () { delete ivPtr; }
  6774.   } *ivPtrRc;
  6775. public:
  6776.   IMgRef () : ivPtrRc (0) {}
  6777.   IMgRef (Element *ptr) {
  6778.     ivPtrRc = new PtrRc (ptr);
  6779.   }
  6780.   IMgRef (Element const& e) {
  6781.     ivPtrRc = new PtrRc (new Element (e));
  6782.   }
  6783.   IMgRef (IMgRef < Element > const& ref) {
  6784.     ivPtrRc = ref.ivPtrRc;
  6785.     ivPtrRc->ivRc++;
  6786.   }
  6787.   ~IMgRef () {
  6788.     if (ivPtrRc && --ivPtrRc->ivRc == 0) delete ivPtrRc;
  6789.   }
  6790.   IMgRef < Element >& operator= (IMgRef < Element > const& ref) {
  6791.     if (ivPtrRc == ref.ivPtrRc) return *this;
  6792.     if (ivPtrRc && --ivPtrRc->ivRc == 0) delete ivPtrRc;
  6793.     ivPtrRc = ref.ivPtrRc;
  6794.     ivPtrRc->ivRc++;
  6795.     return *this;
  6796.   }
  6797.   operator Element&       ()       { return *ivPtrRc->ivPtr; }
  6798.   operator Element const& () const { return *ivPtrRc->ivPtr; }
  6799.   friend inline Element&       elementForOps (IMgRef < Element > &     ref)
  6800.   { return *ref.ivPtrRc->ivPtr; }
  6801.   friend inline Element const& elementForOps (IMgRef < Element > const&ref)
  6802.   { return *ref.ivPtrRc->ivPtr; }
  6803. };
  6804.  
  6805.  
  6806. ΓòÉΓòÉΓòÉ 6. subj='Abstract Classes'.Reference Manual - Abstract Classes ΓòÉΓòÉΓòÉ
  6807.  
  6808. The following chapters describe the abstract classes of the library. 
  6809.  
  6810.  
  6811. ΓòÉΓòÉΓòÉ 6.1. Collection ΓòÉΓòÉΓòÉ
  6812.  
  6813. The collection is an abstract class. I.e. it cannot be used to create any 
  6814. objects. The following abstract classes are derived from collection: 
  6815.  
  6816. o key collection 
  6817.  
  6818. o equality collection 
  6819.  
  6820. o ordered collection 
  6821. The following concrete classes are defined by collection: 
  6822.  
  6823. o heap 
  6824. "Figure: The abstract class hierarchy" shows the position of collection in 
  6825. respect to the whole class hierarchie. 
  6826.  
  6827.  
  6828. ΓòÉΓòÉΓòÉ 6.1.1. Declarations ΓòÉΓòÉΓòÉ
  6829.  
  6830. template < class Element >
  6831. class IACollection {
  6832. public:
  6833.   virtual                ~IACollection             ();
  6834.   virtual Boolean        add                         (Element const&) = 0;
  6835.   virtual Boolean        add                         (Element const&,
  6836.                                                ICursor&) = 0;
  6837.   virtual void           addAllFrom                  (IACollection <Element> const&);
  6838.   virtual void           copy                        (IACollection
  6839.                                                   <Element> const&);
  6840.   virtual Element const& elementAt                   (ICursor const&) const = 0;
  6841.   virtual Element&       elementAt                   (ICursor const&) = 0;
  6842.   virtual Element const& anyElement                  () const = 0;
  6843.   virtual void           removeAt                    (ICursor const&) = 0;
  6844.   virtual INumber        removeAll                   (Boolean (*property)
  6845.                                                (Element const&, void*),
  6846.                                                void* additionalArgument = 0) = 0;
  6847.   virtual void           replaceAt                   (ICursor const&,
  6848.                                                Element const&) = 0;
  6849.   virtual void           removeAll                   () = 0;
  6850.   virtual Boolean        isBounded                   () const = 0;
  6851.   virtual INumber        maxNumberOfElements         () const = 0;
  6852.   virtual INumber        numberOfElements            () const = 0;
  6853.   virtual Boolean        isEmpty                     () const = 0;
  6854.   virtual Boolean        isFull                      () const = 0;
  6855.   virtual ICursor*       newCursor                   () const = 0;
  6856.   virtual Boolean        setToFirst                  (ICursor&) const = 0;
  6857.   virtual Boolean        setToNext                   (ICursor&) const = 0;
  6858.   virtual Boolean        allElementsDo               (Boolean (*function)
  6859.                                                   (Element&, void*),
  6860.                                                void* additionalArgument = 0) = 0;
  6861.   virtual Boolean        allElementsDo               (IIterator <Element>&) = 0;
  6862.   virtual Boolean        allElementsDo               (Boolean (*function)
  6863.                                                (Element const&, void*),
  6864.                                                void* additionalArgument = 0)
  6865.                                                const = 0;
  6866.   virtual Boolean        allElementsDo               (IConstantIterator
  6867.                                                   <Element>&) const = 0;
  6868. };
  6869.  
  6870.  
  6871. ΓòÉΓòÉΓòÉ 6.2. Equality Collection ΓòÉΓòÉΓòÉ
  6872.  
  6873. The equality collection is an abstract class. I.e. it cannot be used to create 
  6874. any objects. The equality collection inherits from collection. It defines the 
  6875. interfaces for the following properties: 
  6876.  
  6877. o element equality 
  6878. The following abstract classes are derived from equality collection: 
  6879.  
  6880. o equality key collection 
  6881.  
  6882. o equality sorted collection 
  6883. The following concrete classes are defined by equality collection: 
  6884.  
  6885. o set 
  6886.  
  6887. o bag 
  6888.  
  6889. o equality sequence. 
  6890. "Figure: The abstract class hierarchy" shows the position of equality 
  6891. collection in respect to the whole class hierarchie. 
  6892.  
  6893.  
  6894. ΓòÉΓòÉΓòÉ 6.2.1. Declarations ΓòÉΓòÉΓòÉ
  6895.  
  6896. template < class Element >
  6897. class IAEqualityCollection : public virtual IACollection < Element > {
  6898. public:
  6899.   virtual Boolean        contains                    (Element const&) const = 0;
  6900.   virtual Boolean        containsAllFrom             (IACollection <Element>
  6901.                                                const&) const;
  6902.   virtual Boolean        locate                      (Element const&, ICursor&)
  6903.                                                const = 0;
  6904.   virtual Boolean        locateOrAdd                 (Element const&) = 0;
  6905.   virtual Boolean        locateOrAdd                 (Element const&,
  6906.                                                ICursor&) = 0;
  6907.   virtual Boolean        remove                      (Element const&) = 0;
  6908.   virtual INumber        numberOfOccurrences         (Element const&) const = 0;
  6909.   virtual Boolean        locateNext                  (Element const&, ICursor&)
  6910.                                                const = 0;
  6911.   virtual INumber        removeAllOccurrences        (Element const&) = 0;
  6912. protected:
  6913.   static Boolean isContained (Element const&, void* env);
  6914.   static Boolean isNotContained (Element const&, void* env);
  6915. };
  6916.  
  6917.  
  6918. ΓòÉΓòÉΓòÉ 6.3. Key Collection ΓòÉΓòÉΓòÉ
  6919.  
  6920. The key collection is an abstract class. I.e. it cannot be used to create any 
  6921. objects. The key collection inherits from collection. It defines the interfaces 
  6922. for the following properties: 
  6923.  
  6924. o key 
  6925. The following abstract classes are derived from key collection: 
  6926.  
  6927. o equality key collection 
  6928.  
  6929. o key sorted collection 
  6930. The following concrete classes are defined by key collection: 
  6931.  
  6932. o key set 
  6933.  
  6934. o key bag 
  6935. "Figure: The abstract class hierarchy" shows the position of key collection in 
  6936. respect to the whole class hierarchie. 
  6937.  
  6938.  
  6939. ΓòÉΓòÉΓòÉ 6.3.1. Declarations ΓòÉΓòÉΓòÉ
  6940.  
  6941. template < class Element, class Key >
  6942. class IAKeyCollection : public virtual IACollection < Element > {
  6943. public:
  6944.   virtual Key const&     key                         (Element const&) const = 0;
  6945.   virtual Boolean        containsElementWithKey      (Key const&) const = 0;
  6946.   virtual Boolean        containsAllKeysFrom         (IACollection <Element>
  6947.                                                const&) const;
  6948.   virtual Boolean        locateElementWithKey        (Key const&, ICursor&)
  6949.                                                const = 0;
  6950.   virtual Boolean        replaceElementWithKey       (Element const&) = 0;
  6951.   virtual Boolean        replaceElementWithKey       (Element const&,
  6952.                                                ICursor&) = 0;
  6953.   virtual Boolean        locateOrAddElementWithKey   (Element const&) = 0;
  6954.   virtual Boolean        locateOrAddElementWithKey   (Element const&,
  6955.                                                ICursor&) = 0;
  6956.   virtual Boolean        addOrReplaceElementWithKey  (Element const&) = 0;
  6957.   virtual Boolean        addOrReplaceElementWithKey  (Element const&,
  6958.                                                ICursor&) = 0;
  6959.   virtual Boolean        removeElementWithKey        (Key const&) = 0;
  6960.   virtual Element const& elementWithKey              (Key const&) const = 0;
  6961.   virtual Element&       elementWithKey              (Key const&) = 0;
  6962.   virtual INumber        numberOfElementsWithKey     (Key const&) const = 0;
  6963.   virtual Boolean        locateNextElementWithKey    (Key const&,
  6964.                                                ICursor&) const = 0;
  6965.   virtual INumber        removeAllElementsWithKey    (Key const&) = 0;
  6966.   virtual INumber        numberOfDifferentKeys       () const = 0;
  6967.   virtual Boolean        setToNextWithDifferentKey   (ICursor&) const = 0;
  6968. };
  6969.  
  6970.  
  6971. ΓòÉΓòÉΓòÉ 6.4. Ordered Collection ΓòÉΓòÉΓòÉ
  6972.  
  6973. The ordered collection is an abstract class. I.e. it cannot be used to create 
  6974. any objects. The ordered collection inherits from collection. It defines the 
  6975. interfaces for the following properties: 
  6976.  
  6977. o ordered elements 
  6978. The following abstract classes are derived from ordered collection: 
  6979.  
  6980. o sorted collection 
  6981.  
  6982. o sequential collection 
  6983. "Figure: The abstract class hierarchy" shows the position of ordered collection 
  6984. in respect to the whole class hierarchie. 
  6985.  
  6986.  
  6987. ΓòÉΓòÉΓòÉ 6.4.1. Declarations ΓòÉΓòÉΓòÉ
  6988.  
  6989. template < class Element >
  6990. class IAOrderedCollection : public virtual IACollection < Element > {
  6991. public:
  6992.   virtual void           removeFirst                 () = 0;
  6993.   virtual void           removeLast                  () = 0;
  6994.   virtual void           removeAtPosition            (IPosition) = 0;
  6995.   virtual Element const& firstElement                () const = 0;
  6996.   virtual Element const& lastElement                 () const = 0;
  6997.   virtual Element const& elementAtPosition           (IPosition) const = 0;
  6998.   virtual Boolean        setToLast                   (ICursor&) const = 0;
  6999.   virtual Boolean        setToPrevious               (ICursor&) const = 0;
  7000.   virtual void           setToPosition               (IPosition,
  7001.                                                ICursor&) const = 0;
  7002.   virtual Boolean        isFirst                     (ICursor const&) const = 0;
  7003.   virtual Boolean        isLast                      (ICursor const&) const = 0;
  7004. };
  7005.  
  7006.  
  7007. ΓòÉΓòÉΓòÉ 6.5. Sorted Collection ΓòÉΓòÉΓòÉ
  7008.  
  7009. The sorted collection is an abstract class. I.e. it cannot be used to create 
  7010. any objects. The sorted collection inherits from ordered collection. It defines 
  7011. the interfaces for the following properties: 
  7012.  
  7013. o sorted elements 
  7014. The following abstract classes are derived from sorted collection: 
  7015.  
  7016. o equality sorted collection 
  7017.  
  7018. o key sorted collection 
  7019. "Figure: The abstract class hierarchy" shows the position of sorted collection 
  7020. in respect to the whole class hierarchie. 
  7021.  
  7022.  
  7023. ΓòÉΓòÉΓòÉ 6.5.1. Declarations ΓòÉΓòÉΓòÉ
  7024.  
  7025. template < class Element >
  7026. class IASortedCollection :
  7027.   public virtual IAOrderedCollection < Element > {
  7028. public:
  7029. };
  7030.  
  7031.  
  7032. ΓòÉΓòÉΓòÉ 6.6. Sequential Collection ΓòÉΓòÉΓòÉ
  7033.  
  7034. The equality key sorted collection is an abstract class. I.e. it cannot be used 
  7035. to create any objects. The equality key sorted collection inherits from ordered 
  7036. collection. It defines the interfaces for the following properties: 
  7037.  
  7038. o orderd elements 
  7039. The following concrete classes are defined by equality key sorted collection: 
  7040.  
  7041. o sequence 
  7042.  
  7043. o equality sequence 
  7044. "Figure: The abstract class hierarchy" shows the position of equality key 
  7045. sorted collection in respect to the whole class hierarchie. 
  7046.  
  7047.  
  7048. ΓòÉΓòÉΓòÉ 6.6.1. Declarations ΓòÉΓòÉΓòÉ
  7049.  
  7050. template < class Element >
  7051. class IASequentialCollection :
  7052.   public virtual IAOrderedCollection < Element > {
  7053. public:
  7054.   virtual void           addAsFirst                  (Element const&) = 0;
  7055.   virtual void           addAsFirst                  (Element const&,
  7056.                                                ICursor&) = 0;
  7057.   virtual void           addAsLast                   (Element const&) = 0;
  7058.   virtual void           addAsLast                   (Element const&,
  7059.                                                ICursor&) = 0;
  7060.   virtual void           addAsNext                   (Element const&,
  7061.                                                ICursor&) = 0;
  7062.   virtual void           addAsPrevious               (Element const&,
  7063.                                                ICursor&) = 0;
  7064.   virtual void           addAtPosition               (IPosition,
  7065.                                                Element const&) = 0;
  7066.   virtual void           addAtPosition               (IPosition,
  7067.                                                Element const&,
  7068.                                                ICursor&) = 0;
  7069.   virtual void           sort                        (long (*comparisonFunction)
  7070.                                                (Element const&,
  7071.                                                Element const&)) = 0;
  7072. };
  7073.  
  7074.  
  7075. ΓòÉΓòÉΓòÉ 6.7. Equality Key Collection ΓòÉΓòÉΓòÉ
  7076.  
  7077. The equality key collection is an abstract class. I.e. it cannot be used to 
  7078. create any objects. The equality key collection inherits from equality 
  7079. collection and key collection. It defines the interfaces for the following 
  7080. properties: 
  7081.  
  7082. o element equality 
  7083.  
  7084. o key equality 
  7085. The following abstract classes are derived from equality key collection: 
  7086.  
  7087. o equality key sorted collection 
  7088. The following concrete classes are defined by equality key collection: 
  7089.  
  7090. o map 
  7091.  
  7092. o relation 
  7093. "Figure: The abstract class hierarchy" shows the position of equality key 
  7094. collection in respect to the whole class hierarchie. 
  7095.  
  7096.  
  7097. ΓòÉΓòÉΓòÉ 6.7.1. Declarations ΓòÉΓòÉΓòÉ
  7098.  
  7099. template < class Element, class Key >
  7100. class IAEqualityKeyCollection :
  7101.   public virtual IAEqualityCollection < Element >,
  7102.   public virtual IAKeyCollection < Element, Key > {
  7103. public:
  7104. };
  7105.  
  7106.  
  7107. ΓòÉΓòÉΓòÉ 6.8. Equality Key Collection ΓòÉΓòÉΓòÉ
  7108.  
  7109. The equality key collection is an abstract class. I.e. it cannot be used to 
  7110. create any objects. The equality key collection inherits from equality 
  7111. collection and key collection. It defines the interfaces for the following 
  7112. properties: 
  7113.  
  7114. o element equality 
  7115.  
  7116. o key equality 
  7117. The following abstract classes are derived from equality key collection: 
  7118.  
  7119. o equality key sorted collection 
  7120. The following concrete classes are defined by equality key collection: 
  7121.  
  7122. o map 
  7123.  
  7124. o relation 
  7125. "Figure: The abstract class hierarchy" shows the position of equality key 
  7126. collection in respect to the whole class hierarchie. 
  7127.  
  7128.  
  7129. ΓòÉΓòÉΓòÉ 6.8.1. Declarations ΓòÉΓòÉΓòÉ
  7130.  
  7131. template < class Element, class Key >
  7132. class IAEqualityKeyCollection :
  7133.   public virtual IAEqualityCollection < Element >,
  7134.   public virtual IAKeyCollection < Element, Key > {
  7135. public:
  7136. };
  7137.  
  7138.  
  7139. ΓòÉΓòÉΓòÉ 6.9. Key Sorted Collection ΓòÉΓòÉΓòÉ
  7140.  
  7141. The key sorted collection is an abstract class. I.e. it cannot be used to 
  7142. create any objects. The key sorted collection inherits from sorted collection 
  7143. and key collection. It defines the interfaces for the following properties: 
  7144.  
  7145. o key equality 
  7146.  
  7147. o sorted elements 
  7148. The following abstract classes are derived from key sorted collection: 
  7149.  
  7150. o equality key sorted collection 
  7151. The following concrete classes are defined by key sorted collection: 
  7152.  
  7153. o key sorted set 
  7154.  
  7155. o key sorted bag 
  7156. "Figure: The abstract class hierarchy" shows the position of key sorted 
  7157. collection in respect to the whole class hierarchie. 
  7158.  
  7159.  
  7160. ΓòÉΓòÉΓòÉ 6.9.1. Declarations ΓòÉΓòÉΓòÉ
  7161.  
  7162. template < class Element, class Key >
  7163. class IAKeySortedCollection :
  7164.   public virtual IASortedCollection < Element >,
  7165.   public virtual IAKeyCollection < Element, Key > {
  7166. public:
  7167. };
  7168.  
  7169.  
  7170. ΓòÉΓòÉΓòÉ 6.10. Equality Sorted Collection ΓòÉΓòÉΓòÉ
  7171.  
  7172. The equality sorted collection is an abstract class. I.e. it cannot be used to 
  7173. create any objects. The equality sorted collection inherits from equality 
  7174. collection and sorted collection. It defines the interfaces for the following 
  7175. properties: 
  7176.  
  7177. o element equality 
  7178.  
  7179. o sorted elements 
  7180. The following abstract classes are derived from equality sorted collection: 
  7181.  
  7182. o equality key sorted collection 
  7183. The following concrete classes are defined by equality sorted collection: 
  7184.  
  7185. o sorted set 
  7186.  
  7187. o sorted bag 
  7188. "Figure: The abstract class hierarchy" shows the position of equality sorted 
  7189. collection in respect to the whole class hierarchie. 
  7190.  
  7191.  
  7192. ΓòÉΓòÉΓòÉ 6.10.1. Declarations ΓòÉΓòÉΓòÉ
  7193.  
  7194. template < class Element >
  7195. class IAEqualitySortedCollection :
  7196.   public virtual IAEqualityCollection < Element >,
  7197.   public virtual IASortedCollection < Element > {
  7198. public:
  7199. };
  7200.  
  7201.  
  7202. ΓòÉΓòÉΓòÉ 6.11. Equality Key Sorted Collection ΓòÉΓòÉΓòÉ
  7203.  
  7204. The equality key sorted collection is an abstract class. I.e. it cannot be used 
  7205. to create any objects. The equality key sorted collection inherits from 
  7206. equality key collection, key sorted collection and equality sorted collection. 
  7207. It defines the interfaces for the following properties: 
  7208.  
  7209. o element equality 
  7210.  
  7211. o key equality 
  7212.  
  7213. o sorted elements 
  7214. The following concrete classes are defined by equality key sorted collection: 
  7215.  
  7216. o sorted map 
  7217.  
  7218. o sorted relation 
  7219. "Figure: The abstract class hierarchy" shows the position of equality key 
  7220. sorted collection in respect to the whole class hierarchie. 
  7221.  
  7222.  
  7223. ΓòÉΓòÉΓòÉ 6.11.1. Declarations ΓòÉΓòÉΓòÉ
  7224.  
  7225. template < class Element, class Key >
  7226. class IAEqualityKeySortedCollection :
  7227.   public virtual IAEqualityKeyCollection < Element, Key >,
  7228.   public virtual IAEqualitySortedCollection < Element >,
  7229.   public virtual IAKeySortedCollection < Element, Key > {
  7230. public:
  7231. };
  7232.  
  7233.  
  7234. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  7235.  
  7236. Usually the compiler can optimize function calls when it knows the exact type 
  7237. of the object. Because collections are mostly passed by reference, this would 
  7238. not be possible. 
  7239.  
  7240.  
  7241. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  7242.  
  7243. The general technique to avoid such expansions is to use untyped (void*) 
  7244. implementations for functions. Collections, however, make use of element type 
  7245. specific functions which complicates the situation.