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

  • Home
  • SEARCH
  • 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 6690045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:35:27+00:00 2026-05-26T05:35:27+00:00

I want to create a Hash Map (or another structure, if you have any

  • 0

I want to create a Hash Map (or another structure, if you have any suggestions) to store key value pairs. The keys will all be inserted at once at the same time as the map is created, but I don’t know what the keys will be (arbitrary length strings) until runtime, when I need to create the map.

I am parsing a query string like this "x=100&name=bob&color=red&y=150" (but the string can have an unlimited number of variables and the variables can have any length name).

I want to parse it once and create a Hash Map, preferably minimal and with a perfect hash function to satisfy linear storage requirements. Once the map is created the values won’t be modified or deleted, no more key value pairs will be added to the map either, so the entire map is effectively a constant. I’m assuming that a variable doesn’t occur twice in the string (IE. "x=1&x=2" is not valid).

I am coding in C, and currently have a function that I can use like get("x") which will return the string "100", but it parses the query string each time which takes O(n) time. I’d like to parse it once when it is first loaded since it is a very large query string and every value will be read several times. Even though I’m using C, I don’t need code in C as an answer. Pseudocode, or any suggestions at all would be awesome!

  • 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-26T05:35:27+00:00Added an answer on May 26, 2026 at 5:35 am

    Try GPL’d gperf, or Bob Jenkins’ public domain implementation in C

    Procedure:

    • receive query string and identify domain of perfect hash function by enumerating the list of keys

    • provide these keys and list size (the range will be 1..size) to the perfect hash generation function derived from above reference implementations

    • Use the perfect hash function generated to create the HashMap

    • Use the same perfect hash function to process the get requests in the HashMap

    Edit Necrolis noted in the comment below that the reference implementations output perfect hash functions in C source code, so you’ll need to modify them to generate something like a bytecode for a VM instead. You could also use an interpretative language like embedded Scheme or Lua.

    It would be interesting to know if this is worth the effort over a simple (non-perfect) HashMap when the overhead of creating the perfect hash function is amortized over the lookups

    Another option is Cuckoo hashing which also has O(1) lookups

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

Sidebar

Related Questions

i want create image animation , i have 50 images with png format now
If I have a Map like this: HashMap<Integer, ComparableObject> map; and I want to
I have these classes that I use to create objects that I want to
I want to serialize a hash map to a file and de-serialize it later
I want to compare two Java Map s by a simple hash. Each object
I have a Rails controller with a create method, and I want to POST
I have a problem. I want to create a search engine which is based
I want create a drop shadow around the canvas component in flex. Technically speaking
I want create a excel with Apache POI in java and I must insert
I want to create a Java application bundle for Mac without using Mac. According

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.