2 * Copyright 2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Paweł Dziepak, pdziepak@quarnos.org
10 #include <util/Bitmap.h>
16 #include <util/BitUtils.h>
19 const int Bitmap::kBitsPerElement
= sizeof(addr_t
) * 8;
22 Bitmap::Bitmap(int bitCount
)
28 int count
= fSize
+ kBitsPerElement
- 1;
29 count
/= kBitsPerElement
;
31 fBits
= new(std::nothrow
) addr_t
[count
];
34 fInitStatus
= B_NO_MEMORY
;
37 fElementsCount
= count
;
38 memset(fBits
, 0, sizeof(addr_t
) * count
);
49 Bitmap::GetHighestSet() const
51 int i
= fElementsCount
- 1;
52 while (i
>= 0 && fBits
[i
] == 0)
58 STATIC_ASSERT(sizeof(addr_t
) == sizeof(uint64
)
59 || sizeof(addr_t
) == sizeof(uint32
));
60 if (sizeof(addr_t
) == sizeof(uint32
))
61 return log2(fBits
[i
]) + i
* kBitsPerElement
;
63 uint32 v
= (uint64
)fBits
[i
] >> 32;
65 return log2(v
) + sizeof(uint32
) * 8 + i
* kBitsPerElement
;
66 return log2(fBits
[i
]) + i
* kBitsPerElement
;