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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:59:38+00:00 2026-05-26T15:59:38+00:00

I have a dict from some hash key to a bitstring. The bitstring can

  • 0

I have a dict from some hash key to a bitstring. The bitstring can be variable length, but are generally < 160 bits and usually <80. I have about 80M key value pairs.

How can I store this data structure in as little memory as possible? I don’t want to pad the bitstrings, or I will lose quite a bit of space (no pun intended).

I assume that I will have to store a byte at the beginning giving the length of the bit string. That’s okay.

What is the most memory-efficient way to store this dict in memory?

I would prefer to use Python, but am open to other choices.

  • 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-26T15:59:39+00:00Added an answer on May 26, 2026 at 3:59 pm

    If you’re referring to padding the bitstrings to an integral number of bytes, then you could store the concatenation of all the initial bitstrings in a single bitstring, and keep a dictionary whose values are tuples of the form (bit position, length).

    Problem is, if I did the math right, then the length of this larger bitstring can be over 12 billion bits, so the bit position would be need a couple of bits over an int. Then if you need to pad the bit position itself we’re back to square one.

    If, however, the number of distinct lengths is < 64, you could fit the length field in 6 bits, and you end up with a dictionary mapping hash keys to 5-byte tuples indexing into the single bitstring. Would this work for you?

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

Sidebar

Related Questions

In several places I have to retrieve some value from a dict, but need
I have a dict, which I need to pass key/values as keyword arguments.. For
Let's say that I have class , that uses some functionality of dict .
Here is an example bit from the xml file: <array> <dict> <key>Name</key> <string>Joe Smith</string>
I have a class that inherits from a dictionary in order to add some
I have subclass that inherits from a dict. On __getitem__ method I'd like to
I have some problem converting my data from an plist to objects. The plist
I have a dict, that looks like this: { 'foo': { 'opt1': 1, 'opt2':
I have a dict object. I dumped the data using this: for alldata in
I have an versioned document store which I want to access through an dict

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.