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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:39:46+00:00 2026-05-31T09:39:46+00:00

Most applications, especially databases, can sort and filter by small integers or floats much

  • 0

Most applications, especially databases, can sort and filter by small integers or floats much faster than they can do string comparisons.

Therefore I’m wondering if there is a hashing function that I can use to return a 32bit or 64bit number of a short string (about 5 – 40 characters) so that I can compare by integer instead of by string.

I first thought of crc32, but it seems it’s much too small of a number and would result in possible collisions in less than 50,000 hashes (I need to do over a million).

I’m mostly interested in working in Python, PHP, V8 Javascript, PostgreSQL, and MySQL.

  • 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-31T09:39:48+00:00Added an answer on May 31, 2026 at 9:39 am

    The problem that collisions become likely at 50k entries is inherent in all 32 bit hashes. If you read a bit on the Birthday problem you’ll see that collisions become likely if you have around sqrt(HashSpace) elements, e.g. sqrt(2^32) = 64k for 32 bit hashes.


    With 64 bit hashes collisions become much rarer. But I still don’t feel too comfortable betting the correctness of my program on that.

    Using an approximation from wikipedia:

    We obtain a probability of 3*10-8 for 1 million elements, and 3*10-6 for 10 million elements.

    You could use CRC64 for that. Or just truncate a crypto hash, such as md5 or sha1 to the desired length.


    If a malicious person can choose the strings, breaking your program by deliberately creating collisions, you should at least switch to a keyed hash, such as HMAC.


    Depending on what you’re doing, you could also simply create an in-memory mapping between string and int where you simply increment a counter for each element you encounter. This gives you a perfect mapping without risk for collisions, but is only applicable in some scenarios.

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

Sidebar

Related Questions

Most web applications have a Location field, in which uses may enter a Location
Most web applications depend on some kind of session with the user (for instance,
Historically I've been completely against using ORMS for all but the most basics applications.
I tend to use a StatusStrip at the bottom of most of my applications
I have an application that is database intensive. Most of the applications methods are
How do most people handle updating ASP.NET applications running in a webfarm? I am
When writing multi-threaded applications, one of the most common problems experienced are deadlocks. My
When writing multithreaded applications, one of the most common problems experienced is race conditions.
What things should be kept most in mind when writing cross-platform applications in C?
I create business applications with heavy database use. Most of the programming work is

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.