[Checkins] SVN: zc.catalog/trunk/src/zc/catalog/ Persist the flavor
of BTrees we use during instantiation, so that
Albertas Agejevas
alga at pov.lt
Fri Feb 2 16:02:15 EST 2007
Log message for revision 72336:
Persist the flavor of BTrees we use during instantiation, so that
changing the configuration could not break existing instances.
Changed:
U zc.catalog/trunk/src/zc/catalog/extentcatalog.py
U zc.catalog/trunk/src/zc/catalog/index.py
-=-
Modified: zc.catalog/trunk/src/zc/catalog/extentcatalog.py
===================================================================
--- zc.catalog/trunk/src/zc/catalog/extentcatalog.py 2007-02-02 20:56:08 UTC (rev 72335)
+++ zc.catalog/trunk/src/zc/catalog/extentcatalog.py 2007-02-02 21:02:15 UTC (rev 72336)
@@ -32,21 +32,22 @@
interface.implements(interfaces.IFilterExtent)
__parent__ = None
+ # The [IL]FBTree utilities of the flavor we need
+ _weightedUnion = IFBTree.weightedUnion
+ _weightedIntersection = IFBTree.weightedIntersection
+ _difference = IFBTree.difference
+
def __init__(self, filter):
treeset = zope.component.queryUtility(IFactory, name='IFTreeSet',
default=IFBTree.IFTreeSet)
self.set = treeset()
+ myIFBTree = zope.component.queryUtility(IMerge, name='IFBTree',
+ default=IFBTree)
+ self._weightedUnion = myIFBTree.weightedUnion
+ self._weightedIntersection = myIFBTree.weightedIntersection
+ self._difference = myIFBTree.difference
self.filter = filter
- @property
- def IFBTree(self):
- """Get the [IL]BTree module of the correct flavor.
-
- Used for set operations.
- """
- return zope.component.queryUtility(IMerge, name='IFBTree',
- default=IFBTree)
-
def addable(self, uid, obj):
return self.filter(self, uid, obj)
@@ -60,7 +61,7 @@
__ror__ = __or__
def union(self, other, self_weight=1, other_weight=1):
- return self.IFBTree.weightedUnion(
+ return self._weightedUnion(
self.set, other, self_weight, other_weight)[1]
def __and__(self, other):
@@ -70,7 +71,7 @@
__rand__ = __and__
def intersection(self, other, self_weight=1, other_weight=1):
- return self.IFBTree.weightedIntersection(
+ return self._weightedIntersection(
self.set, other, self_weight, other_weight)[1]
def __sub__(self, other):
@@ -78,14 +79,14 @@
return self.difference(other)
def difference(self, other):
- return self.IFBTree.difference(self.set, other)
+ return self._difference(self.set, other)
def __rsub__(self, other):
"set - extent"
return self.rdifference(other)
def rdifference(self, other):
- return self.IFBTree.difference(other, self.set)
+ return self._difference(other, self.set)
def __iter__(self):
return iter(self.set)
Modified: zc.catalog/trunk/src/zc/catalog/index.py
===================================================================
--- zc.catalog/trunk/src/zc/catalog/index.py 2007-02-02 20:56:08 UTC (rev 72335)
+++ zc.catalog/trunk/src/zc/catalog/index.py 2007-02-02 21:02:15 UTC (rev 72336)
@@ -40,36 +40,40 @@
zc.catalog.interfaces.IIndexValues,
)
+ # The [IL]FBTree utilities of the flavor we need
+ _multiunion = IFBTree.multiunion
+ _weightedUnion = IFBTree.weightedUnion
+ _intersection = IFBTree.intersection
+
+ # BTree components of the flavor we need
+ IFTreeSet = IFBTree.IFTreeSet
+ IFSet = IFBTree.IFSet
+ IFBucket = IFBTree.IFBucket
+
def __init__(self):
self.clear()
+ self.IFTreeSet = component.queryUtility(
+ zope.component.interfaces.IFactory,
+ name='IFTreeSet',
+ default=IFBTree.IFTreeSet)
+ self.IFSet = component.queryUtility(
+ zope.component.interfaces.IFactory,
+ name='IFSet',
+ default=IFBTree.IFSet)
+ self.IFBucket = component.queryUtility(
+ zope.component.interfaces.IFactory,
+ name='IFBucket',
+ default=IFBTree.IFBucket)
- @property
- def IFBTree(self):
- """Get the [IL]FBTree module of the flavour we're using"""
- return component.queryUtility(IMerge, name='IFBTree',
- default=IFBTree)
+ myIFBTree = component.queryUtility(
+ IMerge,
+ name='IFBTree',
+ default=IFBTree)
- @property
- def IFTreeSet(self):
- """Get the [IL]FTreeSet class of the flavour we're using"""
- return component.queryUtility(zope.component.interfaces.IFactory,
- name='IFTreeSet',
- default=IFBTree.IFTreeSet)
+ self._multiunion = myIFBTree.multiunion
+ self._weightedUnion = myIFBTree.weightedUnion
+ self._intersection = myIFBTree.intersection
- @property
- def IFSet(self):
- """Get the [IL]FSet class of the flavour we're using"""
- return component.queryUtility(zope.component.interfaces.IFactory,
- name='IFSet',
- default=IFBTree.IFSet)
-
- @property
- def IFBucket(self):
- """Get the [IL]FBucket class of the flavour we're using"""
- return component.queryUtility(zope.component.interfaces.IFactory,
- name='IFBucket',
- default=IFBTree.IFBucket)
-
def clear(self):
self.values_to_documents = OOBTree.OOBTree()
self.documents_to_values = component.queryUtility(
@@ -171,7 +175,7 @@
if query_type is None:
res = None
elif query_type == 'any_of':
- res = self.IFBTree.multiunion(
+ res = self._multiunion(
[s for s in (values_to_documents.get(v) for v in query)
if s is not None])
elif query_type == 'any':
@@ -181,7 +185,7 @@
assert zc.catalog.interfaces.IExtent.providedBy(query)
res = query & self.IFSet(self.ids())
elif query_type == 'between':
- res = self.IFBTree.multiunion(
+ res = self._multiunion(
[s for s in (values_to_documents.get(v) for v in
values_to_documents.keys(*query))
if s is not None])
@@ -270,7 +274,7 @@
elif query_type == 'any_of':
res = self.IFBucket()
for v in query:
- _, res = self.IFBTree.weightedUnion(
+ _, res = self._weightedUnion(
res, values_to_documents.get(v))
elif query_type == 'any':
if query is None:
@@ -290,13 +294,12 @@
v = values.next()
except StopIteration:
break
- res = self.IFBTree.intersection(res,
- values_to_documents.get(v))
+ res = self._intersection(res, values_to_documents.get(v))
elif query_type == 'between':
res = self.IFBucket()
for v in values_to_documents.keys(*query):
- _, res = self.IFBTree.weightedUnion(res,
- values_to_documents.get(v))
+ _, res = self._weightedUnion(res,
+ values_to_documents.get(v))
elif query_type == 'none':
assert zc.catalog.interfaces.IExtent.providedBy(query)
res = query - self.IFSet(self.ids())
More information about the Checkins
mailing list