3 // Copyright (C) 2005-2016 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
23 // Permission to use, copy, modify, sell, and distribute this software
24 // is hereby granted without fee, provided that the above copyright
25 // notice appears in all copies, and that both that copyright notice
26 // and this permission notice appear in supporting documentation. None
27 // of the above authors, nor IBM Haifa Research Laboratories, make any
28 // representation about the suitability of this software for any
29 // purpose. It is provided "as is" without express or implied
33 * @file ds_string_form.hpp
34 * Transforms containers into string form.
37 #ifndef PB_DS_DS_STRING_FORM_HPP
38 #define PB_DS_DS_STRING_FORM_HPP
41 #include <ext/pb_ds/tag_and_trait.hpp>
42 #include <common_type/assoc/detail/list_update_policy_string_form.hpp>
43 #include <common_type/assoc/detail/comb_hash_fn_string_form.hpp>
44 #include <common_type/assoc/detail/resize_policy_string_form.hpp>
45 #include <common_type/assoc/detail/probe_fn_string_form.hpp>
46 #include <common_type/assoc/detail/tree_supports_order_statistics.hpp>
47 #include <common_type/assoc/detail/trie_supports_order_statistics.hpp>
48 #include <common_type/assoc/detail/trie_supports_prefix_search.hpp>
49 #include <common_type/assoc/detail/store_hash_string_form.hpp>
58 template<typename Cntnr, class Tag>
59 struct ds_string_form;
61 template<typename Cntnr>
62 struct ds_string_form<Cntnr, __gnu_pbds::cc_hash_tag>
68 comb_hash_fn_string_form<typename Cntnr::comb_hash_fn>::name() +
69 resize_policy_string_form<typename Cntnr::resize_policy>::name() +
70 store_hash_string_form<Cntnr::store_hash>::name());
76 const std::string comb_hash_fn_desc =
77 comb_hash_fn_string_form<typename Cntnr::comb_hash_fn>::desc();
79 const std::string resize_policy_desc =
80 resize_policy_string_form<typename Cntnr::resize_policy>::desc();
82 const std::string store_hash_desc =
83 store_hash_string_form<Cntnr::store_hash>::desc();
85 return (make_xml_tag("type", "value", "cc_hash_table", comb_hash_fn_desc + resize_policy_desc + store_hash_desc));
89 template<typename Cntnr>
90 struct ds_string_form<Cntnr, __gnu_pbds::gp_hash_tag>
96 comb_hash_fn_string_form<typename Cntnr::comb_probe_fn>::name() +
97 probe_fn_string_form<typename Cntnr::probe_fn>::name() +
98 resize_policy_string_form<typename Cntnr::resize_policy>::name() +
99 store_hash_string_form<Cntnr::store_hash>::name());
105 const std::string comb_probe_fn_desc =
106 comb_hash_fn_string_form<typename Cntnr::comb_probe_fn>::desc();
108 const std::string probe_fn_desc =
109 probe_fn_string_form<typename Cntnr::probe_fn>::desc();
111 const std::string resize_policy_desc =
112 resize_policy_string_form<typename Cntnr::resize_policy>::desc();
114 const std::string store_hash_desc =
115 store_hash_string_form<Cntnr::store_hash>::desc();
117 return make_xml_tag("type", "value", "gp_hash_table",
118 comb_probe_fn_desc + probe_fn_desc + resize_policy_desc + store_hash_desc);
122 template<typename Cntnr>
123 struct tree_ds_string_form
126 name(const std::string container_category_str)
128 if (tree_supports_order_statistics<Cntnr>::value)
129 return (container_category_str + "ost_");
130 return container_category_str;
134 desc(const std::string container_category_str)
136 const std::string category_str =
137 make_xml_tag("Tag", "value", container_category_str);
139 const std::string node_update_str =
140 make_xml_tag("Node_Update",
141 "value",(tree_supports_order_statistics<Cntnr>::value ?
142 "tree_order_statistics_node_update" : "null_node_update"));
144 return make_xml_tag("type", "value", "tree", category_str + node_update_str);
148 template<typename Cntnr>
149 struct ds_string_form<Cntnr, __gnu_pbds::rb_tree_tag>
150 : private tree_ds_string_form<Cntnr>
153 typedef tree_ds_string_form< Cntnr> base_type;
158 { return base_type::name("rb_tree_"); }
162 { return base_type::desc("rb_tree_tag"); }
165 template<typename Cntnr>
166 struct ds_string_form<Cntnr, __gnu_pbds::splay_tree_tag>
167 : private tree_ds_string_form<Cntnr>
170 typedef tree_ds_string_form< Cntnr> base_type;
175 { return base_type::name("splay_tree_"); }
179 { return base_type::desc("splay_tree_tag"); }
182 template<typename Cntnr>
183 struct ds_string_form<Cntnr, __gnu_pbds::ov_tree_tag>
184 : private tree_ds_string_form<Cntnr>
187 typedef tree_ds_string_form< Cntnr> base_type;
192 { return (base_type::name("ov_tree_")); }
196 { return (base_type::desc("ov_tree_tag")); }
199 template<typename Cntnr>
200 struct ds_string_form<Cntnr, __gnu_pbds::list_update_tag>
206 lu_policy_string_form<typename Cntnr::update_policy>::name());
212 return make_xml_tag("type", "value", "list_update",
213 lu_policy_string_form<typename Cntnr::update_policy>::desc());
217 template<typename Cntnr>
218 struct ds_string_form<Cntnr, __gnu_pbds::pat_trie_tag>
223 if (trie_supports_order_statistics<Cntnr>::value)
224 return ("pat_trie_ost_");
226 if (trie_supports_prefix_search<Cntnr>::value)
227 return ("pat_trie_prs_");
229 return ("pat_trie_");
235 std::string category_s = make_xml_tag("Tag", "value", "pat_trie_tag");
237 if (trie_supports_order_statistics<Cntnr>::value)
238 s = "trie_order_statistics_node_update";
239 else if (trie_supports_prefix_search<Cntnr>::value)
240 s = "trie_prefix_search_node_update";
242 s = "null_node_update";
243 std::string node_s = make_xml_tag("Node_Update", "value", s);
244 return make_xml_tag("type", "value", "trie", category_s + node_s);
248 } // namespace detail
252 } // namespace __gnu_pbds
254 #endif // #ifndef PB_DS_DS_STRING_FORM_HPP