单军华
2017-07-12 20d1260d26b028897f3c0935c12fc35aa37b2e93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Copyright 2012 ZXing authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
@class ZXByteArray, ZXIntArray;
 
/**
 * A simple, fast array of bits, represented compactly by an array of ints internally.
 */
@interface ZXBitArray : NSObject <NSCopying>
 
/**
 * @return underlying array of ints. The first element holds the first 32 bits, and the least
 *         significant bit is bit 0.
 */
@property (nonatomic, assign, readonly) int32_t *bits;
 
@property (nonatomic, assign, readonly) int size;
 
- (id)initWithSize:(int)size;
 
- (int)sizeInBytes;
 
/**
 * @param i bit to get
 * @return true iff bit i is set
 */
- (BOOL)get:(int)i;
 
/**
 * Sets bit i.
 *
 * @param i bit to set
 */
- (void)set:(int)i;
 
/**
 * Flips bit i.
 *
 * @param i bit to set
 */
- (void)flip:(int)i;
 
/**
 * @param from first bit to check
 * @return index of first bit that is set, starting from the given index, or size if none are set
 *  at or beyond this given index
 */
- (int)nextSet:(int)from;
 
- (int)nextUnset:(int)from;
 
/**
 * Sets a block of 32 bits, starting at bit i.
 *
 * @param i first bit to set
 * @param newBits the new value of the next 32 bits. Note again that the least-significant bit
 * corresponds to bit i, the next-least-significant to i+1, and so on.
 */
- (void)setBulk:(int)i newBits:(int32_t)newBits;
 
/**
 * Sets a range of bits.
 *
 * @param start start of range, inclusive.
 * @param end end of range, exclusive
 */
- (void)setRange:(int)start end:(int)end;
 
/**
 * Clears all bits (sets to false).
 */
- (void)clear;
 
/**
 * Efficient method to check if a range of bits is set, or not set.
 *
 * @param start start of range, inclusive.
 * @param end end of range, exclusive
 * @param value if true, checks that bits in range are set, otherwise checks that they are not set
 * @return true iff all bits are set or not set in range, according to value argument
 * @throws NSInvalidArgumentException if end is less than or equal to start
 */
- (BOOL)isRange:(int)start end:(int)end value:(BOOL)value;
 
- (void)appendBit:(BOOL)bit;
 
/**
 * Appends the least-significant bits, from value, in order from most-significant to
 * least-significant. For example, appending 6 bits from 0x000001E will append the bits
 * 0, 1, 1, 1, 1, 0 in that order.
 */
- (void)appendBits:(int32_t)value numBits:(int)numBits;
 
- (void)appendBitArray:(ZXBitArray *)other;
 
- (void)xor:(ZXBitArray *)other;
 
/**
 *
 * @param bitOffset first bit to start writing
 * @param array array to write into. Bytes are written most-significant byte first. This is the opposite
 *  of the internal representation, which is exposed by {@link #getBitArray()}
 * @param offset position in array to start writing
 * @param numBytes how many bytes to write
 */
- (void)toBytes:(int)bitOffset array:(ZXByteArray *)array offset:(int)offset numBytes:(int)numBytes;
 
/**
 * @return underlying array of ints. The first element holds the first 32 bits, and the least
 *         significant bit is bit 0.
 */
- (ZXIntArray *)bitArray;
 
/**
 * Reverses all bits in the array.
 */
- (void)reverse;
 
@end