We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
It would be useful for hash maps (structural keys) and efficient comparisons (due to shadow classes)
Code example:
import { equals, hash } from "@deepkit/type"; type User = { id: number; name: string; }; type Organization = { boss: User; }; // use cases equals<User>({ id: 1, name: "bob" }, { id: 2, name: "alice" }); // false hash<User>({ id: 3, name: "john" }); // 45 hash<User>( { id: 3, name: "john" }, { create: () => require("crypto").createHash("sha256"), update: (state, data) => state.update(data), digest: (state) => state.digest("hex"), } ); // example of generated code function equalsUser(a: User, b: User): boolean { return a.id === b.id && a.name === b.name; } type HashFunction<State, Output> = { create(): State; update(state: State, data: unknown): void; digest(state: State): Output; }; function hashUser<State, Output>( user: User, hashFunction: HashFunction<State, Output> = defaultHashFunction, [state, isRoot] = [hashFunction.create(), true] ) { hashFunction.update(state, user.id); hashFunction.update(state, user.name); if (isRoot) return hashFunction.digest(state); } function hashOrganization<State, Output>( organization: Organization, hashFunction: HashFunction<State, Output> = defaultHashFunction, [state, isRoot] = [hashFunction.create(), true] ) { hashUser(organization.boss, hashFunction, [state, false]) if (isRoot) return hashFunction.digest(state); }
The text was updated successfully, but these errors were encountered:
If you find it useful i can try to write a pull request
Sorry, something went wrong.
@freddi301 cool idea! If we can get it very fast, we could replace the primary key hashing of the ORM https://github.com/deepkit/deepkit-framework/blob/master/packages/type/src/snapshot.ts#L153-L159
If you want to create a PR that would be cool
No branches or pull requests
It would be useful for hash maps (structural keys) and efficient comparisons (due to shadow classes)
Code example:
The text was updated successfully, but these errors were encountered: