]>
git.ipfire.org Git - thirdparty/bird.git/blob - lib/bitmap.h
2 * BIRD Library -- Bitmaps
4 * (c) 2019 Ondrej Zajicek <santiago@crfreenet.org>
5 * (c) 2019 CZ.NIC z.s.p.o.
7 * Can be freely distributed and used under the terms of the GNU GPL.
10 #ifndef _BIRD_BITMAP_H_
11 #define _BIRD_BITMAP_H_
19 void bmap_init(struct bmap
*b
, pool
*p
, uint size
);
20 void bmap_grow(struct bmap
*b
, uint need
);
21 void bmap_free(struct bmap
*b
);
23 static inline uint
bmap_max(struct bmap
*b
)
24 { return 8 * b
->size
; }
26 static inline int bmap_test(struct bmap
*b
, uint n
)
27 { return (n
< bmap_max(b
)) && BIT32_TEST(b
->data
, n
); }
29 static inline void bmap_set(struct bmap
*b
, uint n
)
31 if (n
>= bmap_max(b
)) bmap_grow(b
, n
/8 + 1);
32 BIT32_SET(b
->data
, n
);
35 static inline void bmap_clear(struct bmap
*b
, uint n
)
37 if (n
>= bmap_max(b
)) return;
38 BIT32_CLR(b
->data
, n
);
49 static inline uint
hmap_max(struct hmap
*b
)
50 { return 8 * b
->size
[0]; }
52 static inline int hmap_test(struct hmap
*b
, uint n
)
53 { return (n
< hmap_max(b
)) && BIT32_TEST(b
->data
[0], n
); }
55 void hmap_init(struct hmap
*b
, pool
*p
, uint size
);
56 void hmap_free(struct hmap
*b
);
57 void hmap_set(struct hmap
*b
, uint n
);
58 void hmap_clear(struct hmap
*b
, uint n
);
59 u32
hmap_first_zero(struct hmap
*b
);
60 void hmap_check(struct hmap
*b
);