Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polish hash function #2

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/react/src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from "react";
import { getHash, getInstance } from "sdk";
import { getInstance } from "sdk";
import styles from "./home.module.css";
import mxLogo from "/mx.svg";
import reactLogo from "/react.svg";
Expand Down Expand Up @@ -53,7 +53,6 @@ export function HomePage() {
<h3>Assignment</h3>
{JSON.stringify(assignment, null, 2)}
</div>
<div>test: {getHash("experiment-1", 2).toPrecision(10)}</div>
</div>
);
}
9 changes: 0 additions & 9 deletions packages/sdk/src/assignment/hashing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ import { stringify } from "../utils";
export function getHash(experimentKey: string, subjectKey: unknown): number {
const key = [experimentKey, stringify(subjectKey)].join();

return hash(key);
}

/**
* Hashes a string to a number between 0 and 1
* @param key - The string to hash
* @returns A hash value between 0 and 1
*/
function hash(key: string): number {
return (hashFnv32a(key) % 1000) / 1000;
}

Expand Down