2626namespace datasketches {
2727
2828using aos_sketch = update_array_of_strings_tuple_sketch<>;
29- using array_of_strings = array<std::string>;
29+ using types = array_of_strings_types<std::allocator<char >>;
30+ using array_of_strings = types::array_of_strings;
31+ using string_allocator = types::string_allocator;
32+ using string_type = types::string_type;
33+ using array_allocator = types::array_allocator;
3034
3135static array_of_strings make_array (std::initializer_list<std::string> items) {
32- array_of_strings array (static_cast <uint8_t >(items.size ()), " " );
36+ const string_type empty{string_allocator ()};
37+ array_of_strings array (static_cast <uint8_t >(items.size ()), empty, array_allocator ());
3338 size_t i = 0 ;
3439 for (const auto & item: items) {
35- array[static_cast <uint8_t >(i)] = item;
40+ array[static_cast <uint8_t >(i)] = string_type ( item. data (), item. size (), string_allocator ()) ;
3641 ++i;
3742 }
3843 return array;
@@ -43,10 +48,13 @@ TEST_CASE("aos sketch generate one value", "[serialize_for_java]") {
4348 for (const unsigned n: n_arr) {
4449 auto sketch = aos_sketch::builder ().build ();
4550 for (unsigned i = 0 ; i < n; ++i) {
46- array_of_strings key (1 , " " );
47- key[0 ] = std::to_string (i);
48- array_of_strings value (1 , " " );
49- value[0 ] = " value" + std::to_string (i);
51+ const string_type empty{string_allocator ()};
52+ array_of_strings key (1 , empty, array_allocator ());
53+ const std::string key_value = std::to_string (i);
54+ key[0 ] = string_type (key_value.data (), key_value.size (), string_allocator ());
55+ array_of_strings value (1 , empty, array_allocator ());
56+ const std::string value_str = " value" + std::to_string (i);
57+ value[0 ] = string_type (value_str.data (), value_str.size (), string_allocator ());
5058 sketch.update (hash_array_of_strings_key (key), value);
5159 }
5260 REQUIRE (sketch.is_empty () == (n == 0 ));
@@ -61,12 +69,17 @@ TEST_CASE("aos sketch generate three values", "[serialize_for_java]") {
6169 for (const unsigned n: n_arr) {
6270 auto sketch = aos_sketch::builder ().build ();
6371 for (unsigned i = 0 ; i < n; ++i) {
64- array_of_strings key (1 , " " );
65- key[0 ] = std::to_string (i);
66- array_of_strings value (3 , " " );
67- value[0 ] = " a" + std::to_string (i);
68- value[1 ] = " b" + std::to_string (i);
69- value[2 ] = " c" + std::to_string (i);
72+ const string_type empty{string_allocator ()};
73+ array_of_strings key (1 , empty, array_allocator ());
74+ const std::string key_value = std::to_string (i);
75+ key[0 ] = string_type (key_value.data (), key_value.size (), string_allocator ());
76+ array_of_strings value (3 , empty, array_allocator ());
77+ const std::string value_a = " a" + std::to_string (i);
78+ const std::string value_b = " b" + std::to_string (i);
79+ const std::string value_c = " c" + std::to_string (i);
80+ value[0 ] = string_type (value_a.data (), value_a.size (), string_allocator ());
81+ value[1 ] = string_type (value_b.data (), value_b.size (), string_allocator ());
82+ value[2 ] = string_type (value_c.data (), value_c.size (), string_allocator ());
7083 sketch.update (hash_array_of_strings_key (key), value);
7184 }
7285 REQUIRE (sketch.is_empty () == (n == 0 ));
@@ -82,9 +95,10 @@ TEST_CASE("aos sketch generate non-empty no entries", "[serialize_for_java]") {
8295 .set_resize_factor (resize_factor::X8 )
8396 .set_p (0 .01f )
8497 .build ();
85- array_of_strings key (1 , " " );
98+ const string_type empty{string_allocator ()};
99+ array_of_strings key (1 , empty, array_allocator ());
86100 key[0 ] = " key1" ;
87- array_of_strings value (1 , " " );
101+ array_of_strings value (1 , empty, array_allocator () );
88102 value[0 ] = " value1" ;
89103 sketch.update (hash_array_of_strings_key (key), value);
90104 REQUIRE_FALSE (sketch.is_empty ());
@@ -98,11 +112,15 @@ TEST_CASE("aos sketch generate multi key strings", "[serialize_for_java]") {
98112 for (const unsigned n: n_arr) {
99113 auto sketch = aos_sketch::builder ().build ();
100114 for (unsigned i = 0 ; i < n; ++i) {
101- array_of_strings key (2 , " " );
102- key[0 ] = " key" + std::to_string (i);
103- key[1 ] = " subkey" + std::to_string (i % 10 );
104- array_of_strings value (1 , " " );
105- value[0 ] = " value" + std::to_string (i);
115+ const string_type empty{string_allocator ()};
116+ array_of_strings key (2 , empty, array_allocator ());
117+ const std::string key0 = " key" + std::to_string (i);
118+ const std::string key1 = " subkey" + std::to_string (i % 10 );
119+ key[0 ] = string_type (key0.data (), key0.size (), string_allocator ());
120+ key[1 ] = string_type (key1.data (), key1.size (), string_allocator ());
121+ array_of_strings value (1 , empty, array_allocator ());
122+ const std::string value_str = " value" + std::to_string (i);
123+ value[0 ] = string_type (value_str.data (), value_str.size (), string_allocator ());
106124 sketch.update (hash_array_of_strings_key (key), value);
107125 }
108126 REQUIRE (sketch.is_empty () == (n == 0 ));
0 commit comments