Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/harfbuzz/src/hb-set.hh @ 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 * Copyright © 2012,2017 Google, Inc. | |
| 3 * Copyright © 2021 Behdad Esfahbod | |
| 4 * | |
| 5 * This is part of HarfBuzz, a text shaping library. | |
| 6 * | |
| 7 * Permission is hereby granted, without written agreement and without | |
| 8 * license or royalty fees, to use, copy, modify, and distribute this | |
| 9 * software and its documentation for any purpose, provided that the | |
| 10 * above copyright notice and the following two paragraphs appear in | |
| 11 * all copies of this software. | |
| 12 * | |
| 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR | |
| 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES | |
| 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN | |
| 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | |
| 17 * DAMAGE. | |
| 18 * | |
| 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | |
| 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS | |
| 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO | |
| 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
| 24 * | |
| 25 * Google Author(s): Behdad Esfahbod | |
| 26 */ | |
| 27 | |
| 28 #ifndef HB_SET_HH | |
| 29 #define HB_SET_HH | |
| 30 | |
| 31 #include "hb.hh" | |
| 32 #include "hb-bit-set-invertible.hh" | |
| 33 | |
| 34 | |
| 35 template <typename impl_t> | |
| 36 struct hb_sparseset_t | |
| 37 { | |
| 38 hb_object_header_t header; | |
| 39 impl_t s; | |
| 40 | |
| 41 hb_sparseset_t () { init (); } | |
| 42 ~hb_sparseset_t () { fini (); } | |
| 43 | |
| 44 hb_sparseset_t (const hb_sparseset_t& other) : hb_sparseset_t () { set (other); } | |
| 45 hb_sparseset_t (hb_sparseset_t&& other) : hb_sparseset_t () { s = std::move (other.s); } | |
| 46 hb_sparseset_t& operator = (const hb_sparseset_t& other) { set (other); return *this; } | |
| 47 hb_sparseset_t& operator = (hb_sparseset_t&& other) { s = std::move (other.s); return *this; } | |
| 48 friend void swap (hb_sparseset_t& a, hb_sparseset_t& b) { hb_swap (a.s, b.s); } | |
| 49 | |
| 50 hb_sparseset_t (std::initializer_list<hb_codepoint_t> lst) : hb_sparseset_t () | |
| 51 { | |
| 52 for (auto&& item : lst) | |
| 53 add (item); | |
| 54 } | |
| 55 template <typename Iterable, | |
| 56 hb_requires (hb_is_iterable (Iterable))> | |
| 57 hb_sparseset_t (const Iterable &o) : hb_sparseset_t () | |
| 58 { | |
| 59 hb_copy (o, *this); | |
| 60 } | |
| 61 | |
| 62 void init () | |
| 63 { | |
| 64 hb_object_init (this); | |
| 65 s.init (); | |
| 66 } | |
| 67 void fini () | |
| 68 { | |
| 69 hb_object_fini (this); | |
| 70 s.fini (); | |
| 71 } | |
| 72 | |
| 73 explicit operator bool () const { return !is_empty (); } | |
| 74 | |
| 75 void err () { s.err (); } | |
| 76 bool in_error () const { return s.in_error (); } | |
| 77 | |
| 78 void alloc (unsigned sz) { s.alloc (sz); } | |
| 79 void reset () { s.reset (); } | |
| 80 void clear () { s.clear (); } | |
| 81 void invert () { s.invert (); } | |
| 82 bool is_empty () const { return s.is_empty (); } | |
| 83 uint32_t hash () const { return s.hash (); } | |
| 84 | |
| 85 void add (hb_codepoint_t g) { s.add (g); } | |
| 86 bool add_range (hb_codepoint_t a, hb_codepoint_t b) { return s.add_range (a, b); } | |
| 87 | |
| 88 template <typename T> | |
| 89 void add_array (const T *array, unsigned int count, unsigned int stride=sizeof(T)) | |
| 90 { s.add_array (array, count, stride); } | |
| 91 template <typename T> | |
| 92 void add_array (const hb_array_t<const T>& arr) { add_array (&arr, arr.len ()); } | |
| 93 | |
| 94 /* Might return false if array looks unsorted. | |
| 95 * Used for faster rejection of corrupt data. */ | |
| 96 template <typename T> | |
| 97 bool add_sorted_array (const T *array, unsigned int count, unsigned int stride=sizeof(T)) | |
| 98 { return s.add_sorted_array (array, count, stride); } | |
| 99 template <typename T> | |
| 100 bool add_sorted_array (const hb_sorted_array_t<const T>& arr) { return add_sorted_array (&arr, arr.len ()); } | |
| 101 | |
| 102 void del (hb_codepoint_t g) { s.del (g); } | |
| 103 void del_range (hb_codepoint_t a, hb_codepoint_t b) { s.del_range (a, b); } | |
| 104 | |
| 105 bool get (hb_codepoint_t g) const { return s.get (g); } | |
| 106 | |
| 107 /* Has interface. */ | |
| 108 bool operator [] (hb_codepoint_t k) const { return get (k); } | |
| 109 bool has (hb_codepoint_t k) const { return (*this)[k]; } | |
| 110 | |
| 111 /* Predicate. */ | |
| 112 bool operator () (hb_codepoint_t k) const { return has (k); } | |
| 113 | |
| 114 /* Sink interface. */ | |
| 115 hb_sparseset_t& operator << (hb_codepoint_t v) | |
| 116 { add (v); return *this; } | |
| 117 hb_sparseset_t& operator << (const hb_pair_t<hb_codepoint_t, hb_codepoint_t>& range) | |
| 118 { add_range (range.first, range.second); return *this; } | |
| 119 | |
| 120 bool intersects (hb_codepoint_t first, hb_codepoint_t last) const | |
| 121 { return s.intersects (first, last); } | |
| 122 | |
| 123 void set (const hb_sparseset_t &other) { s.set (other.s); } | |
| 124 | |
| 125 bool is_equal (const hb_sparseset_t &other) const { return s.is_equal (other.s); } | |
| 126 bool operator == (const hb_set_t &other) const { return is_equal (other); } | |
| 127 bool operator != (const hb_set_t &other) const { return !is_equal (other); } | |
| 128 | |
| 129 bool is_subset (const hb_sparseset_t &larger_set) const { return s.is_subset (larger_set.s); } | |
| 130 | |
| 131 void union_ (const hb_sparseset_t &other) { s.union_ (other.s); } | |
| 132 void intersect (const hb_sparseset_t &other) { s.intersect (other.s); } | |
| 133 void subtract (const hb_sparseset_t &other) { s.subtract (other.s); } | |
| 134 void symmetric_difference (const hb_sparseset_t &other) { s.symmetric_difference (other.s); } | |
| 135 | |
| 136 bool next (hb_codepoint_t *codepoint) const { return s.next (codepoint); } | |
| 137 bool previous (hb_codepoint_t *codepoint) const { return s.previous (codepoint); } | |
| 138 bool next_range (hb_codepoint_t *first, hb_codepoint_t *last) const | |
| 139 { return s.next_range (first, last); } | |
| 140 bool previous_range (hb_codepoint_t *first, hb_codepoint_t *last) const | |
| 141 { return s.previous_range (first, last); } | |
| 142 unsigned int next_many (hb_codepoint_t codepoint, hb_codepoint_t *out, unsigned int size) const | |
| 143 { return s.next_many (codepoint, out, size); } | |
| 144 | |
| 145 unsigned int get_population () const { return s.get_population (); } | |
| 146 hb_codepoint_t get_min () const { return s.get_min (); } | |
| 147 hb_codepoint_t get_max () const { return s.get_max (); } | |
| 148 | |
| 149 static constexpr hb_codepoint_t INVALID = impl_t::INVALID; | |
| 150 | |
| 151 /* | |
| 152 * Iterator implementation. | |
| 153 */ | |
| 154 using iter_t = typename impl_t::iter_t; | |
| 155 iter_t iter () const { return iter_t (this->s); } | |
| 156 operator iter_t () const { return iter (); } | |
| 157 }; | |
| 158 | |
| 159 struct hb_set_t : hb_sparseset_t<hb_bit_set_invertible_t> | |
| 160 { | |
| 161 using sparseset = hb_sparseset_t<hb_bit_set_invertible_t>; | |
| 162 | |
| 163 ~hb_set_t () = default; | |
| 164 hb_set_t () : sparseset () {}; | |
| 165 hb_set_t (const hb_set_t &o) : sparseset ((sparseset &) o) {}; | |
| 166 hb_set_t (hb_set_t&& o) : sparseset (std::move ((sparseset &) o)) {} | |
| 167 hb_set_t& operator = (const hb_set_t&) = default; | |
| 168 hb_set_t& operator = (hb_set_t&&) = default; | |
| 169 hb_set_t (std::initializer_list<hb_codepoint_t> lst) : sparseset (lst) {} | |
| 170 template <typename Iterable, | |
| 171 hb_requires (hb_is_iterable (Iterable))> | |
| 172 hb_set_t (const Iterable &o) : sparseset (o) {} | |
| 173 }; | |
| 174 | |
| 175 static_assert (hb_set_t::INVALID == HB_SET_VALUE_INVALID, ""); | |
| 176 | |
| 177 | |
| 178 #endif /* HB_SET_HH */ |
