Skip to content
/ bitter Public

Compact/succinct representations for vectors and arrays

License

Notifications You must be signed in to change notification settings

ocsmit/bitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

40 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

bitter

Compact/succinct representations for vectors and arrays

BitArray

Compact bit arrays are space effecient representation of the classical array as described in "Compact Data Structures, a practical approach" and its extensive bibliography.

Arrays are stored in a compact form by using only the bits needed for each element. E.g. below the array A is shown to be stored using only two uint32 elements (W). From the compact representation, the values from the original array (A) can be read, written, and operated on.

     β”Œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”
  A  β”‚  20  β”‚  18  β”‚  22  β”‚  22  β”‚  16  β”‚  21  β”‚  11  β”‚  22  β”‚  21  β”‚  21  β”‚
     β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜
         β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚
         β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚
         β–Ό      β–Ό      β–Ό      β–Ό      β–Ό      β–Ό      β–Ό      β–Ό      β–Ό      β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”
  B  β”‚10100 β”‚10010 β”‚10110 β”‚10110 β”‚10000 β”‚10101 β”‚01011 β”‚10110 β”‚10101 β”‚10101 β”‚ 
     β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜
         β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚
         β”‚      β”‚      β”‚  B is a virtual bit array β”‚      β”‚      β”‚      β”‚
         β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚      β”‚
         β–Ό      β–Ό      β–Ό      β–Ό      β–Ό      β–Ό      β–Ό      β–Ό      β–Ό      β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  B  β”‚10100  10010  10110  10110  10000  10101  01011  10110  10101  10101 β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β”‚                                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚   The bits are reordered to provide          β”‚                        β”‚
  β”‚   0 based indexing from W                 β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”               β”‚
  β”‚                                       MSB β”‚ 010 β”‚ 11  β”‚ LSB           β”‚
  β”‚                                           β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜               β”‚
  β”‚                                               A[6] β”‚                  β”‚
  β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
  β–Ό  β”Œ β”Ό ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─│─ ┐
       β–Ό                                                                  β–Ό
  W  β”‚11  10101  10000  10110  10110  10010  10100 β”‚10101  10101  10110  010 β”‚
      ^^                                                                 ^^^
     β”” ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ β”΄ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ β”˜
      A[6]                  β”‚                 A[0]   A[9]       β”‚        A[6]
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                   β”‚
            β”‚            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β–Ό            β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  W  β”‚ 3943389780 β”‚   177586   β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

It is key to note that the values of A are stored lowest significant first. The same is true for entries which span multiple words. E.g. A[6] in the above visual is split with the 2 lowest sig bits in word 1, and the three highest sig bits in word 2. In word 1 the lowest sig bits of A[6] will be the last bits accessed, while in word 2 the highest sig bits of A[6] will be accessed first.

for implementation and operation details see:

About

Compact/succinct representations for vectors and arrays

Resources

License

Stars

Watchers

Forks