-
Notifications
You must be signed in to change notification settings - Fork 20
include: introduce bitmap API #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
include/bitmap.h
Outdated
| int nbits; | ||
| } bitmap_t; | ||
|
|
||
| static inline bitmap_t *bitmap_alloc(int nbits) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would place bitmap_alloc() and bitmap_free() into bitmap.c file and declare them as non-inline functions.
include/bitmap.h
Outdated
| if (NULL == map) | ||
| return NULL; | ||
|
|
||
| map->word = kmalloc(BITS_TO_LONGS(nbits) * __SIZEOF_LONG__); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better would be kzmalloc(); or add explicit memset(map->word, 0, size)
include/bitmap.h
Outdated
| int nbits; | ||
| } bitmap_t; | ||
|
|
||
| static inline bitmap_t *bitmap_alloc(int nbits) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: nbits could be unsigned
include/bitmap.h
Outdated
| static inline int bitmap_find_first_clear(const bitmap_t *map) { | ||
| if (NULL == map || NULL == map->word) | ||
| return INT_MAX; | ||
|
|
||
| for (int i = 0; i < BITS_TO_LONGS(map->nbits); i++) { | ||
| int ret = __builtin_ffsl(~map->word[i]); | ||
| if (0 == ret) | ||
| continue; | ||
|
|
||
| return i * BITS_PER_LONG + ret - 1; | ||
| } | ||
|
|
||
| return INT_MAX; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one appears identical to bitmap_find_first_set()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is except for the negation on map->word[i]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I missed that, my bad.
Add a new bitmap_t that represents an array-based bitmap. Implement alloc/free and various functions for bitmap operations. Add div_round_up helper macro for computing the number of longs that a given bitmap should be. Signed-off-by: Connor Davis <[email protected]>
dkgupta-amzn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Add a new bitmap_t that represents an array-based bitmap.
Implement alloc/free and various functions for bitmap operations.
Add div_round_up helper macro for computing the number of longs
that a given bitmap should be.
Signed-off-by: Connor Davis [email protected]
Issue #145
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.