2012-04-24 04:41:09 +02:00
|
|
|
/*
|
2017-10-15 16:53:09 +02:00
|
|
|
* Copyright © 2012,2017 Google, Inc.
|
2021-08-15 20:34:55 +02:00
|
|
|
* Copyright © 2021 Behdad Esfahbod
|
2012-04-24 04:41:09 +02:00
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#ifndef HB_SET_HH
|
|
|
|
#define HB_SET_HH
|
2012-04-24 04:41:09 +02:00
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb.hh"
|
2021-08-17 23:37:19 +02:00
|
|
|
#include "hb-bit-set-invertible.hh"
|
2012-04-24 04:41:09 +02:00
|
|
|
|
|
|
|
|
2021-08-17 18:53:08 +02:00
|
|
|
template <typename impl_t>
|
2021-08-17 23:37:19 +02:00
|
|
|
struct hb_sparseset_t
|
2012-04-24 04:41:09 +02:00
|
|
|
{
|
2012-06-06 09:30:09 +02:00
|
|
|
hb_object_header_t header;
|
2021-08-17 18:53:08 +02:00
|
|
|
impl_t s;
|
2017-10-15 16:53:09 +02:00
|
|
|
|
2021-08-17 23:37:19 +02:00
|
|
|
hb_sparseset_t () { init (); }
|
|
|
|
~hb_sparseset_t () { fini (); }
|
|
|
|
|
2021-08-29 18:32:40 +02:00
|
|
|
hb_sparseset_t (const hb_sparseset_t& other) : hb_sparseset_t () { set (other); }
|
2021-11-02 07:14:34 +01:00
|
|
|
hb_sparseset_t (hb_sparseset_t&& other) : hb_sparseset_t () { s = std::move (other.s); }
|
2022-05-19 22:12:42 +02:00
|
|
|
hb_sparseset_t& operator = (const hb_sparseset_t& other) { set (other); return *this; }
|
|
|
|
hb_sparseset_t& operator = (hb_sparseset_t&& other) { s = std::move (other.s); return *this; }
|
2021-11-02 03:55:30 +01:00
|
|
|
friend void swap (hb_sparseset_t& a, hb_sparseset_t& b) { hb_swap (a.s, b.s); }
|
|
|
|
|
2021-11-02 04:34:46 +01:00
|
|
|
hb_sparseset_t (std::initializer_list<hb_codepoint_t> lst) : hb_sparseset_t ()
|
2021-11-02 03:55:30 +01:00
|
|
|
{
|
2021-11-02 04:34:46 +01:00
|
|
|
for (auto&& item : lst)
|
|
|
|
add (item);
|
2021-11-02 03:55:30 +01:00
|
|
|
}
|
|
|
|
template <typename Iterable,
|
2022-05-12 19:58:37 +02:00
|
|
|
hb_requires (hb_is_iterable (Iterable))>
|
2021-11-02 03:55:30 +01:00
|
|
|
hb_sparseset_t (const Iterable &o) : hb_sparseset_t ()
|
|
|
|
{
|
|
|
|
hb_copy (o, *this);
|
|
|
|
}
|
2021-08-29 18:32:40 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
void init ()
|
2018-05-02 18:56:21 +02:00
|
|
|
{
|
|
|
|
hb_object_init (this);
|
2022-07-20 23:57:09 +02:00
|
|
|
s.init ();
|
2018-05-02 18:56:21 +02:00
|
|
|
}
|
2018-12-17 19:01:01 +01:00
|
|
|
void fini ()
|
2018-05-02 18:56:21 +02:00
|
|
|
{
|
|
|
|
hb_object_fini (this);
|
2022-07-20 23:57:09 +02:00
|
|
|
s.fini ();
|
2018-05-02 18:56:21 +02:00
|
|
|
}
|
2017-12-14 22:37:48 +01:00
|
|
|
|
2020-06-29 07:41:09 +02:00
|
|
|
explicit operator bool () const { return !is_empty (); }
|
2017-10-15 16:53:09 +02:00
|
|
|
|
2021-08-17 04:48:24 +02:00
|
|
|
void err () { s.err (); }
|
|
|
|
bool in_error () const { return s.in_error (); }
|
2018-05-02 00:27:41 +02:00
|
|
|
|
2022-05-18 23:24:40 +02:00
|
|
|
void alloc (unsigned sz) { s.alloc (sz); }
|
2021-08-17 04:48:24 +02:00
|
|
|
void reset () { s.reset (); }
|
|
|
|
void clear () { s.clear (); }
|
2021-08-17 23:37:19 +02:00
|
|
|
void invert () { s.invert (); }
|
2023-01-06 00:26:41 +01:00
|
|
|
bool is_inverted () const { return s.is_inverted (); }
|
2021-08-17 04:48:24 +02:00
|
|
|
bool is_empty () const { return s.is_empty (); }
|
2022-05-19 23:42:54 +02:00
|
|
|
uint32_t hash () const { return s.hash (); }
|
2021-08-17 04:48:24 +02:00
|
|
|
|
|
|
|
void add (hb_codepoint_t g) { s.add (g); }
|
|
|
|
bool add_range (hb_codepoint_t a, hb_codepoint_t b) { return s.add_range (a, b); }
|
2017-12-15 04:33:55 +01:00
|
|
|
|
2017-12-13 22:12:20 +01:00
|
|
|
template <typename T>
|
2018-12-16 20:08:10 +01:00
|
|
|
void add_array (const T *array, unsigned int count, unsigned int stride=sizeof(T))
|
2021-08-17 04:48:24 +02:00
|
|
|
{ s.add_array (array, count, stride); }
|
2021-04-01 23:47:21 +02:00
|
|
|
template <typename T>
|
|
|
|
void add_array (const hb_array_t<const T>& arr) { add_array (&arr, arr.len ()); }
|
2017-12-16 17:36:16 +01:00
|
|
|
|
2017-12-15 04:33:55 +01:00
|
|
|
/* Might return false if array looks unsorted.
|
|
|
|
* Used for faster rejection of corrupt data. */
|
|
|
|
template <typename T>
|
2018-12-16 20:08:10 +01:00
|
|
|
bool add_sorted_array (const T *array, unsigned int count, unsigned int stride=sizeof(T))
|
2021-08-17 04:48:24 +02:00
|
|
|
{ return s.add_sorted_array (array, count, stride); }
|
2021-04-01 23:47:21 +02:00
|
|
|
template <typename T>
|
|
|
|
bool add_sorted_array (const hb_sorted_array_t<const T>& arr) { return add_sorted_array (&arr, arr.len ()); }
|
2017-12-15 04:33:55 +01:00
|
|
|
|
2021-08-17 04:48:24 +02:00
|
|
|
void del (hb_codepoint_t g) { s.del (g); }
|
|
|
|
void del_range (hb_codepoint_t a, hb_codepoint_t b) { s.del_range (a, b); }
|
2020-09-16 22:56:33 +02:00
|
|
|
|
2021-08-17 04:48:24 +02:00
|
|
|
bool get (hb_codepoint_t g) const { return s.get (g); }
|
2019-01-09 17:39:25 +01:00
|
|
|
|
2019-01-28 22:34:04 +01:00
|
|
|
/* Has interface. */
|
2022-11-29 03:42:27 +01:00
|
|
|
bool operator [] (hb_codepoint_t k) const { return get (k); }
|
|
|
|
bool has (hb_codepoint_t k) const { return (*this)[k]; }
|
2022-03-25 16:36:44 +01:00
|
|
|
|
2019-01-28 22:34:04 +01:00
|
|
|
/* Predicate. */
|
2019-01-09 17:39:25 +01:00
|
|
|
bool operator () (hb_codepoint_t k) const { return has (k); }
|
|
|
|
|
2019-01-28 22:39:01 +01:00
|
|
|
/* Sink interface. */
|
2021-08-17 23:37:19 +02:00
|
|
|
hb_sparseset_t& operator << (hb_codepoint_t v)
|
2020-04-23 19:51:12 +02:00
|
|
|
{ add (v); return *this; }
|
2021-08-17 23:37:19 +02:00
|
|
|
hb_sparseset_t& operator << (const hb_pair_t<hb_codepoint_t, hb_codepoint_t>& range)
|
2020-04-23 19:51:12 +02:00
|
|
|
{ add_range (range.first, range.second); return *this; }
|
2019-01-28 22:39:01 +01:00
|
|
|
|
2019-01-09 17:39:25 +01:00
|
|
|
bool intersects (hb_codepoint_t first, hb_codepoint_t last) const
|
2021-08-17 04:48:24 +02:00
|
|
|
{ return s.intersects (first, last); }
|
2017-10-15 16:53:09 +02:00
|
|
|
|
2021-08-17 23:37:19 +02:00
|
|
|
void set (const hb_sparseset_t &other) { s.set (other.s); }
|
2021-05-19 09:34:09 +02:00
|
|
|
|
2021-08-17 23:37:19 +02:00
|
|
|
bool is_equal (const hb_sparseset_t &other) const { return s.is_equal (other.s); }
|
2022-05-19 20:58:02 +02:00
|
|
|
bool operator == (const hb_set_t &other) const { return is_equal (other); }
|
|
|
|
bool operator != (const hb_set_t &other) const { return !is_equal (other); }
|
2021-05-19 09:34:09 +02:00
|
|
|
|
2021-08-17 23:37:19 +02:00
|
|
|
bool is_subset (const hb_sparseset_t &larger_set) const { return s.is_subset (larger_set.s); }
|
2021-05-19 09:34:09 +02:00
|
|
|
|
2021-08-17 23:37:19 +02:00
|
|
|
void union_ (const hb_sparseset_t &other) { s.union_ (other.s); }
|
|
|
|
void intersect (const hb_sparseset_t &other) { s.intersect (other.s); }
|
|
|
|
void subtract (const hb_sparseset_t &other) { s.subtract (other.s); }
|
|
|
|
void symmetric_difference (const hb_sparseset_t &other) { s.symmetric_difference (other.s); }
|
2021-05-19 09:34:09 +02:00
|
|
|
|
2021-08-17 04:48:24 +02:00
|
|
|
bool next (hb_codepoint_t *codepoint) const { return s.next (codepoint); }
|
|
|
|
bool previous (hb_codepoint_t *codepoint) const { return s.previous (codepoint); }
|
2018-12-16 20:08:10 +01:00
|
|
|
bool next_range (hb_codepoint_t *first, hb_codepoint_t *last) const
|
2021-08-17 04:48:24 +02:00
|
|
|
{ return s.next_range (first, last); }
|
2018-12-16 20:08:10 +01:00
|
|
|
bool previous_range (hb_codepoint_t *first, hb_codepoint_t *last) const
|
2021-08-17 04:48:24 +02:00
|
|
|
{ return s.previous_range (first, last); }
|
2022-03-25 16:42:36 +01:00
|
|
|
unsigned int next_many (hb_codepoint_t codepoint, hb_codepoint_t *out, unsigned int size) const
|
|
|
|
{ return s.next_many (codepoint, out, size); }
|
2018-02-14 10:00:10 +01:00
|
|
|
|
2021-08-17 04:48:24 +02:00
|
|
|
unsigned int get_population () const { return s.get_population (); }
|
|
|
|
hb_codepoint_t get_min () const { return s.get_min (); }
|
|
|
|
hb_codepoint_t get_max () const { return s.get_max (); }
|
2018-02-14 10:00:10 +01:00
|
|
|
|
2021-08-17 18:53:08 +02:00
|
|
|
static constexpr hb_codepoint_t INVALID = impl_t::INVALID;
|
2012-04-24 04:41:09 +02:00
|
|
|
|
2018-12-22 02:06:17 +01:00
|
|
|
/*
|
|
|
|
* Iterator implementation.
|
|
|
|
*/
|
2021-08-17 18:53:08 +02:00
|
|
|
using iter_t = typename impl_t::iter_t;
|
2021-08-17 04:48:24 +02:00
|
|
|
iter_t iter () const { return iter_t (this->s); }
|
2018-12-27 01:49:13 +01:00
|
|
|
operator iter_t () const { return iter (); }
|
2012-04-24 04:41:09 +02:00
|
|
|
};
|
|
|
|
|
2021-11-02 03:55:30 +01:00
|
|
|
struct hb_set_t : hb_sparseset_t<hb_bit_set_invertible_t>
|
|
|
|
{
|
2022-05-12 20:58:07 +02:00
|
|
|
using sparseset = hb_sparseset_t<hb_bit_set_invertible_t>;
|
|
|
|
|
2021-11-02 04:25:03 +01:00
|
|
|
~hb_set_t () = default;
|
2022-05-12 20:58:07 +02:00
|
|
|
hb_set_t () : sparseset () {};
|
|
|
|
hb_set_t (const hb_set_t &o) : sparseset ((sparseset &) o) {};
|
|
|
|
hb_set_t (hb_set_t&& o) : sparseset (std::move ((sparseset &) o)) {}
|
2022-05-19 22:12:42 +02:00
|
|
|
hb_set_t& operator = (const hb_set_t&) = default;
|
|
|
|
hb_set_t& operator = (hb_set_t&&) = default;
|
2022-05-12 20:58:07 +02:00
|
|
|
hb_set_t (std::initializer_list<hb_codepoint_t> lst) : sparseset (lst) {}
|
2021-11-02 03:55:30 +01:00
|
|
|
template <typename Iterable,
|
2022-05-12 21:05:32 +02:00
|
|
|
hb_requires (hb_is_iterable (Iterable))>
|
2022-05-12 20:58:07 +02:00
|
|
|
hb_set_t (const Iterable &o) : sparseset (o) {}
|
2023-01-05 01:12:08 +01:00
|
|
|
|
|
|
|
hb_set_t& operator << (hb_codepoint_t v)
|
|
|
|
{ sparseset::operator<< (v); return *this; }
|
|
|
|
hb_set_t& operator << (const hb_pair_t<hb_codepoint_t, hb_codepoint_t>& range)
|
|
|
|
{ sparseset::operator<< (range); return *this; }
|
2021-11-02 03:55:30 +01:00
|
|
|
};
|
2021-08-17 18:53:08 +02:00
|
|
|
|
|
|
|
static_assert (hb_set_t::INVALID == HB_SET_VALUE_INVALID, "");
|
|
|
|
|
2012-04-24 04:41:09 +02:00
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#endif /* HB_SET_HH */
|