Commit be6ca14c authored by Julien Muchembled's avatar Julien Muchembled

wip

parent dc8eeb8c
...@@ -118,29 +118,33 @@ class OidArray(object): ...@@ -118,29 +118,33 @@ class OidArray(object):
__slots__ = 'arrays', __slots__ = 'arrays',
def __init__(self, arrays): def __init__(self, arrays):
self.arrays = arrays a = self.arrays = defaultdict(array32u)
for k, v in arrays:
if v:
a[k] = v
def __iand__(self, other): def __iand__(self, other):
arrays = self.arrays arrays = self.arrays
other = other.arrays other = other.arrays
for i, a in enumerate(arrays): for i in sorted(arrays):
a = set(a) a = set(arrays[i])
try: a.intersection_update(other.get(i, ()))
a.intersection_update(other[i]) if a:
except IndexError: arrays[i] = array32u(sorted(a))
del arrays[i:] else:
break del arrays[i]
arrays[i] = array32u(sorted(a))
return self return self
def __nonzero__(self): def __nonzero__(self):
return any(self.arrays) return any(self.arrays.itervalues())
def __len__(self): def __len__(self):
return sum(map(len, self.arrays)) return sum(map(len, self.arrays.itervalues()))
def __iter__(self): def __iter__(self):
for i, x in enumerate(self.arrays): arrays = self.arrays
for i in sorted(arrays):
x = arrays[i]
i <<= 32 i <<= 32
for x in x: for x in x:
yield p64(i | x) yield p64(i | x)
...@@ -148,24 +152,19 @@ class OidArray(object): ...@@ -148,24 +152,19 @@ class OidArray(object):
def __delitem__(self, key): def __delitem__(self, key):
assert None is key.start is key.step, key assert None is key.start is key.step, key
n = key.stop n = key.stop
for x in self.arrays: arrays = self.arrays
for i in sorted(arrays):
x = arrays[i]
k = len(x) k = len(x)
del x[:n] if n < k:
n -= k del x[:n]
if n <= 0:
break break
n -= k
del arrays[i]
def append(self, oid): def append(self, oid):
oid = u64(oid) oid = u64(oid)
i = oid >> 32 self.arrays[oid >> 32].append(oid & 0xFFFFFFFF)
oid &= 0xFFFFFFFF
arrays = self.arrays
while True:
try:
arrays[i].append(oid)
break
except IndexError:
arrays.append(array32u())
class Object(object): class Object(object):
...@@ -399,13 +398,14 @@ class Changeset(object): ...@@ -399,13 +398,14 @@ class Changeset(object):
try: try:
oid = stack.pop() oid = stack.pop()
except IndexError: except IndexError:
x, = q('SELECT MAX(oid) >> 32 FROM t').fetchone() (k, x), = q(
return OidArray([ 'SELECT MIN(oid) >> 32, MAX(oid) >> 32 FROM t')
array32u(x for x, in q( return OidArray(() if k is None else ((k,
array32u(v for v, in q(
'SELECT oid & 0xFFFFFFFF FROM t' 'SELECT oid & 0xFFFFFFFF FROM t'
' WHERE oid>=? AND oid<? ORDER BY oid', ' WHERE oid>=? AND oid<? ORDER BY oid',
(x << 32, x+1 << 32))) (k << 32, k+1 << 32))))
for x in xrange(x + 1)]) for k in xrange(k, x + 1)))
k = oid, k = oid,
try: try:
(v,), = q('SELECT referents FROM t WHERE oid=?', k) (v,), = q('SELECT referents FROM t WHERE oid=?', k)
......
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