MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / bitmap_init

Function bitmap_init

deps/memkind/src/jemalloc/src/bitmap.c:44–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44void
45bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo, bool fill) {
46 size_t extra;
47 unsigned i;
48
49 /*
50 * Bits are actually inverted with regard to the external bitmap
51 * interface.
52 */
53
54 if (fill) {
55 /* The "filled" bitmap starts out with all 0 bits. */
56 memset(bitmap, 0, bitmap_size(binfo));
57 return;
58 }
59
60 /*
61 * The "empty" bitmap starts out with all 1 bits, except for trailing
62 * unused bits (if any). Note that each group uses bit 0 to correspond
63 * to the first logical bit in the group, so extra bits are the most
64 * significant bits of the last group.
65 */
66 memset(bitmap, 0xffU, bitmap_size(binfo));
67 extra = (BITMAP_GROUP_NBITS - (binfo->nbits & BITMAP_GROUP_NBITS_MASK))
68 & BITMAP_GROUP_NBITS_MASK;
69 if (extra != 0) {
70 bitmap[binfo->levels[1].group_offset - 1] >>= extra;
71 }
72 for (i = 1; i < binfo->nlevels; i++) {
73 size_t group_count = binfo->levels[i].group_offset -
74 binfo->levels[i-1].group_offset;
75 extra = (BITMAP_GROUP_NBITS - (group_count &
76 BITMAP_GROUP_NBITS_MASK)) & BITMAP_GROUP_NBITS_MASK;
77 if (extra != 0) {
78 bitmap[binfo->levels[i+1].group_offset - 1] >>= extra;
79 }
80 }
81}
82
83#else /* BITMAP_USE_TREE */
84

Callers 6

extents_initFunction · 0.70
arena_slab_allocFunction · 0.70
test_bitmap_init_bodyFunction · 0.50
test_bitmap_set_bodyFunction · 0.50
test_bitmap_unset_bodyFunction · 0.50
test_bitmap_xfu_bodyFunction · 0.50

Calls 1

bitmap_sizeFunction · 0.70

Tested by 4

test_bitmap_init_bodyFunction · 0.40
test_bitmap_set_bodyFunction · 0.40
test_bitmap_unset_bodyFunction · 0.40
test_bitmap_xfu_bodyFunction · 0.40