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 8726951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:20:58+00:00 2026-06-13T08:20:58+00:00

I need to implement a hash table to maintain IP packets. However, due to

  • 0

I need to implement a hash table to maintain IP packets. However, due to the uniqueness of packets, I cannot make a hash key using one single element (say IP address). Following are the elements in a packet which will be responsible for making an packet unique:

  1. Source IP address (16 byte string, due to IPv6 format)
  2. Source port (2 byte)
  3. Destination ip address(16 byte again)
  4. Destination port(2 byte) 5. id1(1 byte)

I know that if there is one element to calculate hash value, it can be done using any of the known algorithm like MD5, etc. My question is, how can I include multiple elements like the above, in the process of hash value calculation?

  • 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-13T08:20:59+00:00Added an answer on June 13, 2026 at 8:20 am

    To create an effective hash; first determine which data you’re going to use for lookups. For example, if you’re going to search for all packets sent from a certain IP address then you only want to use “source IP address” (and you wouldn’t want to use source IP address and source port because that’d mean you’d have to do 65536 searches to find all packets sent from a certain IP address).

    The next step is to determine the most effective hash size. This tends to depend on the amount of data and the size of the CPU’s caches. If the hash size is too small (e.g. 8 bits) then you end up with long lists of entries for each hash (which increases time to find anything); and if the hash size is too big (e.g. 24 bits) then you get frequent cache misses when trying to find the list of entries for the hash.

    Please note that you can also have multiple levels. For example, if you want to search for the packets from a specific port and IP address; then you could use the IP address alone to create one hash table that is used to find a second hash table; and then use the port to create a different hash that is used with the second hash table.

    Once you’ve decided what information you need to use for the hash and the hash size; the next step is to determine how to calculate the hash in a way that minimises collisions. This calculation needs to be fast – you don’t want a large amount of overhead that attempts to prevent a small amount of overhead (and using something complex like MD5 would be a bad idea). Often simple methods like “XOR and shift” are fast and effective. For example, for a 16-byte IP address and 16-bit hash you might just do hash ^= (hash << 3) | next_pair_of_bytes; 8 times.

    Finally, you want to tune it. Mostly you want to adjust the hash size and try a few different hash calculations to see if it improves performance. All of the above relies on assumptions about the data and cache sizes, and these assumptions may be wrong in practice. For example, maybe most packets come from a single IP address and using the IP address in the hash is a waste of time; maybe other parts of the program are consuming lots of cache and attempting to minimise cache misses was a bad idea (and a much larger hash might improve performance); maybe there isn’t as much data as you thought and you’re not getting many hash collisions and reducing the hash size can improve performance; etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to implement a hash table and hash function using JavaScript. The goal
I need to create a hash key on my tables for uniqueness and someone
I am using std::map to implement my local hash table, which will be accessed
I need to implement the following: There is a table A which is supposed
I need to implement a one-to-one videoconferencing solution server-based, runnable by browser, free (or
I'm trying to implement a Chord distributed hash table. I want to use SHA-1
I never need to store objects in a hash table. The reason is twofold:
I've got a rather strange problem. For a Distributed Hash Table I need to
I have an assignment to design a simple spam filter using a hash table
I've implemented LRU using hashtable+linked list. The hash table has chaining. The structure for

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.