hb-set.cc revision 29ce446d3161b7ea5874352e5f8eb33cd59338c3
10b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod/*
20b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * Copyright © 2012  Google, Inc.
30b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod *
40b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
50b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod *
60b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * Permission is hereby granted, without written agreement and without
70b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
80b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * software and its documentation for any purpose, provided that the
90b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * above copyright notice and the following two paragraphs appear in
100b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * all copies of this software.
110b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod *
120b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
130b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
140b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
150b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
160b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * DAMAGE.
170b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod *
180b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
190b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
200b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
210b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
220b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
230b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod *
240b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod * Google Author(s): Behdad Esfahbod
250b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod */
260b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
270b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod#include "hb-set-private.hh"
280b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
290b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
300b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
316c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod/* Public API */
326c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod
330b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodstatic hb_set_t _hb_set_nil = {
340b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  HB_OBJECT_HEADER_STATIC,
350b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
360b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  {0} /* elts */
370b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod};
380b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
390b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
400b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_t *
410b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_create ()
420b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
430b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  hb_set_t *set;
440b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
450b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  if (!(set = hb_object_create<hb_set_t> ()))
460b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod    return &_hb_set_nil;
470b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
480b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  set->clear ();
490b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
500b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  return set;
510b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
520b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
530b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_t *
540b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_get_empty (void)
550b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
560b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  return &_hb_set_nil;
570b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
580b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
590b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_t *
600b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_reference (hb_set_t *set)
610b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
620b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  return hb_object_reference (set);
630b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
640b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
650b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodvoid
660b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_destroy (hb_set_t *set)
670b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
680b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  if (!hb_object_destroy (set)) return;
690b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
70a5e39fed85e069ba1afbf90408349ad99ceb0e1dBehdad Esfahbod  set->fini ();
71a5e39fed85e069ba1afbf90408349ad99ceb0e1dBehdad Esfahbod
720b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  free (set);
730b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
740b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
750b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_bool_t
760b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_set_user_data (hb_set_t        *set,
770b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod			 hb_user_data_key_t *key,
780b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod			 void *              data,
790b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod			 hb_destroy_func_t   destroy,
800b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod			 hb_bool_t           replace)
810b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
820b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  return hb_object_set_user_data (set, key, data, destroy, replace);
830b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
840b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
850b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodvoid *
860b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_get_user_data (hb_set_t        *set,
870b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod			 hb_user_data_key_t *key)
880b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
890b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  return hb_object_get_user_data (set, key);
900b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
910b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
920b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
930b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_bool_t
949f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbodhb_set_allocation_successful (hb_set_t  *set HB_UNUSED)
950b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
960b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  return TRUE;
970b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
980b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
990b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodvoid
1000b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_clear (hb_set_t *set)
1010b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
1020b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  set->clear ();
1030b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
1040b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
1050b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_bool_t
1066c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_set_empty (hb_set_t *set)
1076c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod{
1086c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod  return set->empty ();
1096c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod}
1106c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod
1116c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_bool_t
1120b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_has (hb_set_t       *set,
1130b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod	    hb_codepoint_t  codepoint)
1140b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
1150b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  return set->has (codepoint);
1160b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
1170b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
1180b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodvoid
1190b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_add (hb_set_t       *set,
1200b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod	    hb_codepoint_t  codepoint)
1210b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
1220b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  set->add (codepoint);
1230b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
1240b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod
1250b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodvoid
1260b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbodhb_set_del (hb_set_t       *set,
1270b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod	    hb_codepoint_t  codepoint)
1280b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod{
1290b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod  set->del (codepoint);
1300b08adb3539f2ec29682456b89c69e89ff5e9c03Behdad Esfahbod}
1316c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod
1326c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_bool_t
1336c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_set_equal (hb_set_t *set,
1346c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod	      hb_set_t *other)
1356c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod{
1366c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod  return set->equal (other);
1376c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod}
1386c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod
1396c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodvoid
1406c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_set_set (hb_set_t *set,
1416c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod	    hb_set_t *other)
1426c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod{
1436c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod  set->set (other);
1446c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod}
1456c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod
1466c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodvoid
1476c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_set_union (hb_set_t *set,
1486c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod	      hb_set_t *other)
1496c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod{
1506c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod  set->union_ (other);
1516c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod}
1526c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod
1536c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodvoid
1546c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_set_intersect (hb_set_t *set,
1556c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod		  hb_set_t *other)
1566c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod{
1576c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod  set->intersect (other);
1586c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod}
1596c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod
1606c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodvoid
1616c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_set_subtract (hb_set_t *set,
1626c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod		 hb_set_t *other)
1636c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod{
1646c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod  set->subtract (other);
1656c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod}
1666c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod
16762c3e111fce0ad34960871134c2eb6da572df303Behdad Esfahbodvoid
16862c3e111fce0ad34960871134c2eb6da572df303Behdad Esfahbodhb_set_symmetric_difference (hb_set_t *set,
16962c3e111fce0ad34960871134c2eb6da572df303Behdad Esfahbod			     hb_set_t *other)
17062c3e111fce0ad34960871134c2eb6da572df303Behdad Esfahbod{
17162c3e111fce0ad34960871134c2eb6da572df303Behdad Esfahbod  set->symmetric_difference (other);
17262c3e111fce0ad34960871134c2eb6da572df303Behdad Esfahbod}
17362c3e111fce0ad34960871134c2eb6da572df303Behdad Esfahbod
1746c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_codepoint_t
1756c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_set_min (hb_set_t *set)
1766c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod{
177f039e79d5438a8fc4a3ec11a387bbfc0f6b83024Behdad Esfahbod  return set->get_min ();
1786c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod}
1796c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod
1806c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_codepoint_t
1816c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbodhb_set_max (hb_set_t *set)
1826c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod{
183f039e79d5438a8fc4a3ec11a387bbfc0f6b83024Behdad Esfahbod  return set->get_max ();
1846c6ccaf575392f6e6bb9a15534026e4ea462705bBehdad Esfahbod}
18529ce446d3161b7ea5874352e5f8eb33cd59338c3Behdad Esfahbod
18629ce446d3161b7ea5874352e5f8eb33cd59338c3Behdad Esfahbodhb_bool_t
18729ce446d3161b7ea5874352e5f8eb33cd59338c3Behdad Esfahbodhb_set_next (hb_set_t       *set,
18829ce446d3161b7ea5874352e5f8eb33cd59338c3Behdad Esfahbod	     hb_codepoint_t *codepoint)
18929ce446d3161b7ea5874352e5f8eb33cd59338c3Behdad Esfahbod{
19029ce446d3161b7ea5874352e5f8eb33cd59338c3Behdad Esfahbod  return set->next (codepoint);
19129ce446d3161b7ea5874352e5f8eb33cd59338c3Behdad Esfahbod}
192