2 * Copyright 2007 Google Inc.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.google.zxing.common;
\r
20 * <p>A simple, fast array of bits, represented compactly by an array of ints internally.</p>
\r
22 * @author srowen@google.com (Sean Owen)
\r
24 public final class BitArray {
\r
26 private final int[] bits;
\r
28 public BitArray(int size) {
\r
29 int arraySize = size >> 5;
\r
30 if ((size & 0x1F) != 0) {
\r
33 bits = new int[arraySize];
\r
37 * @return true iff bit i is set
\r
39 public boolean get(int i) {
\r
40 return (bits[i >> 5] & (1 << (i & 0x1F))) != 0;
\r
46 public void set(int i) {
\r
47 bits[i >> 5] |= 1 << (i & 0x1F);
\r
50 public void setBulk(int i, int newBits) {
\r
51 bits[i >> 5] = newBits;
\r
57 public void clear() {
\r
58 int max = bits.length;
\r
59 for (int i = 0; i < max; i++) {
\r
65 * @return underlying array of ints. The first element holds the first 32 bits, and the least
\r
66 * significant bit is bit 0.
\r
68 public int[] getBitArray() {
\r