From fefb795f80cea54764948e29692aaa7ecf4afa32 Mon Sep 17 00:00:00 2001 From: Student Date: Tue, 9 Sep 2025 09:24:01 +0530 Subject: [PATCH] updated lab5 and 6 --- IS/Lab/Lab5/customhash.py | 2 +- IS/Lab/Lab5/hashbench.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/IS/Lab/Lab5/customhash.py b/IS/Lab/Lab5/customhash.py index be7dc93..622fb9f 100644 --- a/IS/Lab/Lab5/customhash.py +++ b/IS/Lab/Lab5/customhash.py @@ -12,7 +12,7 @@ def hash_gen(s: str, h: int, mult: int): cur ^= (cur >> 16) cur = (cur * 0x85ebca6b) & MASK32 cur ^= (cur >> 13) - print(f"String: {s!r} Hash: {cur:#010x}") + print(f"Hash: {cur:#010x}") h = cur time.sleep(2) except KeyboardInterrupt: diff --git a/IS/Lab/Lab5/hashbench.py b/IS/Lab/Lab5/hashbench.py index da6844d..708f806 100644 --- a/IS/Lab/Lab5/hashbench.py +++ b/IS/Lab/Lab5/hashbench.py @@ -7,12 +7,12 @@ def ds_gen(dsize): """Generate random strings dataset""" dataset = [] for _ in range(dsize): - length = random.randint(10, 50) + length = random.randint(500000, 1000000) random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=length)) dataset.append(random_string) return dataset -def hash_benchmark(dataset, hash_func, hash_name): +def hash_benchmark(dataset, hash_func): """Benchmark hashing function and detect collisions""" start_time = time.time() hashes = {} @@ -43,7 +43,7 @@ def main(): print(f"Testing with {len(dataset)} strings\n") for hash_func, name in hash_functions: - time_taken, collision_count, collisions = hash_benchmark(dataset, hash_func, name) + time_taken, collision_count, collisions = hash_benchmark(dataset, hash_func) print(f"{name}:") print(f" Time: {time_taken:.6f} seconds") print(f" Collisions: {collision_count}")