Esempio n. 1
0
def test_sortedlistHT():
    lt = sortedlistHT()

    for i in range(10, 0, -1):
        lt.put(i, random.randint(1, 100))


    print lt

    print lt.get(3)
    print lt.get(11)

    lt.remove(3)
    print lt.get(3)

    print lt
Esempio n. 2
0
def test_performance():
    nHT = NaiveHT()
    lt = listHT()
    sHT = sortedlistHT()

    keys =  [i for i in range(10000)]
    
    random.shuffle(keys)

    for key in keys:
        v = random.randint(1, 100)
        nHT.put(key, v)
        lt.put(key, v)
        sHT.put(key, v)

    now = time.time()
    
    c = 0
    random.shuffle(keys)
    while(time.time() - now < 0.1):
        nHT.get(keys[c%10000])
        c += 1
    print 'native data structure: ' + str(c)

    now = time.time()
    c = 0
    while(time.time() - now < 0.1):
        lt.get(keys[c%10000])
        c += 1
    print 'list data structure: ' + str(c)

    now = time.time()
    c = 0
    while(time.time() - now < 0.1):
        sHT.get(keys[c%10000])
        c += 1
    print 'sorted list data structure: ' + str(c)