def negative_find_test(): ok = True t = treap.treap() for i in xrange(0, n, 2): t[i] = i for i in xrange(1, n, 2): myut.require_exceptions(functools.partial(t.find, i), ( exceptions.LookupError, ))
def repeat_length_test(): t = treap.treap() for i in xrange(n): t[i] = i for i in xrange(n): t[i] = i myut.assertEqual(len(t), n)
def positive_find_test(): ok = True t = treap.treap() for i in xrange(0, n, 2): t[i] = i for i in xrange(0, n, 2): myut.assertEqual(t[i], i)
def iterator_test(): lst = range(n) random_lst = random_swaps(lst[:]) t = treap.treap() for x in random_lst: t[x] = x lst2 = list(t.iterator()) myut.assertTrue(lst == lst2)
def max_test(): lst = range(n) random_lst = random_swaps(lst[:]) t = treap.treap() for x in random_lst: t[x] = x least = t.find_max() myut.assertEqual(least, n-1)
def duplication_behavior_unique(): #t = treap.treap(allow_duplicates=False) t = treap.treap() t[1] = 1 t[2] = 2 t[2] = 2 t[3] = 3 myut.assertTrue(list(t) == [1, 2, 3])
def create(self, sequence): self.treap = treap.treap() for i in sequence: self.treap[i] = i self.content = [] self.treap.inorder_traversal(self.add)
def min_max_length_test(): t = treap.treap() for i in xrange(n): t[i] = 0 myut.assertEqual(len(t), n) t.remove_min() myut.assertEqual(len(t), n-1) t.remove_max() myut.assertEqual(len(t), n-2)
def __init__(self, parts, delta): self.kds = [py_treap.treap() for i in range(parts)] # we 'parts' # of kds self.tmap = bidict( ) # keeps track of the kds part with earliest event time self.smap = bidict() # keeps track of the size of the kds parts self.delta = delta for i in range(parts): self.smap.update((0, i), i) # initially all kds parts have size = 0
def del_insert_del_insert(): t = treap.treap() for i in xrange(n): t[i] = 0 for i in xrange(n): t.remove_min() for i in xrange(n): t[i] = 0 for i in xrange(n): t.remove_min()
def depth_test(): # O(n^2), so we don't use n - we use something small. # We assume very little about the resulting depths - in particular, even though this datastructure should very nearly always be log2(n) deep, we assume that # worst case behavior is possible - IE that depth can be as high as n. We also don't make any effort to show that an empty treap has a depth of 0 my_n = min(n, 100) for i in xrange(my_n): t = treap.treap() for j in xrange(i): t[j] = j myut.assertTrue(0 <= t.depth() <= i)
def remove_max_test(): # O(n^2) test! lst = range(n) t = treap.treap() for i in lst: t[i] = 0 # taking advantage of the fact that the keys are the same as our lst indices for i in lst: t.remove_max() myut.assertTrue(list(t) == lst[:-(i+1)])
def reremoval_test(): t = treap.treap() # fill the treap with 0..n for i in xrange(n): t[i] = i # remove all the odd values for i in xrange(1,n,2): del t[i] # check that we have nothing but even values left ordered_values = list(t.iterator()) for i in [ 1, 3, 7 ]: myut.require_exceptions(functools.partial(t.remove, i), ( exceptions.LookupError, ))
def removal_test(): t = treap.treap() # fill the treap with 0..n for i in xrange(n): t[i] = i # remove all the odd values for i in xrange(1,n,2): del t[i] # check that we have nothing but even values left ordered_values = list(t.iterator()) result = ordered_values == range(0, n, 2) myut.assertEqual(result, True)
def string_test(): def random_char(): return chr(97 + int(random.random() * 32)) t = treap.treap() dict = {} for i in xrange(n): strng = '%s%s' % (random_char(), random_char()) t[strng] = None dict[strng] = None lst = dict.keys() lst.sort() myut.assertTrue(list(t) == lst)
def remove_min_test(): # O(n^2) test! lst = range(n) t = treap.treap() for i in lst: t[i] = 0 # taking advantage of the fact that the keys are the same as our lst indices for i in lst: if i % (n / 5) == 0: myut.assertTrue(t.check_heap_invariant()) myut.assertTrue(t.check_tree_invariant()) t.remove_min() myut.assertTrue(list(t) == lst[i+1:])
def remove_sequence_test(reverse): t = treap.treap() lst = range(n) for item in lst: t[item] = 0 if reverse: lst.reverse() pop = t.remove_max else: pop = t.remove_min for i in xrange(len(lst)): value_from_treap = pop() myut.assertEqual((lst[i], 0), value_from_treap) myut.assertTrue(not bool(t))
def failed_removal_from_one_test(): t = treap.treap() t[5] = 5 myut.require_exceptions(functools.partial(t.remove, 10), ( exceptions.LookupError, ))
def print_test(n): t = treap.treap() for i in xrange(n): t[i] = i dummy = str(t)
def simple_length_test(): t = treap.treap() for i in xrange(n): myut.assertEqual(len(t), i) t[i] = i myut.assertEqual(len(t), n)
def empty_0_test(): t = treap.treap() myut.assertEqual(t.depth(), 0)
def removal_from_empty_test(): t = treap.treap() for i in [ 1, 3, 7 ]: myut.require_exceptions(functools.partial(t.remove, i), ( exceptions.LookupError, ))
def nonempty_test(): t = treap.treap() t[1] = 1 myut.assertTrue(bool(t) == True)
def empty_test(): t = treap.treap() myut.assertTrue(not (bool(t) == True))
def empty_max_test(): t = treap.treap() myut.require_exceptions(t.find_max, (exceptions.LookupError, ))
def successful_removal_from_one_test(): t = treap.treap() t[5] = 5 del t[5]
with open('data/completion_time.csv', 'rb') as csvfile2: csvreader2 = csv.reader(csvfile2, delimiter=' ') for row in csvreader2: time_iter.append(float(row[2])) display(dict1) allQuery = [] times = [] tperiod = 2 ###################################### Main working loop ################################################################################### for iteration in range(1832): print iteration kds = py_treap.treap() total_events = 0 current_time = 0.0 next_event = 100000.0 next_query = 100000.0 current_trajectories = [] current_lines = [] current_objects = [] #current_queries=[] object_line_map = {} isProcessed = {} ###Setting-up an overall result variable comaxrs = [] #setup the lines, trajectories, etc.
def __init__(self): self.kv = py_treap.treap() self.vk = dict()
def value_test(): t = treap.treap() for i in xrange(n): t[i] = i*3 for i in xrange(n): myut.assertEqual(t[i], i*3)
#!/usr/bin/env python import time try: import psyco except: pass else: psyco.full() import py_treap as treap import random n=100000 tick = n / 10 t = treap.treap() t0 = time.time() for i in xrange(n): if i % tick == 0: print '%5.1f%%...' % (float(i) / n * 100) t[int(random.random() * n)] = None print '%5.1f%%...' % (float(n) / n * 100) t1 = time.time() difference = t1 - t0 if difference > 20: print "Something's wrong - this usually takes about 4 to 8 seconds (on a 1795MHz Intel CPU" print "But this time it took", difference, "seconds, which is more than 20 seconds" else: print "Test passed - took", difference, "seconds"