BoundSerializedSizeInBytes returns an upper bound on the serialized size in bytes assuming that one wants to store "cardinality" integers in [0, universe_size)
(cardinality uint64, universeSize uint64)
| 490 | // BoundSerializedSizeInBytes returns an upper bound on the serialized size in bytes |
| 491 | // assuming that one wants to store "cardinality" integers in [0, universe_size) |
| 492 | func BoundSerializedSizeInBytes(cardinality uint64, universeSize uint64) uint64 { |
| 493 | contnbr := (universeSize + uint64(65535)) / uint64(65536) |
| 494 | if contnbr > cardinality { |
| 495 | contnbr = cardinality |
| 496 | // we cannot have more containers than we have values |
| 497 | } |
| 498 | headermax := 8*contnbr + 4 |
| 499 | if 4 > (contnbr+7)/8 { |
| 500 | headermax += 4 |
| 501 | } else { |
| 502 | headermax += (contnbr + 7) / 8 |
| 503 | } |
| 504 | valsarray := uint64(arrayContainerSizeInBytes(int(cardinality))) |
| 505 | valsbitmap := contnbr * uint64(bitmapContainerSizeInBytes()) |
| 506 | valsbest := valsarray |
| 507 | if valsbest > valsbitmap { |
| 508 | valsbest = valsbitmap |
| 509 | } |
| 510 | return valsbest + headermax |
| 511 | } |
| 512 | |
| 513 | // IntIterable allows you to iterate over the values in a Bitmap |
| 514 | type IntIterable interface { |
searching dependent graphs…