Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ZXBitArray.h 3.5KB

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