history.qbk 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. [/license
  2. Boost.Bimap
  3. Copyright (c) 2006-2007 Matias Capeletto
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. ]
  8. [/ QuickBook Document version 1.4 ]
  9. [section History]
  10. [section The long path from Code Project to Boost]
  11. [variablelist
  12. [[2002 - bimap at Code Project]
  13. [
  14. Joaquin Lopez Muñoz posted his first
  15. [@https://www.codeproject.com/Articles/3016/An-STL-like-bidirectional-map#test_suite bimap library]
  16. in 2002. Tons of users have been using it. He then
  17. [@https://lists.boost.org/Archives/boost/2002/10/38123.php asked the
  18. list for interest] in his library in 2003. Luckily, there was a lot of
  19. interest and Joaquin started to boostify the code. At some point all the
  20. developers seemed to agree that, rather than a bidirectional map, it would
  21. be better to work on an N-indexed set that contained Joaquin's library as a
  22. particular case.
  23. ]]
  24. [[2003 - multiindex_set]
  25. [
  26. The library grew enormously and was ready for a formal review in
  27. 2003. At this point, the container was a lot more powerful, but
  28. everything comes with a price and this new beast lacked the simplicity
  29. of the original bimap.
  30. ]]
  31. [[2004 - indexed_set]
  32. [
  33. In 2004, the formal review ended well for the new multi-indexed
  34. container. This Swiss army knife introduced several new features, such
  35. as non-unique indexes, hashed indices and sequenced indices. In the list
  36. of improvements to the library, it was mentioned that a bidirectional
  37. map should be coded in top of this container.
  38. ]]
  39. [[2005 - multi_index_container]
  40. [
  41. Once in Boost, the library switched to the now familiar name
  42. "Boost.MultiIndex". Late in 2004, it formally became a member of Boost.
  43. Joaquin continued to enhance the library and added new features such as
  44. composite keys and random-access indices.
  45. ]]
  46. [[2006 - Multi Index Specialized Containers SoC project]
  47. [
  48. In 2006, during the formal review of Boost.Property_tree, the need
  49. for a bidirectional map container built on top of Boost.MultiIndex arose
  50. again. Boost entered the Google SoC 2006 as a mentor organization at the
  51. same time. Joaquin put himself forward as a mentor. He proposed to build
  52. not only a bidirectional map, but a myriad multi-indexed specialized
  53. containers. Matias Capeletto presented an application to code Boost.Misc
  54. for the SoC and was elected, along with nine other students. Matias's and
  55. Joaquin's SoC project ends with a working implementation of the bimap
  56. library that was presented in an informal review. By the end of the year
  57. the library was queued for a formal review.
  58. ]]
  59. [[2007 - Boost.Bimap]
  60. [
  61. The formal review took place at the beginning of the year and Boost.Bimap
  62. was accepted in Boost.
  63. ]]
  64. ]
  65. [endsect]
  66. [section MultiIndex and Bimap]
  67. This is the conversation thread that began during Boost.PropertyTree formal
  68. review process. The review was very interesting and very deep topics were
  69. addressed. It is quite interesting and it is now part of this library history.
  70. Enjoy!
  71. [*Marcin]
  72. [:['
  73. The biggest virtue of property_tree is easy to use interface.
  74. If we try to make generic tree of it, it will be compromised.
  75. ]]
  76. [*Gennadiy]
  77. [:['
  78. IMO the same result (as library presents) could be achieved
  79. just by using multi_index.
  80. ]]
  81. [*Marcin]
  82. [:['
  83. Could you elaborate more on that? I considered use of
  84. multi_index to implement indexing for properties, but it only affected the
  85. implementation part of library, not interface, and because I already had a
  86. working, exception safe solution, I didn't see the reason to dump it and add
  87. another dependency on another library.
  88. ]]
  89. [*Gennadiy]
  90. [:['
  91. I mean why do I need this half baked property_tree as another
  92. data structure? Property tree supports nothing in itself. It's just a data
  93. structure. You have parsers that produce property tree out of different sources.
  94. But you mat as well produce maps or something else. Here for example All that
  95. I need to do to "implement" similar functionality as your property tree:
  96. ]]
  97. ``
  98. // Data structure itself
  99. template<typename ValueType,typename KeyType>
  100. struct Node;
  101. template<typename ValueType,typename KeyType>
  102. struct ptree_gen {
  103. typedef std::pair<KeyType,Node<ValueType,KeyType> > mi_value;
  104. typedef multi_index_container<mi_value, indexed_by<...> > type;
  105. };
  106. template<typename ValueType,typename KeyType>
  107. struct Node {
  108. ValueType v;
  109. ptree_gen<ValueType,KeyType>::type children;
  110. };
  111. // serialization support
  112. template<class Archive,typename ValueType,typename KeyType>
  113. void serialize(Archive & ar, Node<ValueType,KeyType>& n,
  114. const unsigned int version)
  115. {
  116. ar & n.v;
  117. ar & n.children;
  118. }
  119. // some access methods
  120. template<typename ValueType,typename KeyType>
  121. ValueType const&
  122. get( string const& keys, ptree_gen<ValueType,KeyType>::type const& src )
  123. {
  124. std::pait<string,string> sk = split( keys, "." );
  125. Node const& N = src.find( sk.first );
  126. return sk.second.empty() ? N.v : get( sk.second, N.children );
  127. }
  128. ``
  129. [:['
  130. Use it like this:
  131. ]]
  132. ``
  133. ptree_gen<string,string>::type PT;
  134. boost::archive::text_iarchive ia( std::ifstream ifs("filename") );
  135. ia >> PT;
  136. string value = get( "a.b.c.d", PT );
  137. ``
  138. [:['
  139. Now tell me how property_tree interface is easier? And what is the value in
  140. 50k of Code you need to implement this data structure.
  141. ]]
  142. [*Thorsten]
  143. [:['
  144. Seriously Gennadiy, do you really see newbies writing
  145. the code you just did?
  146. ]]
  147. [*Marcin]
  148. [:['
  149. What you just implemented is stripped down, bare bones version
  150. of property_tree that, among other things, does not allow you to produce human
  151. editable XML files. Now add more interface (aka get functions), add more
  152. archives to serialization lib, add customization, add transparent
  153. translation from strings to arbitrary types and vice versa. Spend some weeks
  154. trying to get all the corner cases right, and then some more weeks trying to
  155. smooth rough edges in the interface. Then write tests. Write docs. At the
  156. end, I believe you will not get much less code than there is in the library
  157. already. Maybe you get some savings by using multi_index instead of manual
  158. indexing.
  159. ]]
  160. [:['
  161. The reason why ptree does not use multi index is because implementation
  162. existed long before I considered submitting to boost, probably before even I
  163. knew of multi index existence. It was working well. Later, when I was
  164. improving it during pre-review process, I seriously considered using
  165. multi-index. But I decided it is not worth throwing everything out.
  166. ]]
  167. [:['
  168. Although ptree has large interface with many functions modifying state of
  169. the tree, it uses "single point of change" approach. Every insert eventually
  170. goes through one function, which takes care of exception safety and keeping
  171. index in sync with data. The same applies to erase. This function has 9
  172. lines of code in case of insert, and (by coincidence) also 9 in case of
  173. erase. By using multi index these functions would obviously be simplified,
  174. maybe to 4 lines each. Net gain: 10 lines of code (out of several hundred in
  175. ptree_implementation.hpp).
  176. ]]
  177. [:['
  178. I'm aware that there are performance gains to be reaped as well, but at that
  179. time I was rather focusing on getting the interface right.
  180. ]]
  181. [*Dave]
  182. [:['
  183. That's perfectly reasonable, but (through no fault of yours)
  184. it misses the point I was trying to make. I guess I should have said,
  185. "...that demonstrates it to be the best implementation."
  186. ]]
  187. [:['
  188. All I'm saying is that the extent to which a Boost library
  189. implementation should leverage other Boost libraries is not a question
  190. that can always be decided based on following simple guidelines, and
  191. that if this library is accepted, it's worth revisiting your decision.
  192. ]]
  193. [*Thorsten]
  194. [:['
  195. I think it is important to focus on the interface in
  196. the review, but I also see several benefits of an implementation that builds on
  197. Boost.MultiIndex:'
  198. ]]
  199. [:['- fewer bugs like the one Joaquin found]]
  200. [:['- better space efficiency]]
  201. [:['- exception-safety guarantees are immediately full-filled (I haven't
  202. looked, but I suspect that there are several bugs in this area)]]
  203. [*Daniel]
  204. [:['
  205. Multi_index supports everything a bimap would, but its
  206. interface is more cumbersome. I for one won't use a W3DOM-like library
  207. if we get one, but I would happily use property_tree. I've also only
  208. used multi_index once, and that was to use it as a bidirectional map.
  209. Property_tree covers other areas as well as being a potential subset of
  210. an XML library, but I still hold there is value in such a subset.
  211. ]]
  212. [*Boris]
  213. [:['
  214. I haven't used program_options yet. But if I understand
  215. correctly both libraries seem to support storing and accessing data with
  216. strings that might describe some kind of hierarchy. This seems to be the core
  217. idea of both libraries - is this correct?
  218. ]]
  219. [:['
  220. Then it wouldn't matter much what container is used. However a generic tree
  221. which can store data hierarchically probably makes most sense. If I
  222. understand correctly both libraries could make use of such a class?
  223. ]]
  224. [*Marcin]
  225. [:['
  226. I think generic tree container is material for another library.
  227. Whether property_tree should be based on it or not is a matter of internal
  228. implementation, and generally of little interest to users. The biggest value
  229. of property_tree is in its easy to use interface, that should not be
  230. compromised, if at all possible. I have been already reassured in this view
  231. by quite many people who took their time to review the library.
  232. ]]
  233. [*Boris]
  234. [:['
  235. I was trying to see the big picture: I rather prefer a C++
  236. standard based on a few well-known concepts like containers, iterators,
  237. algorithms etc. instead of having a C++ standard with hundreds of components
  238. which are tailored for specific needs, collaborate with only a handful of other
  239. components and think they provide an easy-to-use interface while all the
  240. easy-to-use interfaces make the whole standard less easy-to-use.
  241. ]]
  242. [:['
  243. That said I have used your property tree library myself to read and write a
  244. configuration file. It was indeed very easy to use. However it would have
  245. been even easier if it was something I had known before like eg. an
  246. iterator. For now I will definitely use your property tree library but would
  247. appreciate if existing concepts were reused many C++ developers are familiar
  248. with. My opinion is that your library should be a part of Boost but should
  249. be more generalized in the future.
  250. ]]
  251. [*Thorsten]
  252. [:['
  253. Well, I think we need both. Boost.MultiIndex is a great
  254. library and can do all kinds of wonderful things. But I would still like to see
  255. a bidirectional map (boost::bimap) written as a wrapper around it to
  256. get an easy and specialized interface.
  257. ]]
  258. [*Pavel]
  259. [:['
  260. Bimap is available in libs/multi-index/examples/bimap.cpp.
  261. ]]
  262. [*Thorsten]
  263. [:['
  264. Right, but the real value comes when somebody designs a nice
  265. STL-like interface and write docs etc, at least that was my point.
  266. ]]
  267. [*Dave]
  268. [:['
  269. IMO Thorsten is exactly right. This is precisely the sort of
  270. thing that could be added to the library as part of its ongoing maintenance
  271. and development (without review, of course).
  272. ]]
  273. [*Joaquin]
  274. [:['
  275. Thorsten, we have talked about this privately in the past,
  276. but I feel like bringing it to the list in the hope of getting the attention
  277. of potential contributors:
  278. ]]
  279. [:['
  280. There are some data structures buildable with B.MI which are regarded as
  281. particularly useful or common, like for instance the bidirectional map or
  282. bimap. A lean and mean implementation is provided in the aforementioned
  283. example, but certainly a much carefully crafted interface can be provided
  284. keeping B.MI as the implementation core: operator\[\], selection of
  285. 1-1/1-N/N-1/N-N variants, hashing/ordering, etc.
  286. ]]
  287. [:['
  288. I'm afraid I don't have the time to pursue this, as the current roadmap for
  289. core features of B.MI is taking all the spare time I can dedicate to the
  290. library. For this reason, I would love to see some volunteer jumping in who
  291. can develop this and other singular containers using B.MI (a cache container
  292. comes to mind) and then propose the results here either as a stand alone
  293. library of as part of B.MI --I'd prefer the former so as to keep the size
  294. of B.MI bounded.
  295. ]]
  296. [:['
  297. If there's such a volunteer I can provide her with some help/mentoring. I also
  298. wonder whether this is a task suitable to be proposed for Google Summer of
  299. Code.
  300. ]]
  301. [*Thorsten]
  302. [:['
  303. I think it would be good for SOC. All the really hard things
  304. are taken care of by B.MI, and so it seems reasonable for a student to be able
  305. to fill in the details.
  306. ]]
  307. [*Dave]
  308. [:['
  309. Great!
  310. ]]
  311. [*Jeff]
  312. [:['
  313. Please write a proposal!
  314. ]]
  315. [*Joaquin]
  316. [:['
  317. I've just done so:
  318. ]]
  319. [blurb *Specialized containers with Boost.MultiIndex*
  320. *Introduction*
  321. Boost.MultiIndex allows the construction of complex data structures involving
  322. two or more indexing mechanisms on the same set of elements. Out of the
  323. unlimited range of possible data structures specifiable within
  324. Boost.MultiIndex, some particular configurations arise recurrently:
  325. *a.* A bidirectional map or bimap is a container of elements of type pair<T,Q>
  326. where fast look up is provided both for the T and the Q field,
  327. in contrast with a regular STL map which only allows for fast look up on T.
  328. *b.* An MRU (most recently used) list keeps the n last referenced elements:
  329. when a new item is inserted and the list has reached its maximum length, the
  330. oldest element is erased, whereas if an insertion is tried of a preexistence
  331. element, this gets promoted to the first position. MRU lists can be used to
  332. implement dynamic caches and the kind of behavior exhibited by programs
  333. featuring a "Recent files" menu command, for instance.
  334. Although Boost.MultiIndex provides the mechanisms to build these common structures,
  335. the resulting interface can be cumbersome and too general in comparison with
  336. specialized containers focusing on such particular structures.
  337. *Goal*
  338. To write a library of specialized containers like the ones described above, using
  339. Boost.MultiIndex as the implementation core. Besides bimap and MRU list, the student
  340. can also propose other specialized containers of interest in the community. It is
  341. expected that the library meets the standards of quality required by Boost for an
  342. eventual inclusion in this project, which implies a strong emphasis on interface
  343. design, documentation and unit testing; the mentor will be guiding the student
  344. through the complete cycle from specification and requirements gathering to
  345. documentation and actual coding. The final result of the project must then contain:
  346. *a.* Source code following
  347. [@http://boost.org/more/lib_guide.htm#Guidelines Boost programming guidelines].
  348. *b.* User documentation. Requirements on the format are loose, though the
  349. [@http://www.boost.org/tools/quickbook/ QuickBook] format is
  350. gaining acceptance within Boost.
  351. *c.* Complete set of unit tests powered by
  352. [@http://www.boost.org/boost-build2/ Boost Build System V2].
  353. *Requirements*
  354. *a.* Intermediate-to-high level in C++, with emphasis in generic programming
  355. (templates).
  356. *b.* Knowledge of the STL framework and design principles. Of course, knowledge
  357. of Boost in general and Boost.MultiIndex in particular is a big plus.
  358. *c.* Acquaintance with at least two different C++ programming environments.
  359. *d.* Some fluency in the English language; subsequent reviews of the documentation
  360. can help smooth rough edges here, though.
  361. *e.* A mathematical inclination and previous exposure to a formal Algorithms course
  362. would help very much.
  363. *f.* A craving for extreme quality work.
  364. *Benefits for the student*
  365. The student taking on this project will have the opportunity to learn the complete
  366. process of software production inside a highly regarded C++ open source institution,
  367. and even see her work included in Boost eventually. The completion of the project
  368. involves non-trivial problems in C++ interface design and so-called modern C++
  369. programming, high quality user documentation and unit testing. The student will
  370. also learn, perhaps to her surprise, that most of the time will be spent gathering
  371. and trying ideas and, in general, thinking, rather than writing actual code.
  372. ]
  373. [*Matias]
  374. [:['
  375. I am planning to submit an application to SoC. I will love to make real
  376. the specialized containers you mention and try to include some useful others.
  377. ]]
  378. [:[^
  379. And then... after long hours of coding (and fun) this library saw the light.
  380. ]]
  381. [:__BOOST_BIMAP_LOGO__]
  382. [endsect]
  383. [endsect]