3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
12 SkBitSet::SkBitSet(int numberOfBits)
13 : fBitData(NULL), fDwordCount(0), fBitCount(numberOfBits) {
14 SkASSERT(numberOfBits > 0);
15 // Round up size to 32-bit boundary.
16 fDwordCount = (numberOfBits + 31) / 32;
17 fBitData.set(sk_calloc_throw(fDwordCount * sizeof(uint32_t)));
20 SkBitSet::SkBitSet(const SkBitSet& source)
21 : fBitData(NULL), fDwordCount(0), fBitCount(0) {
25 SkBitSet& SkBitSet::operator=(const SkBitSet& rhs) {
29 fBitCount = rhs.fBitCount;
31 fDwordCount = rhs.fDwordCount;
32 fBitData.set(sk_malloc_throw(fDwordCount * sizeof(uint32_t)));
33 memcpy(fBitData.get(), rhs.fBitData.get(), fDwordCount * sizeof(uint32_t));
37 bool SkBitSet::operator==(const SkBitSet& rhs) {
38 if (fBitCount == rhs.fBitCount) {
39 if (fBitData.get() != NULL) {
40 return (memcmp(fBitData.get(), rhs.fBitData.get(),
41 fDwordCount * sizeof(uint32_t)) == 0);
48 bool SkBitSet::operator!=(const SkBitSet& rhs) {
49 return !(*this == rhs);
52 void SkBitSet::clearAll() {
53 if (fBitData.get() != NULL) {
54 sk_bzero(fBitData.get(), fDwordCount * sizeof(uint32_t));
58 bool SkBitSet::orBits(const SkBitSet& source) {
59 if (fBitCount != source.fBitCount) {
62 uint32_t* targetBitmap = this->internalGet(0);
63 uint32_t* sourceBitmap = source.internalGet(0);
64 for (size_t i = 0; i < fDwordCount; ++i) {
65 targetBitmap[i] |= sourceBitmap[i];