Best way to store boolean values to save memory in python

前端 未结 3 1889
闹比i
闹比i 2021-01-22 15:32

What is the best way to store between a million to 450,000 Boolean values in a dictionary like collection indexed by a long number? I need to use the least amount of memory pos

3条回答
  •  无人共我
    2021-01-22 15:58

    Have you thought about using a hybrid list/bitstring?

    Use your list to store one dimension of your bits. Each list item would hold a bitstring of fixed length. You would use your list to focus your search to the bitstring of interest, then use the bitstring to find/modify your bit of interest.

    The list should allow the most efficent recall of the bitstrings, the bitstrings should allow you to pack all your data as efficiently as possible, and the hybrid list/bitstring should allow a compromise between speed (slightly slower accessing the bit string in the list) and storage (bit packed data plus list overhead.)

提交回复
热议问题