Commit 013aad15 authored by Martijn Pieters's avatar Martijn Pieters

Port improvements from ExtendedPathIndex:

- The level < 0 case is basically the union of all searches for levels 0
  through to max. Just call search() for each level and use multiunion on all
  the results.
- Shorten the 'no-such-path' detection to one test.
parent 1a1ce70c
...@@ -21,7 +21,7 @@ from Globals import Persistent, DTMLFile ...@@ -21,7 +21,7 @@ from Globals import Persistent, DTMLFile
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from BTrees.IOBTree import IOBTree from BTrees.IOBTree import IOBTree
from BTrees.OOBTree import OOBTree from BTrees.OOBTree import OOBTree
from BTrees.IIBTree import IITreeSet, IISet, intersection, union from BTrees.IIBTree import IITreeSet, IISet, intersection, union, multiunion
from BTrees.Length import Length from BTrees.Length import Length
from zope.interface import implements from zope.interface import implements
...@@ -169,28 +169,21 @@ class PathIndex(Persistent, SimpleItem): ...@@ -169,28 +169,21 @@ class PathIndex(Persistent, SimpleItem):
level = int(path[1]) level = int(path[1])
path = path[0] path = path[0]
if level < 0:
# Search at every level, return the union of all results
return multiunion(
[self.search(path, level)
for level in xrange(self._depth + 1)])
comps = filter(None, path.split('/')) comps = filter(None, path.split('/'))
if len(comps) == 0: if len(comps) == 0:
return IISet(self._unindex.keys()) return IISet(self._unindex.keys())
results = None results = None
if level >= 0:
for i, comp in enumerate(comps): for i, comp in enumerate(comps):
if not self._index.has_key(comp): return IISet() if not self._index.get(comp, {}).has_key(level+i): return IISet()
if not self._index[comp].has_key(level+i): return IISet()
results = intersection(results, self._index[comp][level+i]) results = intersection(results, self._index[comp][level+i])
else:
for level in range(self._depth + 1):
ids = None
for i, comp in enumerate(comps):
try:
ids = intersection(ids, self._index[comp][level+i])
except KeyError:
break
else:
results = union(results, ids)
return results return results
def numObjects(self): def numObjects(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment