Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/cutil/bitvec.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /****************************************************************************** | |
| 2 ** Filename: bitvec.h | |
| 3 ** Purpose: Routines for manipulating bit vectors | |
| 4 ** Author: Dan Johnson | |
| 5 ** | |
| 6 ** (c) Copyright Hewlett-Packard Company, 1988. | |
| 7 ** Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 ** you may not use this file except in compliance with the License. | |
| 9 ** You may obtain a copy of the License at | |
| 10 ** http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 ** Unless required by applicable law or agreed to in writing, software | |
| 12 ** distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 ** See the License for the specific language governing permissions and | |
| 15 ** limitations under the License. | |
| 16 ******************************************************************************/ | |
| 17 | |
| 18 #ifndef BITVEC_H | |
| 19 #define BITVEC_H | |
| 20 | |
| 21 #include <cstddef> // for size_t | |
| 22 #include <cstdint> // for uint32_t | |
| 23 | |
| 24 /*----------------------------------------------------------------------------- | |
| 25 Include Files and Type Defines | |
| 26 -----------------------------------------------------------------------------*/ | |
| 27 | |
| 28 using BIT_VECTOR = uint32_t *; | |
| 29 | |
| 30 //< no of bits in a BIT_VECTOR element | |
| 31 const size_t BITSINLONG = 8 * sizeof(uint32_t); | |
| 32 | |
| 33 /*----------------------------------------------------------------------------- | |
| 34 Public Function Prototypes | |
| 35 -----------------------------------------------------------------------------*/ | |
| 36 | |
| 37 static inline void zero_all_bits(BIT_VECTOR array, size_t length) { | |
| 38 for (size_t index = 0; index < length; index++) { | |
| 39 array[index] = 0; | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 static inline void set_all_bits(BIT_VECTOR array, size_t length) { | |
| 44 for (size_t index = 0; index < length; index++) { | |
| 45 array[index] = ~0; | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 static inline void copy_all_bits(BIT_VECTOR source, BIT_VECTOR dest, size_t length) { | |
| 50 for (size_t index = 0; index < length; index++) { | |
| 51 dest[index] = source[index]; | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 #define SET_BIT(array, bit) (array[bit / BITSINLONG] |= 1 << (bit & (BITSINLONG - 1))) | |
| 56 | |
| 57 #define reset_bit(array, bit) (array[bit / BITSINLONG] &= ~(1 << (bit & (BITSINLONG - 1)))) | |
| 58 | |
| 59 #define test_bit(array, bit) (array[bit / BITSINLONG] & (1 << (bit & (BITSINLONG - 1)))) | |
| 60 | |
| 61 static inline size_t WordsInVectorOfSize(size_t NumBits) { | |
| 62 return (NumBits + BITSINLONG - 1) / BITSINLONG; | |
| 63 } | |
| 64 | |
| 65 /** | |
| 66 * This routine frees a bit vector. | |
| 67 * | |
| 68 * @param BitVector bit vector to be freed | |
| 69 * | |
| 70 */ | |
| 71 static inline void FreeBitVector(BIT_VECTOR BitVector) { | |
| 72 delete[] BitVector; | |
| 73 } | |
| 74 | |
| 75 /*---------------------------------------------------------------------------*/ | |
| 76 /** | |
| 77 * Allocate and return a new bit vector large enough to | |
| 78 * hold the specified number of bits. | |
| 79 * | |
| 80 * @param NumBits number of bits in new bit vector | |
| 81 * | |
| 82 * @return New bit vector. | |
| 83 */ | |
| 84 static inline BIT_VECTOR NewBitVector(size_t NumBits) { | |
| 85 return new uint32_t[WordsInVectorOfSize(NumBits)]; | |
| 86 } | |
| 87 | |
| 88 #endif |
