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

Add fxhash (Rust) #69

Open
dumblob opened this issue Jul 5, 2019 · 7 comments · May be fixed by #276
Open

Add fxhash (Rust) #69

dumblob opened this issue Jul 5, 2019 · 7 comments · May be fixed by #276

Comments

@dumblob
Copy link

dumblob commented Jul 5, 2019

https://github.com/cbreeden/fxhash (yeah, it's Rust, but at some point there will anyway be a need to test other Rust hashes as they seem to be quite unique)

@rurban
Copy link
Owner

rurban commented Jul 5, 2019

Sure. Accidently I looked at this just yesterday, and saw that it's very similar to my new FNV improvement.

I don't care about Rust, just that gcc-9.1.0 is blacklisted

@rurban
Copy link
Owner

rurban commented Dec 3, 2019

It would be nice if someone does a pull request for rust based hashes like this. I'm too rusty for rust.

I recently added ASM support (for clang and gcc only, no masm), but it's not yet merged. See the aesni-sha1-x86_64 branch.

@rurban rurban changed the title Add fxhash Add fxhash (Rust) Dec 3, 2019
@sharpobject
Copy link

sharpobject commented Jun 8, 2022

Is it acceptable to use a C++ port of the Rust implementation? This hash is quite small and I recently implemented a similar hash in Zig that differs only in that it does fewer rounds for non-multiple-of-8 input sizes and assumes it can read up to 7 bytes past the end.

const Hasher = struct {
    const K: u64 = 0x517cc1b727220a95;
    hash: u64 = 0,
    pub inline fn add(self: *Hasher, i: u64) void {
        self.hash = (((self.hash << 5) | (self.hash >> 59)) ^ i) *% K;
    }

    pub inline fn write(self: *Hasher, start: [*]u8, len: u64) void {
        const end = start + len;
        var p = start;
        while (@ptrToInt(p + 8) <= @ptrToInt(end)) {
            self.add(std.mem.readIntLittle(u64, p[0..8]));
            p += 8;
        }
        if (@ptrToInt(p) < @ptrToInt(end)) {
            // for this last read,
            // the low bytes are our string and the high bytes are garbage
            const garbage_bytes = @intCast(u6, 8 - (@ptrToInt(end) - @ptrToInt(p)));
            self.add(std.mem.readIntLittle(u64, p[0..8]) << garbage_bytes * 8);
        }
    }
};

This obviously isn't useful, but I can make a more faithful C++ port if that would help.

@rurban
Copy link
Owner

rurban commented Jun 8, 2022

Sure it is.
linking to the static rust lib would be better, but we take what we get.

@tgross35
Copy link

tgross35 commented Sep 12, 2023

@rurban do you just need the following API, exposed in a staticlib?

void somehash_test(const void *key, uint32_t len, uint32_t seed, void *out);

Looking at Hashes.h it seems like some hashes set out and some do not - I am thinking that any test that doesn't set the out value may be optimized away completely, how is that handled?

I can add tests for a handful of popular Rust hashers if you can give me some pointers on what to expose

@rurban
Copy link
Owner

rurban commented Sep 12, 2023

Yes, just this is fine, as C or C++.

All hash test functions need to set out, some just do the memcpy in its finalizers, or write directly to it. It's the dest buffer we are writing to

@tgross35 tgross35 linked a pull request Sep 12, 2023 that will close this issue
@tgross35
Copy link

Thank you for the quick response, I submitted a PR to add this and others in #276. A lot of hash libraries use a common trait interface so it was pretty easy to add quite a few implementations.

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

Successfully merging a pull request may close this issue.

4 participants