2 * Copyright © 2012 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
33 * @short_description: Objects representing a set of integers
36 * Set objects represent a mathematical set of integer values. They are
37 * used in non-shaping APIs to query certain sets of characters or glyphs,
38 * or other integer values.
45 * Creates a new, initially empty set.
47 * Return value: (transfer full): The new #hb_set_t
56 if (!(set = hb_object_create<hb_set_t> ()))
57 return hb_set_get_empty ();
65 * Fetches the singleton empty #hb_set_t.
67 * Return value: (transfer full): The empty #hb_set_t
74 return const_cast<hb_set_t *> (&Null (hb_set_t));
78 * hb_set_reference: (skip)
81 * Increases the reference count on a set.
83 * Return value: (transfer full): The set
88 hb_set_reference (hb_set_t *set)
90 return hb_object_reference (set);
94 * hb_set_destroy: (skip)
97 * Decreases the reference count on a set. When
98 * the reference count reaches zero, the set is
99 * destroyed, freeing all memory.
104 hb_set_destroy (hb_set_t *set)
106 if (!hb_object_destroy (set)) return;
112 * hb_set_set_user_data: (skip)
114 * @key: The user-data key to set
115 * @data: A pointer to the user data to set
116 * @destroy: (nullable): A callback to call when @data is not needed anymore
117 * @replace: Whether to replace an existing data with the same key
119 * Attaches a user-data key/data pair to the specified set.
121 * Return value: `true` if success, `false` otherwise
126 hb_set_set_user_data (hb_set_t *set,
127 hb_user_data_key_t *key,
129 hb_destroy_func_t destroy,
132 return hb_object_set_user_data (set, key, data, destroy, replace);
136 * hb_set_get_user_data: (skip)
138 * @key: The user-data key to query
140 * Fetches the user data associated with the specified key,
141 * attached to the specified set.
143 * Return value: (transfer none): A pointer to the user data
148 hb_set_get_user_data (const hb_set_t *set,
149 hb_user_data_key_t *key)
151 return hb_object_get_user_data (set, key);
156 * hb_set_allocation_successful:
159 * Tests whether memory allocation for a set was successful.
161 * Return value: `true` if allocation succeeded, `false` otherwise
166 hb_set_allocation_successful (const hb_set_t *set)
168 return !set->in_error ();
175 * Allocate a copy of @set.
177 * Return value: (transfer full): Newly-allocated set.
182 hb_set_copy (const hb_set_t *set)
184 hb_set_t *copy = hb_set_create ();
185 if (unlikely (copy->in_error ()))
186 return hb_set_get_empty ();
196 * Clears out the contents of a set.
201 hb_set_clear (hb_set_t *set)
203 /* Immutable-safe. */
211 * Tests whether a set is empty (contains no elements).
213 * Return value: `true` if @set is empty
218 hb_set_is_empty (const hb_set_t *set)
220 return set->is_empty ();
226 * @codepoint: The element to query
228 * Tests whether @codepoint belongs to @set.
230 * Return value: `true` if @codepoint is in @set, `false` otherwise
235 hb_set_has (const hb_set_t *set,
236 hb_codepoint_t codepoint)
238 return set->has (codepoint);
244 * @codepoint: The element to add to @set
246 * Adds @codepoint to @set.
251 hb_set_add (hb_set_t *set,
252 hb_codepoint_t codepoint)
254 /* Immutable-safe. */
255 set->add (codepoint);
259 * hb_set_add_sorted_array:
261 * @sorted_codepoints: (array length=num_codepoints): Array of codepoints to add
262 * @num_codepoints: Length of @sorted_codepoints
264 * Adds @num_codepoints codepoints to a set at once.
265 * The codepoints array must be in increasing order,
266 * with size at least @num_codepoints.
271 hb_set_add_sorted_array (hb_set_t *set,
272 const hb_codepoint_t *sorted_codepoints,
273 unsigned int num_codepoints)
275 /* Immutable-safe. */
276 set->add_sorted_array (sorted_codepoints,
278 sizeof(hb_codepoint_t));
284 * @first: The first element to add to @set
285 * @last: The final element to add to @set
287 * Adds all of the elements from @first to @last
288 * (inclusive) to @set.
293 hb_set_add_range (hb_set_t *set,
294 hb_codepoint_t first,
297 /* Immutable-safe. */
298 set->add_range (first, last);
304 * @codepoint: Removes @codepoint from @set
306 * Removes @codepoint from @set.
311 hb_set_del (hb_set_t *set,
312 hb_codepoint_t codepoint)
314 /* Immutable-safe. */
315 set->del (codepoint);
321 * @first: The first element to remove from @set
322 * @last: The final element to remove from @set
324 * Removes all of the elements from @first to @last
325 * (inclusive) from @set.
327 * If @last is #HB_SET_VALUE_INVALID, then all values
328 * greater than or equal to @first are removed.
333 hb_set_del_range (hb_set_t *set,
334 hb_codepoint_t first,
337 /* Immutable-safe. */
338 set->del_range (first, last);
344 * @other: Another set
346 * Tests whether @set and @other are equal (contain the same
349 * Return value: `true` if the two sets are equal, `false` otherwise.
354 hb_set_is_equal (const hb_set_t *set,
355 const hb_set_t *other)
357 return set->is_equal (*other);
364 * Creates a hash representing @set.
371 HB_EXTERN unsigned int
372 hb_set_hash (const hb_set_t *set)
380 * @larger_set: Another set
382 * Tests whether @set is a subset of @larger_set.
384 * Return value: `true` if the @set is a subset of (or equal to) @larger_set, `false` otherwise.
389 hb_set_is_subset (const hb_set_t *set,
390 const hb_set_t *larger_set)
392 return set->is_subset (*larger_set);
398 * @other: Another set
400 * Makes the contents of @set equal to the contents of @other.
405 hb_set_set (hb_set_t *set,
406 const hb_set_t *other)
408 /* Immutable-safe. */
415 * @other: Another set
417 * Makes @set the union of @set and @other.
422 hb_set_union (hb_set_t *set,
423 const hb_set_t *other)
425 /* Immutable-safe. */
426 set->union_ (*other);
432 * @other: Another set
434 * Makes @set the intersection of @set and @other.
439 hb_set_intersect (hb_set_t *set,
440 const hb_set_t *other)
442 /* Immutable-safe. */
443 set->intersect (*other);
449 * @other: Another set
451 * Subtracts the contents of @other from @set.
456 hb_set_subtract (hb_set_t *set,
457 const hb_set_t *other)
459 /* Immutable-safe. */
460 set->subtract (*other);
464 * hb_set_symmetric_difference:
466 * @other: Another set
468 * Makes @set the symmetric difference of @set
474 hb_set_symmetric_difference (hb_set_t *set,
475 const hb_set_t *other)
477 /* Immutable-safe. */
478 set->symmetric_difference (*other);
485 * Inverts the contents of @set.
490 hb_set_invert (hb_set_t *set)
492 /* Immutable-safe. */
497 * hb_set_is_inverted:
500 * Returns whether the set is inverted.
502 * Return value: `true` if the set is inverted, `false` otherwise
507 hb_set_is_inverted (const hb_set_t *set)
509 return set->is_inverted ();
513 * hb_set_get_population:
516 * Returns the number of elements in the set.
518 * Return value: The population of @set
523 hb_set_get_population (const hb_set_t *set)
525 return set->get_population ();
532 * Finds the smallest element in the set.
534 * Return value: minimum of @set, or #HB_SET_VALUE_INVALID if @set is empty.
539 hb_set_get_min (const hb_set_t *set)
541 return set->get_min ();
548 * Finds the largest element in the set.
550 * Return value: maximum of @set, or #HB_SET_VALUE_INVALID if @set is empty.
555 hb_set_get_max (const hb_set_t *set)
557 return set->get_max ();
563 * @codepoint: (inout): Input = Code point to query
564 * Output = Code point retrieved
566 * Fetches the next element in @set that is greater than current value of @codepoint.
568 * Set @codepoint to #HB_SET_VALUE_INVALID to get started.
570 * Return value: `true` if there was a next value, `false` otherwise
575 hb_set_next (const hb_set_t *set,
576 hb_codepoint_t *codepoint)
578 return set->next (codepoint);
584 * @codepoint: (inout): Input = Code point to query
585 * Output = Code point retrieved
587 * Fetches the previous element in @set that is lower than current value of @codepoint.
589 * Set @codepoint to #HB_SET_VALUE_INVALID to get started.
591 * Return value: `true` if there was a previous value, `false` otherwise
596 hb_set_previous (const hb_set_t *set,
597 hb_codepoint_t *codepoint)
599 return set->previous (codepoint);
605 * @first: (out): The first code point in the range
606 * @last: (inout): Input = The current last code point in the range
607 * Output = The last code point in the range
609 * Fetches the next consecutive range of elements in @set that
610 * are greater than current value of @last.
612 * Set @last to #HB_SET_VALUE_INVALID to get started.
614 * Return value: `true` if there was a next range, `false` otherwise
619 hb_set_next_range (const hb_set_t *set,
620 hb_codepoint_t *first,
621 hb_codepoint_t *last)
623 return set->next_range (first, last);
627 * hb_set_previous_range:
629 * @first: (inout): Input = The current first code point in the range
630 * Output = The first code point in the range
631 * @last: (out): The last code point in the range
633 * Fetches the previous consecutive range of elements in @set that
634 * are greater than current value of @last.
636 * Set @first to #HB_SET_VALUE_INVALID to get started.
638 * Return value: `true` if there was a previous range, `false` otherwise
643 hb_set_previous_range (const hb_set_t *set,
644 hb_codepoint_t *first,
645 hb_codepoint_t *last)
647 return set->previous_range (first, last);
653 * @codepoint: Outputting codepoints starting after this one.
654 * Use #HB_SET_VALUE_INVALID to get started.
655 * @out: (array length=size): An array of codepoints to write to.
656 * @size: The maximum number of codepoints to write out.
658 * Finds the next element in @set that is greater than @codepoint. Writes out
659 * codepoints to @out, until either the set runs out of elements, or @size
660 * codepoints are written, whichever comes first.
662 * Return value: the number of values written.
667 hb_set_next_many (const hb_set_t *set,
668 hb_codepoint_t codepoint,
672 return set->next_many (codepoint, out, size);