METADATA 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. Metadata-Version: 2.1
  2. Name: ruamel.ordereddict
  3. Version: 0.4.15
  4. Summary: a version of dict that keeps keys in insertion resp. sorted order
  5. Home-page: https://bitbucket.org/ruamel/ordereddict
  6. Author: Anthon van der Neut
  7. Author-email: a.van.der.neut@ruamel.eu
  8. License: MIT license
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 5 - Production/Stable
  11. Classifier: Intended Audience :: System Administrators
  12. Classifier: License :: OSI Approved :: MIT License
  13. Classifier: Operating System :: POSIX :: Linux
  14. Classifier: Programming Language :: Python
  15. The ordereddict module in short
  16. -------------------------------
  17. This is an implementation of an ordered dictionary with Key Insertion
  18. Order (KIO: updates of values do not affect the position of the key),
  19. Key Value Insertion Order (KVIO, an existing key's position is removed
  20. and put at the back). The standard library module OrderedDict, implemented
  21. later, implements a subset of ``ordereddict`` functionality.
  22. Sorted dictionaries are also provided. Currently only with Key Sorted
  23. Order (KSO, no sorting function can be specified, but you can specify a
  24. transform to apply on the key before comparison (e.g. string.lower)).
  25. This package is hosted on BitBucket and installable from PyPI::
  26. pip install ruamel.ordereddict
  27. For Windows there are 32 and 64 bit installable wheels available.
  28. Usage::
  29. from ruamel.ordereddict import ordereddict
  30. kio = ordereddict()
  31. kvio = ordereddict(kvio=True)
  32. # without relax unordered initalisation is not allowed
  33. d = ordereddict({'a':1, 'b': 2}, relax=True)
  34. sd = sorteddict({'a':1, 'b': 2}) # sorteddict is always relaxed
  35. **please note that starting with 0.4.6 you should not import _ordereddict
  36. directly**
  37. This module has been tested under:
  38. ============= ========================= ==========
  39. OS compiler Python
  40. Linux Mint 17 gcc 4.8.4 2.7.13
  41. Windows Visual Studio 2010 2.7.13-32
  42. Windows Visual Studio 2010 2.7.13-64
  43. ============= ========================= ==========
  44. Older versions of this module has been tested under
  45. and I expect those to still work:
  46. ============= ======================== =========
  47. OS compiler Python
  48. Windows XP-64 Visual Studio 2010 2.7.10-32
  49. Windows XP-64 Visual Studio 2010 2.7.10-64
  50. Windows XP-64 Visual Studio 2008 2.6.9-32
  51. Windows XP-64 Visual Studio 2008 2.6.9-64
  52. Linux Mint 17 gcc 4.8.2 2.6.9
  53. Ubuntu 12.04 gcc 4.7.2 2.7.6
  54. Ubuntu 12.04 gcc 4.7.2 2.6.8
  55. Ubuntu 8.04 gcc 4.2.4 2.7.6
  56. Ubuntu 8.04 gcc 4.2.4 2.5.2
  57. Windows XP Visual C++ 2008 Express 2.7.6
  58. Windows 7 64 Windows SDK for Win7 SP1 2.7.6
  59. Ubuntu 12.04 gcc 4.6.3 2.7.3
  60. Ubuntu 8.04 gcc 4.2.4 2.6.4
  61. Ubuntu 8.04 gcc 4.2.4 2.5.2
  62. Ubuntu 8.10 gcc 4.3.2 2.5.4
  63. Ubuntu 8.10 gcc 4.3.2 2.4.6
  64. Ubuntu 7.04 gcc 4.1.2 2.5.1
  65. Ubuntu 7.04 gcc 4.1.2 2.4.4
  66. Ubuntu 6.06 gcc 2.5.1
  67. Windows XP Visual Studio 2003 2.5.1
  68. Windows XP Visual C++ 2008 Express 2.6.5
  69. Windows MingGW 4.7.0 2.7.3
  70. Solaris 10 GCC 4.4.x 2.7.3
  71. ============= ======================== =========
  72. Version 0.4.1 was tested and found working on SuSE Linux Enterprise Server
  73. (GCC 4.1.0 and Intel C/C++ 10.1) by Stuart Stock.
  74. MingGW and Solaris were tested and reported to work by Wladimir with version
  75. 0.4.5
  76. Home
  77. ----------------------------
  78. https://bitbucket.org/ruamel/ordereddict is ordereddict's home on the web.
  79. Clone the repository there if you want to work from the source.
  80. http://www.xs4all.nl/~anthon/Python/ordereddict used to be
  81. ordereddict's home on the web.
  82. There you can still find the links for downloading the older version (0.4.5).
  83. Installation
  84. ------------
  85. .. comment: To install the package you can use::
  86. pip install ruamel.ordereddict
  87. You can clone and checkout the sources, and then run::
  88. python setup.py install
  89. Bugreporting
  90. ------------
  91. If you find any problems, please let me know, but also realise that I
  92. have a spamfilter that catches over 100 emails a day and yours might
  93. get in there unnoticed. So if there is no response within a few days
  94. please try again.
  95. Functionality
  96. -------------
  97. ordereddict has all of the functionality of dict() except that there
  98. is no keyword based initialisation and that you cannot pass a normal
  99. dict to the initialisation of the basic ordereddict (however see the
  100. relax-ed keyword below). sorteddict cannot be initialised from keywords
  101. either, but can be initialised from normal dict (ie. they are always
  102. relaxed).
  103. As you probably would expect .keys(), .values(), .items(),
  104. .iterkeys(), itervalues(), iteritems() and "for i in some_ordereddict"
  105. have elements ordered based on the key insertion order (or key value
  106. insertion order if kvio is specified, or sort order for sorteddict).
  107. ordered/sorteddicts can be pickled.
  108. Some methods have been slightly changed:
  109. - initialisation of ordereddict takes keywords:
  110. - kvio: if set to True, then move an existing key on update
  111. - relax: if set to True, the ordereddict is relaxed for its life regarding
  112. initialisation and/or update from unordered data (read a normal dict).
  113. - initialisation of sorteddict takes keyword:
  114. - key: specifies a function to apply on key (e.g. string.lower)
  115. - .popitem() takes an optional argument (defaulting to -1) indicating which
  116. key/value pair to return (by default the last one available)
  117. - .dict()/.values()/.items()/.iterdict()/.itervalues()/.iteritems()
  118. all take an optional reverse (default False) parameter that gives
  119. the list reversed order resp. iterates in reverse
  120. (the non-iterator can also be done relatively efficient with e.g.
  121. od.dict().reverse() )
  122. - .update(): takes an optional relax=True which allows one time
  123. ordereddict update from normal dictionaries regardless of
  124. initialisation time relax setting.
  125. In addition to that ordereddict and sorteddict have some extra methods:
  126. - .index(key) - gives an integer value that is the index of the key
  127. - .setkeys()/.setvalues()/.setitems(), work like those in the Larosa/Foord
  128. implementation, although they might throw different exceptions:
  129. - setvalues' argument must be an itereable that returns the same number of
  130. items as the length of the ordereddict
  131. - setitems' argument is free in length, it performs a clear and adds
  132. the items in order.
  133. - slice retrieval for all
  134. and ordereddict only also has:
  135. - .setkeys(), works like the one in the Larosa/Foord
  136. implementation. Argument must be an itereable returning a permutation of the
  137. existing keys ( that implies having the same length as the ordereddict)
  138. - .reverse() - reverses the keys in place
  139. - .insert(position, key, value) - this will put a key at a particular position
  140. so that afterwards .index(key) == position, if the key was already there
  141. the original position (and value) is lost to the new position. This often
  142. means moving keys to new positions!
  143. - slice deletion/assignment:
  144. - stepped deletion could be optimized a bit (individual items are deleted
  145. which can require memmoving multiple items)
  146. - assignment only from OrderedDict (with the same length as the slice). This
  147. could also be optimised as I first delete, then insert individual items.
  148. If the assigned items contain keys that are still there after the deletion
  149. 'phase' then retrieving that slice does not always give the original
  150. assigned ordereddict (depending on the position of the items
  151. with those keys in either ordereddict)
  152. - .rename(oldkey, newkey) renames a key, but keeps the items position and value
  153. The new OrderedDict in the standard collections module
  154. ------------------------------------------------------
  155. With Python 3.1 and backported to 2.7 there is an OrderedDict class
  156. available in the collections modules. Raymond Hettinger indicated in
  157. 2009 at EuroPython that he preferred to start from a minimal
  158. OrderedDict instead of using the Larosa/Foord
  159. implementation. Unfortunately the available tests (for the
  160. functionality that the simple collections.OrderedDict supports) were
  161. not used either resulting in preventable bugs like repr initially not
  162. working on recursive OrderedDicts.
  163. ordereddict (and the Larosa/Foord implementation) is essentially
  164. a superset of collections.OrderedDict, but there are a few
  165. differences:
  166. - OrderedDict is by default relax-ed.
  167. - repr of recursive OrderedDict does not give any indication of the
  168. value of the recursive key, as it only displays `...`. ordereddict
  169. displays `ordereddict([...])` as value. Just using the dots like
  170. OrderedDict does is going to be ambiguous as soon as you have two different
  171. types A and B and nest A in B in A or B in B in A.
  172. - some newer build-in functions available in OrderedDict are not
  173. available in ordereddict ( __reversed__, viewkeys, viewvalues, viewitems).
  174. All of the differences can be straightened out in small (70 lines of
  175. Python) OrderedDict wrapper around ordereddict. With this wrapper the
  176. OrderedDict tests in the standard test_collections.py all pass.
  177. Testing
  178. -------
  179. testordereddict.py in the test subdirectory has been used to test the module.
  180. You can use::
  181. python testordereddict
  182. to run the tests (py.test support has been dropped as newer versions
  183. of py.test were not compatible).
  184. There is a somewhat patched copy of the python lib/Test dictionary testing
  185. routines included as well, it fails on the _update test however
  186. because the default is not to use a relaxed ordereddict.
  187. You can run it with::
  188. cd test/unit
  189. python test_dict.py
  190. To Do
  191. -----
  192. - implement Value Sorted Order (VSO: specify value=True for normal
  193. value comparison), or a value rewrite function for VSO ( e.g.
  194. value=string.lower )
  195. - implement Item Sorted Order (ISO): compare value then key ( the other way
  196. around would not make sense with unique keys, but we might have
  197. non-unique values).
  198. - implement slice deletion for sorteddict
  199. - more testing of sorteddict functionality
  200. - speedtest slices
  201. - speedtest sorteddict
  202. - check on the test_update unittest in test_dict.py
  203. To Consider
  204. -----------
  205. - comparing ordereddicts (as per Larosa/Foord)
  206. - implement the whole (optionally) using pointers in the DictObject Items
  207. (Faster on insertion/deletion, slower on accessing slices, makes
  208. implementing algorithms somewhat more difficult), would have to seperate
  209. code for sorteddict as key position determination would be much slower.
  210. - supply a pure Python implementation of exactly the functionality in
  211. ordereddict
  212. - test on older versions (< 2.4) of Python and make portable (if this can
  213. be done without too much clutter) or port.
  214. - test on the Mac
  215. - optimise searching for an item pointer for sorteddict with binary search
  216. (for deletion)
  217. Background information
  218. ----------------------
  219. ordereddict is directly derived from Python's own dictobject.c file.
  220. The extensions and the representation of ordereddicts() are based
  221. on Larosa/Foord's excellent pure Python OrderedDict() module
  222. (http://www.voidspace.org.uk/python/odict.html).
  223. The implemenation adds a vector of pointers to elements to the basic
  224. dictionary structure and keeps this vector compact (and in order) so
  225. indexing is fast. The elements do not know about their position (so
  226. nothing needs to be updated there if that position changes, but then
  227. finding an item's index is expensive. Insertion/deletion is also relatively
  228. expensive in that on average half of the vector of pointers needs to
  229. be memmove-d one position.
  230. There is also a long value for bit info like kvio, relaxed.
  231. The sorteddict structure has an additional 3 pointers of which only
  232. one (sd_key) is currently used (the others are sd_cmp and sd_value).
  233. Speed
  234. -----
  235. Based on some tests with best of 10 iterations of 10000 iterations of various
  236. functions under Ubuntu 7.10 (see test/timeordereddict.py and test/ta.py)::
  237. Results in seconds:
  238. ------------------------------- dict ordereddict Larosa/Ford collections
  239. OrderedDict OrderedDict
  240. empty 0.023 0.025 0.023 0.024
  241. create_empty 0.028 0.031 0.147 0.329
  242. create_five_entry 0.037 0.042 0.384 0.558
  243. create_26_entry 0.187 0.203 1.494 1.602
  244. create_676_entry 5.330 5.574 36.797 34.810
  245. get_keys_from_26_entry 0.209 0.231 1.501 1.762
  246. pop_5_items_26_entry 0.219 0.247 1.952 1.864
  247. pop_26_items_676_entry 7.550 8.127 46.578 41.851
  248. popitem_last_26_entry 0.203 0.225 1.624 1.734
  249. popitem_last_676_entry 5.285 5.534 36.912 34.799
  250. popitem_100_676_entry -------- 5.552 36.577 --------
  251. walk_26_iteritems -------- 0.494 2.792 2.238
  252. ------------------------------- dict ordereddict Larosa/Ford collections
  253. OrderedDict OrderedDict
  254. empty 0.930 1.000 0.950 0.966
  255. create_empty 0.909 1.000 4.728 10.594
  256. create_five_entry 0.892 1.000 9.201 13.374
  257. create_26_entry 0.923 1.000 7.368 7.901
  258. create_676_entry 0.956 1.000 6.601 6.245
  259. get_keys_from_26_entry 0.908 1.000 6.508 7.641
  260. pop_5_items_26_entry 0.888 1.000 7.916 7.559
  261. pop_26_items_676_entry 0.929 1.000 5.732 5.150
  262. popitem_last_26_entry 0.901 1.000 7.222 7.712
  263. popitem_last_676_entry 0.955 1.000 6.670 6.288
  264. popitem_100_676_entry -------- 1.000 6.588 --------
  265. walk_26_iteritems -------- 1.000 5.653 4.532
  266. Why
  267. ---
  268. Because I am orderly ;-O, and because I use dictionaries to
  269. store key/value information read from some text file quite often.
  270. Unfortunately comparing those files with diff when written from
  271. normal dictionaries often obfucates changes because of the reordering
  272. of lines when key/value pairs are added and then written.
  273. I have special routine for YAML files that takes lines like::
  274. - key1: val1
  275. - key2: val3
  276. - key3:
  277. - val3a
  278. - val3b
  279. (i.e. a list of key-value pairs) directly to a single ordered dictionary
  280. and back. (I find it kind of strange to finally have a structured,
  281. human readeable, format that does not try to preserve the
  282. order of key-value pairs so that comparing files is difficult with
  283. 'standard' text tools).
  284. Older versions
  285. --------------
  286. http://www.xs4all.nl/~anthon/Python/ordereddict used to be
  287. ordereddict's home on the web.
  288. There you can still find the links for downloading the older version (0.4.5).
  289. History
  290. -------
  291. ``0.4.13``: 2017-0723
  292. -
  293. | ``0.4.9 2015-08-10``
  294. | typos fixed by Gianfranco Costamagna
  295. |
  296. | ``0.4.8 2015-05-31``
  297. | dependent on ruamel.base
  298. | version number in a single place
  299. | using py.test under tox
  300. | generate wheel for 32/64bit py26/py27 on windows
  301. |
  302. | ``0.4.6 2014-01-18``
  303. | Move to ruamel namespace, hosted on bitbucket, MIT License
  304. | Testing with tox
  305. |
  306. | ``0.4.5 2012-06-17``
  307. | Fix for a bug while inserting last item again beyond last position (reported
  308. | by Volkan Çetin / volki tolki ( cetinv at gmail.com )
  309. | Fix for repeated deletion and insertion fail. Found by and solution provided
  310. | by Darren Dowker (including tests). Also found by Fabio Zadronzy (including
  311. | a less elegant fix).
  312. | applied reindent to .py and astyle to .c files
  313. |
  314. | ``0.4.3 2009-05-11``
  315. | Fix for a bug in slicing SortedDicts.
  316. | Found by, and fix provided by, Migel Anguel (linos.es)
  317. |
  318. | ``0.4.2 2009-03-27``
  319. | Bug found and by Alexandre Andrade and Fabio Zadrozny in
  320. | doing deepcopy
  321. |
  322. | ``0.4.1 2007-11-06``
  323. | Bug found and fixed by Fabio Zadrozny on resizing dictionaries
  324. |
  325. | ``0.4 2007-10-30``
  326. | added pickling, added relaxed initialisation/update (from unordered dicts)
  327. | added KVIO (Key Value Insertion Order ie. key moves to back on update)
  328. | implemented sorteddict, with KSO, Key Sorted Order. You can specify
  329. | a function for key transformation before comparison (such as string.lower)
  330. | sorteddict does not have all of the ordereddict methods as not all make
  331. | sense (eg. slice assignment, rename, setkeys)
  332. |
  333. | ``0.3 2007-10-24``
  334. | added setkeys/setvalues/setitems; slice retrieval, deletion, assignment
  335. | .rename(oldkey, newkey) rename a key keeping same value and position
  336. | .index() of non-existing key now returns ValueError instead of SystemError
  337. | Changed the module name to _ordereddict (from ordereddict), as Jason
  338. | Kirstland probably rightfully suggested that any private implementation
  339. | likely has the (file)name ordereddict.py. A modulename with leading
  340. | underscore seams more common for extension modules anyway.
  341. |
  342. | ``0.2a 2007-10-16``
  343. | Solved the potential GC problem on Windows
  344. |
  345. | ``0.2 2007-10-16``
  346. | First release, with some tests, and possible still a GC problem
  347. | with Windows.
  348. |
  349. | ``0.1 2007-10-..``
  350. | This version was never released. While testing it I was far in writing
  351. | an email to comp.lang.python about why timing with timeit did seem to
  352. | be memory hungry ....
  353. | and then I realised ordereddict had a memory leak %-)