[ZODB-Dev] RE: B-Tree API - again!
Steve Alexander
steve@cat-box.net
Fri, 06 Dec 2002 16:51:33 +0000
Gfeller Martin wrote:
> Sorry to be re-iterate my question, but all the interesting answers
> do not address our concern, namely to have a compatible interface
> between B-Tree and PersistentMapping/dictionary.
>
> Our aim is to replace PersistentMappings by OOBTrees in a large body
> of existing code, so we would profit from a do-nothing sort() method
> on the OOBTreeItems object returned by keys().
I suggest you write your own subclass of OOBTree that returns an
OOBTreeItems, like this (untested):
class MyOOBTree(OOBTree):
def keys(self, min=None, max=None):
return MyOOBTreeItems(OOBTree.keys(min, max))
class MyOOBTreeItems(object):
__slots__ = ['__items']
def __init__(self, items):
self.__items = items
def __getitem__(self, index):
return self.__items[index]
def __getslice__(self, start, end):
return self.__items[start:end]
def __len__(self):
return len(self.__items)
def __nonzero__(self):
return self.__items.__nonzero__
def sort(self):
# XXX log deprecation warning
pass
--
Steve Alexander