IntersectCompressedWith intersects a packed list of UIDs with another list and writes the output to o.
(pack *pb.UidPack, afterUID uint64, v, o *pb.List)
| 31 | // IntersectCompressedWith intersects a packed list of UIDs with another list |
| 32 | // and writes the output to o. |
| 33 | func IntersectCompressedWith(pack *pb.UidPack, afterUID uint64, v, o *pb.List) { |
| 34 | if pack == nil { |
| 35 | return |
| 36 | } |
| 37 | dec := codec.Decoder{Pack: pack} |
| 38 | dec.Seek(afterUID, codec.SeekStart) |
| 39 | n := dec.ApproxLen() |
| 40 | m := len(v.Uids) |
| 41 | |
| 42 | if n > m { |
| 43 | n, m = m, n |
| 44 | } |
| 45 | dst := o.Uids[:0] |
| 46 | |
| 47 | // If n equals 0, set it to 1 to avoid division by zero. |
| 48 | if n == 0 { |
| 49 | n = 1 |
| 50 | } |
| 51 | |
| 52 | // Select appropriate function based on heuristics. |
| 53 | ratio := float64(m) / float64(n) |
| 54 | if ratio < linVsBinRatio { |
| 55 | IntersectCompressedWithLinJump(&dec, v.Uids, &dst) |
| 56 | } else { |
| 57 | IntersectCompressedWithBin(&dec, v.Uids, &dst) |
| 58 | } |
| 59 | o.Uids = dst |
| 60 | } |
| 61 | |
| 62 | // IntersectCompressedWithLinJump performs the intersection linearly. |
| 63 | func IntersectCompressedWithLinJump(dec *codec.Decoder, v []uint64, o *[]uint64) { |