{ "info": { "author": "Gary Poster", "author_email": "gary@zope.com", "bugtrack_url": null, "classifiers": [], "description": "===========\nBForest API\n===========\n\nBForests are dictionary-like objects that use multiple BTrees for a backend and\nsupport rotation of the composite trees. This supports various implementations \nof timed member expirations, enabling caches and semi-persistent storage. A\nuseful and simple subclass would be to promote a key-value pair to the\nfirst (newest) bucket whenever the key is accessed, for instance. It also is\nuseful with disabling the rotation capability.\n\nLike btrees, bforests come in four flavors: Integer-Integer (IIBForest), \nInteger-Object (IOBForest), Object-Integer (OIBForest), and Object-Object\n(OOBForest). The examples here will deal with them in the abstract: we will\ncreate classes from the imaginary and representative BForest class, and\ngenerate keys from KeyGenerator and values from ValueGenerator. From the \nexamples you should be able to extrapolate usage of all four types.\n\nFirst let's instantiate a bforest and look at an empty example. By default,\na new bforest creates two composite btree buckets.\n\n >>> d = BForest()\n >>> list(d.keys())\n []\n >>> list(d.values())\n []\n >>> len(d.buckets)\n 2\n >>> dummy_key = KeyGenerator()\n >>> d.get(dummy_key)\n >>> d.get(dummy_key, 42)\n 42\n\nNow we'll populate it. We'll first create a BTree we'll use to compare.\n\n >>> original = BForest._treemodule.BTree()\n >>> for i in range(10):\n ... original[KeyGenerator()] = ValueGenerator()\n ... \n >>> d.update(original)\n >>> d == original\n True\n >>> list(d) == list(original)\n True\n >>> list(d.keys()) == list(original.keys())\n True\n >>> list(d.values()) == list(original.values())\n True\n >>> list(d.items()) == list(original.items())\n True\n >>> original_min = original.minKey()\n >>> d.popitem() == (original_min, original.pop(original_min))\n True\n >>> original_min = original.minKey()\n >>> d.pop(original_min) == original.pop(original_min)\n True\n >>> len(d) == len(original)\n True\n\nNow let's rotate the buckets.\n\n >>> d.rotateBucket()\n\n...and we'll do the exact same test as above, first.\n\n >>> d == original\n True\n >>> list(d) == list(original)\n True\n >>> list(d.keys()) == list(original.keys())\n True\n >>> list(d.values()) == list(original.values())\n True\n >>> list(d.items()) == list(original.items())\n True\n >>> original_min = original.minKey()\n >>> d.popitem() == (original_min, original.pop(original_min))\n True\n >>> original_min = original.minKey()\n >>> d.pop(original_min) == original.pop(original_min)\n True\n >>> len(d) == len(original)\n True\n\nNow we'll make a new dictionary to represent changes made after the bucket\nrotation.\n\n >>> second = BForest._treemodule.BTree()\n >>> for i in range(10):\n ... key = KeyGenerator()\n ... value = ValueGenerator()\n ... second[key] = value\n ... d[key] = value\n ... \n >>> original.update(second)\n\n...and we'll do the exact same test as above, first.\n\n >>> d == original\n True\n >>> list(d) == list(original)\n True\n >>> list(d.keys()) == list(original.keys())\n True\n >>> list(d.values()) == list(original.values())\n True\n >>> list(d.items()) == list(original.items())\n True\n >>> original_min = original.minKey()\n >>> d.popitem() == (original_min, original.pop(original_min))\n True\n >>> if original_min in second:\n ... _ = second.pop(original_min)\n >>> original_min = original.minKey()\n >>> d.pop(original_min) == original.pop(original_min)\n True\n >>> if original_min in second:\n ... _ = second.pop(original_min)\n >>> len(d) == len(original)\n True\n\nThe bforest offers ``itervalues``, ``iterkeys``, and ``iteritems`` that have\nthe same extended arguments as BTrees' ``values``, ``keys``, and ``items``.\n\n >>> list(d.itervalues()) == list(original.values())\n True\n >>> list(d.iteritems()) == list(original.items())\n True\n >>> list(d.iterkeys()) == list(original.keys())\n True\n\n >>> keys = list(original)\n >>> mid = keys[len(keys)//2]\n >>> list(d.itervalues(min=mid)) == list(original.itervalues(min=mid))\n True\n >>> list(d.itervalues(max=mid)) == list(original.itervalues(max=mid))\n True\n >>> list(d.itervalues(min=mid, excludemin=True)) == list(\n ... original.itervalues(min=mid, excludemin=True))\n True\n >>> list(d.itervalues(max=mid, excludemax=True)) == list(\n ... original.itervalues(max=mid, excludemax=True))\n True\n\n >>> list(d.iterkeys(min=mid)) == list(original.iterkeys(min=mid))\n True\n >>> list(d.iterkeys(max=mid)) == list(original.iterkeys(max=mid))\n True\n >>> list(d.iterkeys(min=mid, excludemin=True)) == list(\n ... original.iterkeys(min=mid, excludemin=True))\n True\n >>> list(d.iterkeys(max=mid, excludemax=True)) == list(\n ... original.iterkeys(max=mid, excludemax=True))\n True\n\n >>> list(d.iteritems(min=mid)) == list(original.iteritems(min=mid))\n True\n >>> list(d.iteritems(max=mid)) == list(original.iteritems(max=mid))\n True\n >>> list(d.iteritems(min=mid, excludemin=True)) == list(\n ... original.iteritems(min=mid, excludemin=True))\n True\n >>> list(d.iteritems(max=mid, excludemax=True)) == list(\n ... original.iteritems(max=mid, excludemax=True))\n True\n\nIt also offers maxKey and minKey, like BTrees.\n\n >>> d.maxKey() == original.maxKey()\n True\n >>> d.minKey() == original.minKey()\n True\n >>> d.maxKey(mid) == original.maxKey(mid)\n True\n >>> d.minKey(mid) == original.minKey(mid)\n True\n\nNow if we rotate the buckets, the first set of items will be gone, but the \nsecond will remain.\n\n >>> d.rotateBucket()\n >>> d == original\n False\n >>> d == second\n True\n\nLet's set a value, check the copy behavior, and then rotate it one more time.\n\n >>> third = BForest._treemodule.BTree({KeyGenerator(): ValueGenerator()})\n >>> d.update(third)\n >>> copy = d.copy()\n >>> copy == d\n True\n >>> copy != second # because second doesn't have the values of third\n True\n >>> list(copy.buckets[0].items()) == list(d.buckets[0].items())\n True\n >>> list(copy.buckets[1].items()) == list(d.buckets[1].items())\n True\n >>> copy[KeyGenerator()] = ValueGenerator()\n >>> copy == d\n False\n >>> d.rotateBucket()\n >>> d == third\n True\n >>> d.clear()\n >>> d == BForest() == {}\n True\n \n >>> d.update(second)\n\nWe'll make a value in one bucket that we'll override in another.\n\n >>> d[third.keys()[0]] = ValueGenerator()\n >>> d.rotateBucket()\n >>> d.update(third)\n >>> second.update(third)\n >>> d == second\n True\n >>> second == d\n True\n\nThe tree method converts the bforest to a btree efficiently for a common case\nof more items in buckets than buckets.\n\n >>> tree = d.tree()\n >>> d_items = list(d.items())\n >>> d_items.sort()\n >>> t_items = list(tree.items())\n >>> t_items.sort()\n >>> t_items == d_items\n True\n\nFinally, comparisons work similarly to dicts but in a simpleminded \nway--improvements welcome! We've already looked at a lot of examples above,\nbut here are some additional cases\n\n >>> d == None\n False\n >>> d == [1, 2]\n False\n >>> d != None\n True\n >>> None == d\n False\n >>> d != None\n True\n >>> d >= second\n True\n >>> d >= dict(second)\n True\n >>> d <= second\n True\n >>> d <= dict(second)\n True\n >>> d > second\n False\n >>> d > dict(second)\n False\n >>> d < second\n False\n >>> d > dict(second)\n False\n >>> original_min = second.minKey()\n >>> del second[original_min]\n >>> original_min in d\n True\n >>> d > second\n True\n >>> d < second\n False\n >>> d >= second\n True\n >>> d <= second\n False\n >>> second < d\n True\n >>> second > d\n False\n >>> second <= d\n True\n >>> second >= d\n False\n\n\n\n\n=======\nCHANGES\n=======\n\n1.2 (2008-05-09)\n----------------\n\nBugfixes:\n\n- added omitted __ne__ implementation.\n\nFeatures:\n\n- added minKey, maxKey, like BTrees.\n\n- gave itervalues, iteritems, and iterkeys same extra arguments as BTrees'\n values, items, and keys: min, max, excludemin, excludemax.\n\n- changed implementation of iter[...] functions to try to only wake up buckets\n as needed.\n\nIncompatible Changes:\n\n- changed definition of __eq__: now compares contents *and* order. Tries to\n only wake up buckets as needed.\n\n1.1.1 (2008-04-09)\n------------------\n\nBugfix:\n\n- periodic variant was pseudo-guaranteeing maximum period, not minimum\n period, contradicting documentation. Changed implementation and test to\n match documentation (i.e., guarantees minimum period; maximum period is\n a bit fuzzy, as described in docs).\n\n1.1 (2008-03-08)\n----------------\n\nFeatures: \n\n- added periodic variant\n\n- added L-variants\n\n1.0 (?)\n-------\n\nInitial release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "zope zope3", "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "zope.bforest", "package_url": "https://pypi.org/project/zope.bforest/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/zope.bforest/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/zope.bforest/1.2/", "requires_dist": null, "requires_python": null, "summary": "Mappings based transparently on multiple BTrees; good for rotating caches and\nlogs.", "version": "1.2" }, "last_serial": 802368, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "1b64d1d8770e206f9338bf4b17729ca7", "sha256": "15fddbaa3759a0049555d7e94536ec58af64e40d56253bd8ff4d8452e10bce48" }, "downloads": -1, "filename": "zope.bforest-1.0-py2.4.egg", "has_sig": false, "md5_digest": "1b64d1d8770e206f9338bf4b17729ca7", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 13294, "upload_time": "2006-12-01T14:48:13", "url": "https://files.pythonhosted.org/packages/69/01/10ed520c197322741e17d9dc4c14eb2554fba74f1e4f0f04f1b1e49ea75e/zope.bforest-1.0-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "fc4c56a9adca2e6e24e2391f1db6c76f", "sha256": "8f02c5111410d78420501fdc8426a6d0c69429bae13aec564cf3dacb9529ccb9" }, "downloads": -1, "filename": "zope.bforest-1.0.tar.gz", "has_sig": false, "md5_digest": "fc4c56a9adca2e6e24e2391f1db6c76f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7177, "upload_time": "2006-12-01T04:31:10", "url": "https://files.pythonhosted.org/packages/ec/26/c0559c1744cafb1326be26e08b1abf8e61bee50a6fe5571a10ed6d65bc59/zope.bforest-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "a15e9f3d65761c9fe84ab731a66c4536", "sha256": "8a66b48a08186d5a5282be2408e85cbfed17a424c6c93054de1020025dc5c221" }, "downloads": -1, "filename": "zope.bforest-1.1.tar.gz", "has_sig": false, "md5_digest": "a15e9f3d65761c9fe84ab731a66c4536", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10175, "upload_time": "2008-03-08T20:08:16", "url": "https://files.pythonhosted.org/packages/cc/a1/e50021abfa975ec11bc9d4d64668970fb69e2d9c75f23b34679417d2fa91/zope.bforest-1.1.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "02dac543994f4f3763d1eb0cf49c9a0c", "sha256": "8f2bc67875f705d30e5ee08268207e18fc0de27791c7f12bb1321a3e50ed8558" }, "downloads": -1, "filename": "zope.bforest-1.1.1.tar.gz", "has_sig": false, "md5_digest": "02dac543994f4f3763d1eb0cf49c9a0c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11560, "upload_time": "2008-04-09T20:11:34", "url": "https://files.pythonhosted.org/packages/5e/c9/ff7ee89f5ed7a6702399fc3dd25f9459f793345395a7d33395726eb71726/zope.bforest-1.1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "7fdefd275c861fcc09cc954309808c81", "sha256": "611e1e0709c51c9c8af4cab86421d9b3eeec38de03d5473008a01e44e8f389e5" }, "downloads": -1, "filename": "zope.bforest-1.2.tar.gz", "has_sig": false, "md5_digest": "7fdefd275c861fcc09cc954309808c81", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14047, "upload_time": "2008-05-09T03:06:29", "url": "https://files.pythonhosted.org/packages/94/d6/c49c8f6a288020423d205f7d07a41853cb3446d71af22ad9cbc0d1ddc1eb/zope.bforest-1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7fdefd275c861fcc09cc954309808c81", "sha256": "611e1e0709c51c9c8af4cab86421d9b3eeec38de03d5473008a01e44e8f389e5" }, "downloads": -1, "filename": "zope.bforest-1.2.tar.gz", "has_sig": false, "md5_digest": "7fdefd275c861fcc09cc954309808c81", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14047, "upload_time": "2008-05-09T03:06:29", "url": "https://files.pythonhosted.org/packages/94/d6/c49c8f6a288020423d205f7d07a41853cb3446d71af22ad9cbc0d1ddc1eb/zope.bforest-1.2.tar.gz" } ] }