Example #1
0
def full_huff_search(tree):
    loops = 0
    to_test = deque(hs.group(tree))
    #defective = 0
    while to_test:
        #print('in here')
        loops+=1
        current = to_test.popleft()
        branch_sum = sum([t[0] for t in current])
        if branch_sum != 0:
            return loops
        else:
            l,r = hs.group(current)
            to_test.extendleft([r])
            to_test.extendleft([l])
    return 0
Example #2
0
def search_hufftree(tree):
    defective = 0
    l, r = hs.group(tree)
    if any(l):
        search_hufftree(l)
    else:
        search_hufftree(r)
    return defective
Example #3
0
def search_hufftree(items):
    defective = 0
    tree = hs.encode(items)
    l, r = hs.group(tree)

    return defective
Example #4
0
#        branch_sum = sum([t[0] for t in current_branch])
#        if branch_sum !=0 :
#            if(len(current_branch)==1):
#                defective.append(current_branch)
#                exit
#            else:
#                l,r = hs.group(current_branch)
#                to_crawl.extendleft([r])
#                to_crawl.extendleft([l])
#        loops += 1
#    return loops-len(to_crawl),defective
    
#items to search
n = 4
items = [0]*n
position = randint(0,n-1)
items[2] = 1

#probabilities
probs = [2**-(x+1) for x in range(0,n)] #[0.5, 0.25, 0.125, 0.125]# #np.random.dirichlet([1]*n)
non_iid_items = zip(items, probs)

#binary searching the items
defindex, bsloops = binary_search(items)

#huffman searching the items
t = hs.encode(non_iid_items)
hsloops = huffman_search(t)