コード例 #1
0
def generation_mode(file_in, num, seed, file_del=None):
    words = synthetic.words(file_in, num, seed)

    size = input("How many lists should be in the hashmap?: ")
    try:
        size = int(size)
    except ValueError as e:
        print("ERROR: Invalid value was passed to the program.\n", e)
        return -1

    hash_table = HashTable(size)
    begin = time.perf_counter()
    hash_table.add_all(words)
    end = time.perf_counter()
    print("Adding time [s]: {:.6f}".format(end - begin))

    begin = time.perf_counter()
    for word in words:
        hash_table.find(word)
    end = time.perf_counter()
    print("Enumerating time [s]: {:.6f}".format(end - begin))

    if file_del is not None:
        words = synthetic.read_file(file_del)
    begin = time.perf_counter()
    for word in words:
        hash_table.delete_all(word)
    end = time.perf_counter()
    print("Deleting time [s]: {:.6f}".format(end - begin))
コード例 #2
0
def gen_step_mode(file_in, num, seed, file_del=None):
    size = input("How many lists should be in the hashmap?: ")
    step_val = input(
        "Specify the step value (number of words generated additionally): ")
    try:
        size = int(size)
        step_val = int(step_val)
    except ValueError as e:
        print("ERROR: Invalid value was passed to the program.\n", e)
        return -1

    words_num = 0
    results = []
    while True:
        words_num += step_val
        if words_num > num:
            break
        print(words_num, " words")
        results.append(words_num)
        words = synthetic.words(file_in, words_num, seed)

        hash_table = HashTable(size)
        begin = time.perf_counter()
        hash_table.add_all(words)
        end = time.perf_counter()
        print("Adding time [s]: {:.6f}".format(end - begin))
        results.append(end - begin)

        begin = time.perf_counter()
        for word in words:
            hash_table.find(word)
        end = time.perf_counter()
        print("Enumerating time [s]: {:.6f}".format(end - begin))
        results.append(end - begin)

        if file_del is not None:
            words = synthetic.read_file(file_del)
        begin = time.perf_counter()
        for word in words:
            hash_table.delete_first(word)
        end = time.perf_counter()
        print("Deleting time [s]: {:.6f}".format(end - begin))
        results.append(end - begin)

    analyse_data(results, num, size)
コード例 #3
0
def words_ready_mode(file_in, file_del=None):
    words = synthetic.read_file(file_in)
    print(words)

    size = input("How many lists should be in the hashmap?: ")
    try:
        size = int(size)
    except ValueError as e:
        print("ERROR: Invalid value was passed to the program.\n", e)
        return -1

    hash_table = HashTable(size)
    hash_table.add_all(words)
    for arr in hash_table.array:
        print(arr)

    if file_del is not None:
        words = synthetic.read_file(file_del)
    for word in words:
        hash_table.delete_all(word)

    for arr in hash_table.array:
        print(arr)