mirror of https://github.com/mahmoud/boltons.git
more progress
This commit is contained in:
parent
f5301eb867
commit
2a63a3dbbf
|
@ -5,7 +5,7 @@ from itertools import chain, islice
|
|||
from collections import MutableSet
|
||||
|
||||
_MISSING = object()
|
||||
_COMPACTION_FACTOR = 20
|
||||
_COMPACTION_FACTOR = 50
|
||||
|
||||
# TODO: inherit from set()
|
||||
# TODO: .discard_many(), .remove_many()
|
||||
|
@ -343,15 +343,21 @@ if __name__ == '__main__':
|
|||
#print thou
|
||||
|
||||
from os import urandom
|
||||
import time
|
||||
big_set = IndexedSet(range(100000))
|
||||
rands = [ord(r) for r in urandom(len(big_set))]
|
||||
start_time, start_size = time.time(), len(big_set)
|
||||
while len(rands) > 10000:
|
||||
if len(big_set) % 300 == 0:
|
||||
print len(big_set),
|
||||
print len(big_set.dead_indices),
|
||||
if len(big_set) % 3000 == 0:
|
||||
print
|
||||
print len(big_set.dead_indices)
|
||||
print len(big_set)
|
||||
big_set.pop(rands.pop())
|
||||
end_time, end_size = time.time(), len(big_set)
|
||||
print
|
||||
print 'popped %s items in %s seconds' % (start_size - end_size,
|
||||
end_time - start_time)
|
||||
except Exception as e:
|
||||
import pdb;pdb.post_mortem()
|
||||
raise
|
||||
|
|
|
@ -76,7 +76,7 @@ class Tree(object):
|
|||
#if height == node[3]:
|
||||
# # if we have not changed heights, we're done rotating
|
||||
# return
|
||||
print 'i: %s, height: %s, new height: %s' % (i, node[3], height)
|
||||
#print 'i: %s, height: %s, new height: %s' % (i, node[3], height)
|
||||
node[3] = height
|
||||
while 1:
|
||||
balance = (node[1] and node[1][3] or 0) - (node[2] and node[2][3] or 0)
|
||||
|
@ -86,16 +86,26 @@ class Tree(object):
|
|||
side, other_side = (balance < 0) + 1, (balance > 0) + 1
|
||||
child = node[side]
|
||||
cbal = (child[1] and child[1][3] or 0) - (child[2] and child[2][3] or 0)
|
||||
#print balance, cbal
|
||||
|
||||
if (rel_side * cbal) < 0:
|
||||
print ['', 'left', 'right'][side]
|
||||
grandchild = child[other_side]
|
||||
node[side] = grandchild
|
||||
child[other_side] = grandchild[side]
|
||||
grandchild[side] = child
|
||||
gc = grandchild
|
||||
gc[3] = max(0, gc[1] and gc[1][3], gc[2] and gc[2][3]) + 1
|
||||
#gc = grandchild
|
||||
#gc[3] = max(0, gc[1] and gc[1][3], gc[2] and gc[2][3]) + 1
|
||||
child[3] = max(0, child[1] and child[1][3], child[2] and child[2][3]) + 1
|
||||
child = node[side] # we're done with the old child
|
||||
|
||||
#for k, v in locals().items():
|
||||
# try:
|
||||
# if v[0] == 91 and k != 'v':
|
||||
# import pdb;pdb.set_trace()
|
||||
# except (TypeError, IndexError):
|
||||
# pass
|
||||
|
||||
if i == 0:
|
||||
self.root = child
|
||||
else:
|
||||
|
@ -142,7 +152,7 @@ class Tree(object):
|
|||
return self.node_count
|
||||
|
||||
|
||||
def test():
|
||||
def general_test():
|
||||
import os
|
||||
vals = [ord(x) for x in os.urandom(2048)]
|
||||
#vals = range(2048)
|
||||
|
@ -167,13 +177,31 @@ def test():
|
|||
print len(vals), len(treed_vals)
|
||||
return sorted(vals) == sorted_vals
|
||||
|
||||
|
||||
def drop_test():
|
||||
cur_state = [156,
|
||||
[45,
|
||||
[20, None, None, 1],
|
||||
[148,
|
||||
[91, None, None, 1], None, 2], 3],
|
||||
[212,
|
||||
[159, None, None, 1],
|
||||
[240, None, None, 1], 2], 4]
|
||||
tree = Tree()
|
||||
tree.root = cur_state
|
||||
tree.node_count = 8
|
||||
assert len(list(tree)) == len(tree)
|
||||
tree.insert(136)
|
||||
return len(list(tree)) == len(tree) == 9
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import signal, pdb
|
||||
def pdb_int_handler(sig, frame):
|
||||
pdb.set_trace()
|
||||
signal.signal(signal.SIGINT, pdb_int_handler)
|
||||
try:
|
||||
res = test()
|
||||
res = drop_test()
|
||||
except:
|
||||
import pdb;pdb.post_mortem()
|
||||
raise
|
||||
|
@ -185,7 +213,7 @@ if __name__ == '__main__':
|
|||
|
||||
|
||||
"""
|
||||
[156, [45, [20, None, None, 1], [148, [91, None, None, 1], None, 2], 3], [212, [159, None, None, 1], [240, None, None, 1], 2], 4]
|
||||
|
||||
|
||||
+ 136
|
||||
|
||||
|
|
Loading…
Reference in New Issue