MCPcopy Create free account
hub / github.com/apache/impala / BitmapFindFirst

Function BitmapFindFirst

be/src/kudu/util/bitmap.cc:70–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70bool BitmapFindFirst(const uint8_t *bitmap, size_t offset, size_t bitmap_size,
71 bool value, size_t *idx) {
72 const uint64_t pattern64[2] = { 0xffffffffffffffff, 0x0000000000000000 };
73 const uint8_t pattern8[2] = { 0xff, 0x00 };
74 size_t bit;
75
76 DCHECK_LE(offset, bitmap_size);
77
78 // Jump to the byte at specified offset
79 const uint8_t *p = bitmap + (offset >> 3);
80 size_t num_bits = bitmap_size - offset;
81
82 // Find a 'value' bit at the end of the first byte
83 if ((bit = offset & 0x7)) {
84 for (; bit < 8 && num_bits > 0; ++bit) {
85 if (BitmapTest(p, bit) == value) {
86 *idx = ((p - bitmap) << 3) + bit;
87 return true;
88 }
89
90 num_bits--;
91 }
92
93 p++;
94 }
95
96 // check 64bit at the time for a 'value' bit
97 const uint64_t *u64 = (const uint64_t *)p;
98 while (num_bits >= 64 && *u64 == pattern64[value]) {
99 num_bits -= 64;
100 u64++;
101 }
102
103 // check 8bit at the time for a 'value' bit
104 p = (const uint8_t *)u64;
105 while (num_bits >= 8 && *p == pattern8[value]) {
106 num_bits -= 8;
107 p++;
108 }
109
110 // Find a 'value' bit at the beginning of the last byte
111 for (bit = 0; num_bits > 0; ++bit) {
112 if (BitmapTest(p, bit) == value) {
113 *idx = ((p - bitmap) << 3) + bit;
114 return true;
115 }
116 num_bits--;
117 }
118
119 return false;
120}
121
122void BitmapCopy(uint8_t* dst, size_t dst_offset,
123 const uint8_t* src, size_t src_offset,

Callers 3

BitmapFindFirstSetFunction · 0.85
BitmapFindFirstZeroFunction · 0.85
NextMethod · 0.85

Calls 1

BitmapTestFunction · 0.85

Tested by

no test coverage detected