[map] Add 5 methods
diff --git a/src/Makefile.am b/src/Makefile.am
index bd88fa0..1bccc5e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -346,6 +346,7 @@
test-algs \
test-array \
test-iter \
+ test-map \
test-meta \
test-number \
test-ot-tag \
@@ -381,6 +382,10 @@
test_iter_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS)
test_iter_LDADD = $(COMPILED_TESTS_LDADD)
+test_map_SOURCES = test-map.cc hb-static.cc
+test_map_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS)
+test_map_LDADD = $(COMPILED_TESTS_LDADD)
+
test_meta_SOURCES = test-meta.cc hb-static.cc
test_meta_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS)
test_meta_LDADD = $(COMPILED_TESTS_LDADD)
diff --git a/src/hb-map.hh b/src/hb-map.hh
index dcd5267..d7b20f3 100644
--- a/src/hb-map.hh
+++ b/src/hb-map.hh
@@ -39,10 +39,14 @@
V vINVALID = hb_is_pointer (V) ? 0 : hb_is_signed (V) ? hb_int_min (V) : (V) -1>
struct hb_hashmap_t
{
- HB_DELETE_COPY_ASSIGN (hb_hashmap_t);
hb_hashmap_t () { init (); }
~hb_hashmap_t () { fini (); }
+ hb_hashmap_t (const hb_hashmap_t& o) : hb_hashmap_t () { hb_copy (o, *this); }
+ hb_hashmap_t (hb_hashmap_t&& o) : hb_hashmap_t () { hb_swap (*this, o); }
+ hb_hashmap_t& operator= (const hb_hashmap_t&& o) { hb_copy (o, *this); return *this; }
+ hb_hashmap_t& operator= (hb_hashmap_t&& o) { hb_swap (*this, o); return *this; }
+
static_assert (hb_is_integral (K) || hb_is_pointer (K), "");
static_assert (hb_is_integral (V) || hb_is_pointer (V), "");
@@ -70,6 +74,17 @@
unsigned int prime;
item_t *items;
+ friend void swap (hb_hashmap_t& a, hb_hashmap_t& b)
+ {
+ if (unlikely (!a.successful || !b.successful))
+ return;
+ hb_swap (a.successful, b.successful);
+ hb_swap (a.population, b.population);
+ hb_swap (a.occupancy, b.occupancy);
+ hb_swap (a.mask, b.mask);
+ hb_swap (a.prime, b.prime);
+ hb_swap (a.items, b.items);
+ }
void init_shallow ()
{
successful = true;
diff --git a/src/meson.build b/src/meson.build
index ca40176..61b3dce 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -488,6 +488,7 @@
'test-repacker': ['test-repacker.cc', 'hb-static.cc'],
'test-priority-queue': ['test-priority-queue.cc', 'hb-static.cc'],
'test-iter': ['test-iter.cc', 'hb-static.cc'],
+ 'test-map': ['test-map.cc', 'hb-static.cc'],
'test-meta': ['test-meta.cc', 'hb-static.cc'],
'test-number': ['test-number.cc', 'hb-number.cc'],
'test-ot-tag': ['hb-ot-tag.cc'],
diff --git a/src/test-map.cc b/src/test-map.cc
new file mode 100644
index 0000000..b685530
--- /dev/null
+++ b/src/test-map.cc
@@ -0,0 +1,68 @@
+/*
+ * Copyright © 2021 Behdad Esfahbod
+ *
+ * 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.
+ *
+ */
+
+#include "hb.hh"
+#include "hb-map.hh"
+
+
+int
+main (int argc, char **argv)
+{
+
+ /* Test copy constructor. */
+ {
+ hb_map_t v1;
+ v1.set (1, 2);
+ hb_map_t v2 {v1};
+ assert (v1.get_population () == 1);
+ assert (v2.get_population () == 1);
+ assert (v1[1] == 2);
+ assert (v2[1] == 2);
+ }
+
+ /* Test copy assignment. */
+ {
+ hb_map_t v1;
+ v1.set (1, 2);
+ hb_map_t v2 = v1;
+ assert (v1.get_population () == 1);
+ assert (v2.get_population () == 1);
+ assert (v1[1] == 2);
+ assert (v2[1] == 2);
+ }
+
+ /* Test move constructor. */
+ {
+ hb_map_t v {hb_map_t {}};
+ }
+
+ /* Test move assignment. */
+ {
+ hb_map_t v;
+ v = hb_map_t {};
+ }
+
+ return 0;
+}
diff --git a/src/test-set.cc b/src/test-set.cc
index 531df17..5c28beb 100644
--- a/src/test-set.cc
+++ b/src/test-set.cc
@@ -59,6 +59,7 @@
v = hb_set_t {1, 2};
assert (v.get_population () == 2);
}
+
/* Test initializing set from iterable. */
{
hb_set_t s;
diff --git a/src/test-vector.cc b/src/test-vector.cc
index 7dacec8..6418a84 100644
--- a/src/test-vector.cc
+++ b/src/test-vector.cc
@@ -77,6 +77,7 @@
assert (v[0] == 1);
assert (v[1] == 2);
}
+
/* Test initializing from iterable. */
{
hb_set_t s;