mercredi 2 septembre 2020

If Statement For A Set of Elements (Bloom Filter)

I am trying to create an if statement to see if an element has a chance of being in the elements, but it does not print the statement when I run the code. What changes do I need to make in order for it to run properly?

def validate_bloom_filter(infile, item, num_of_digits):
"""Checks if an item exists in a set of indices for a bloom filter"""
# Create Spark Context
sc = create_spark_context()

# Get the index value to check for the four hash functions we are using
index_md5    = int(hashlib.md5(item.encode("utf-8")).hexdigest(),16) % (10 ** num_of_digits)
index_sha224 = int(hashlib.sha224(item.encode("utf-8")).hexdigest(),16) % (10 ** num_of_digits)
index_sha256 = int(hashlib.sha256(item.encode("utf-8")).hexdigest(),16) % (10 ** num_of_digits)
index_sha512 = int(hashlib.sha512(item.encode("utf-8")).hexdigest(),16) % (10 ** num_of_digits)

# TODO: FILL OUT RIGHT HAND SIDE: read the file with the Bloom filter indices previously created
bloom_filter_indices = open("out_fname","r")

# Get the indices for each of the hash functions
is_index1 = bloom_filter_indices.filter(lambda x: int(x) == index_md5).count() > 0
is_index2 = bloom_filter_indices.filter(lambda x: int(x) == index_sha224).count() > 0
is_index3 = bloom_filter_indices.filter(lambda x: int(x) == index_sha256).count() > 0
is_index4 = bloom_filter_indices.filter(lambda x: int(x) == index_sha512).count() > 0

# Get logical AND of all index existance flags

is_element_there = str(raw_input('Is element there? Enter Element is possibly in the set of elements 
if is_element_there or Element is definitely not in the set of elements if else'))

# Print message with results depending on indices
if is_element_there:
    print("Element ", item, "is possibly in the set of elements.")
else:
    print("Element ", item, "is definitely not in the set of elements")
sc.stop()

Aucun commentaire:

Enregistrer un commentaire