Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8334419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:20:44+00:00 2026-06-09T03:20:44+00:00

I am writing a Linux kernel module and I need to come up with

  • 0

I am writing a Linux kernel module and I need to come up with a hashing function that takes two integers for input. Because the code runs in kernel space, none of the standard libraries are available to me.

Basically, I need a hashing function where:

hash(a, b) = c
hash(b, a) = c

Where acceptable inputs for a and b are unsigned 32-bit integers. The hashing function should return an unsigned 64-bit integer. Collision (i.e. hash(a, b) = c and hash(d, f) = c as well) is not desirable as these values will be used in a binary search tree. The result of the search is a linked list of possible results that is then iterated over where a and b are actually compared. So some collision is acceptable, but the less collisions, the less iterations required, and the faster it will run.

Performance is also of extreme importance, this lookup will be used for every packet received in a system as I am writing a firewall application (the integers are actually packet source and destination addresses). This function is used to lookup existing network sessions.

Thank you for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:20:46+00:00Added an answer on June 9, 2026 at 3:20 am

    Pseudocode of how you can do it:

    if a>b
      return (a << 32) | b;
    else 
      return (b << 32) | a;
    

    This satisfies hash(a,b) == hash(b,a), utilizes the full 64 bit space, and shouldn’t have collisions …I think 🙂

    Be careful to not directly shift the 32bit variables. Use intermediate 64-bit buffers or inline casts instead:

    uint64_t myhash(uint32_t a, uint32_t b)
    {
        uint64 a64 = (uint64_t) a;
        uint64 b64 = (uint64_t) b;
        return (a > b) ? ((a64 << 32) | b64) : ((b64 << 32) | a64);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a linux kernel module that needs to pin two threads on
I'm writing a linux kernel module that emulates a block device. There are various
I'm writing a linux kernel module that makes use of the exported symbol open_exec
I writing a linux kernel module that does some work with /proc... I'm trying
I'm writing a Linux kernel module that needs to open and read files. What's
I'm writing a linux kernel module that provides a (virtual) block device (so no
I am writing a code for linux kernel module and experiencing a strange behavior
I'm writing a Linux kernel module, and I'd like to allocate an executable page.
I'm taking my first crack at writing some linux kernel code, and I'm hitting
I am writing a Linux kernel module. It is released with all the source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.