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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:07:39+00:00 2026-05-23T08:07:39+00:00

Given a number, how can I create a unique key from that number. This

  • 0

Given a number, how can I create a unique key from that number. This key should never be repeated when given different number. and when the same number is provided it should give back the same key that it generated earlier, i need this in my application. pls can you suggest any algorithm

Edited : sorry guys i changed the Q when you guys were answering the Q i thought the above Q be a better way of asking, my Q is in my B-tree i am storing the ipaddress (src ip and dst ip) of ipv4 i am generating the key for that using the destination ip, for eg: if i have a address 172.28.6.100 i generate a key using the last two bytes as 600 (6*100) now i have to store even the ipv6 address how can i generate a key for that i need to generate a uniqe key for each address.

  • 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-05-23T08:07:40+00:00Added an answer on May 23, 2026 at 8:07 am

    Your algorithm (from the original question, where you stated you were generating a key c*d from the IP address a.b.c.d) doesn’t even guarantee uniqueness for your IPv4 addresses. 172.28.6.12 will have an identical key to 172.28.12.6 and 9.45.3.24 and 10.1.72.1 (among others).

    That is an inevitable outcome of hashing where you map many items to one key.

    My question is: why are you hashing. You can fit an IPv4 address into four bytes and an Ipv6 one into sixteen bytes. They’re not so large that you couldn’t use the entire address as the key, surely?

    And, even if they are too large, if your requirement is to be unique across the entire allowable range of IP addresses, you may have to do that anyway. The only way to guarantee uniqueness is to limit the input values somehow.


    Since you’ve changed your question to remove the specifics, I’ll add this addendum. The reasoning behind my answer doesn’t change.

    If you’re hashing data to generate keys, there are only two ways to guarantee uniqueness of the keys:

    • use the same number of bits for the key as you do for the data; or
    • limit the data somehow.

    The first of those buys you very little. It’s sometimes useful to map sparse data to contiguous indexes for efficient lookups but will not save you any space.

    The second is often used where you know the data will be limited such as (1) all your IP addresses start with 10.1 or they’re all integers between 1000 and 1099.

    But, unless you choose one of those limitations, there’s no way to guarantee there won’t be a key collision.

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

Sidebar

Related Questions

How can I check if a given number is even or odd in C?
Via jquery / Javascript Given a number 1234567891234 How can I concat, or truncast
How can I rotate an Bitmap a given number of degrees while maintaining the
How can I find the least prime number greater than a given number? For
Can anyone tell me how to format a given number of seconds (for example
Given a date how can I add a number of days to it, but
i need an sms service that can gives me a phone number and then
Please help me model this in SQLAlchemy. A user can create a question. A
In Java you can give the number zero as a single parameter for the
Can u give me a simple function in vb.net which can take number of

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.