Commit 825bcee4 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 ffb5fe72
......@@ -21,7 +21,7 @@ from Globals import Persistent, DTMLFile
from OFS.SimpleItem import SimpleItem
from BTrees.IOBTree import IOBTree
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 zope.interface import implements
......@@ -165,6 +165,12 @@ class PathIndex(Persistent, SimpleItem):
else:
level = int(path[1])
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('/'))
......@@ -172,22 +178,9 @@ class PathIndex(Persistent, SimpleItem):
return IISet(self._unindex.keys())
results = None
if level >= 0:
for i, comp in enumerate(comps):
if not self._index.has_key(comp): return IISet()
if not self._index[comp].has_key(level+i): return IISet()
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)
for i, comp in enumerate(comps):
if not self._index.get(comp, {}).has_key(level+i): return IISet()
results = intersection(results, self._index[comp][level+i])
return results
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