Do you know a hash-function (doesn't need to be cryptographic) that I can implement, without fixed size integer-types?
I already searched for a while, but couldn't find an actual fit.

It's for implementing a hasher, used by a hashmap.

  • 2
    Without fixed size integers?
    But that would mean the hash could be of arbitrary length. Wouldn't that go against the idea of hashing algorithms?
  • 1
    Sounds like an X/Y problem, i.e. a question rooted in a wrong approach to the problem.
  • 0
    Maybe I've written it wrong.

    I want to implement it in C, without stdint.h (int64_t,...).
    Just normal int,size_t...

    My point is, that the size of those aren't guarantied by the API.
  • 2
    @metamourge Reason?
    Your compiler knows the sizes during compilation, and you can do check the sizes with #if.

    stdint.h does exactly that, and creates appropriate typedefs matching the "sized" to correct "unsized" ones.
  • 2
    @metamourge So it is an X/Y problem.

    The fixed integer sizes are guaranteed by the standard from C99 onwards. There's absolutely no reason to not use them because you'd be hard pressed to find a C compiler without C99 datatype support.

    And even if you should encounter one, you can add that header file yourself for the platform and compiler you're using because all these types actually do is encaptulating the varying int sizes via typedefs.
Add Comment