Skip to content

Instantly share code, notes, and snippets.

@azat
Created October 27, 2024 14:47
Show Gist options
  • Save azat/8a0a94e4de2d95af8f729b709589ce12 to your computer and use it in GitHub Desktop.
Save azat/8a0a94e4de2d95af8f729b709589ce12 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import matplotlib.pyplot as plt
def hashsocket_1(fd):
return fd
def hashsocket_2(fd):
h = fd & 0xffffffff
h += (h >> 2) & 0xffffffff | (h << 30) & 0xffffffff
return h
def hashsocket_3(fd):
h = fd & 0xffffffff
h = (h >> 2) & 0xffffffff | (h << 30) & 0xffffffff
return h
n1_values = []
n2_values = []
n3_values = []
prime = 49157
for s in range(0, int(prime*1.2), 4):
h1 = hashsocket_1(s)
h2 = hashsocket_2(s)
h3 = hashsocket_3(s)
n1 = h1 % prime
n2 = h2 % prime
n3 = h3 % prime
n1_values.append(n1)
n2_values.append(n2)
n3_values.append(n3)
# Set up subplots for a clear comparison
fig, axes = plt.subplots(3, 1, figsize=(10, 12))
# Plot n1 distribution
axes[0].hist(n1_values, bins=100, color="skyblue", edgecolor="black")
axes[0].set_title("fd % prime")
axes[0].set_xlabel("Value")
axes[0].set_ylabel("Frequency")
# Plot n2 distribution
axes[1].hist(n2_values, bins=100, color="salmon", edgecolor="black")
axes[1].set_title("hashsocket orig % prime")
axes[1].set_xlabel("Value")
axes[1].set_ylabel("Frequency")
# Plot n3 distribution
axes[2].hist(n3_values, bins=100, color="lightgreen", edgecolor="black")
axes[2].set_title("hashsocket patched % prime")
axes[2].set_xlabel("Value")
axes[2].set_ylabel("Frequency")
# Adjust layout and show plot
plt.tight_layout()
plt.show()
@azat
Copy link
Author

azat commented Oct 27, 2024

hashsocket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment