summaryrefslogtreecommitdiffstats
path: root/src/include/util
diff options
context:
space:
mode:
authorMatt Derksen <v2cibmd@us.ibm.com>2016-05-16 16:36:51 -0500
committerBill Hoffa <wghoffa@us.ibm.com>2016-06-02 09:23:44 -0500
commit5c59bb5b9c89a173c6771d4db84abb53f4615d93 (patch)
tree2f20a3174c612c227e1a3f781b8c351d97e9e5f3 /src/include/util
parent6f5df0cc3724b5dd046e2dedc33036853289c840 (diff)
downloadtalos-hostboot-5c59bb5b9c89a173c6771d4db84abb53f4615d93.tar.gz
talos-hostboot-5c59bb5b9c89a173c6771d4db84abb53f4615d93.zip
Implement std::map::emplace()
Change-Id: Id3f42ac3e5edf6c65c420e60ac69d649cbaa1ed0 RTC:153697 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/24631 Reviewed-by: Christian R. Geddes <crgeddes@us.ibm.com> Tested-by: Jenkins Server Tested-by: FSP CI Jenkins Reviewed-by: A. P. Williams III <iawillia@us.ibm.com> Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src/include/util')
-rw-r--r--src/include/util/impl/splaytree.H36
-rw-r--r--src/include/util/impl/stlmap.H27
2 files changed, 60 insertions, 3 deletions
diff --git a/src/include/util/impl/splaytree.H b/src/include/util/impl/splaytree.H
index 11c801135..9e64cbfc5 100644
--- a/src/include/util/impl/splaytree.H
+++ b/src/include/util/impl/splaytree.H
@@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
-/* Contributors Listed Below - COPYRIGHT 2012,2015 */
+/* Contributors Listed Below - COPYRIGHT 2012,2016 */
/* [+] International Business Machines Corp. */
/* */
/* */
@@ -64,6 +64,7 @@
#include <functional>
#include <new>
#include <stdint.h>
+#include <utility>
namespace Util
{
@@ -113,12 +114,41 @@ namespace Util
{
}
+
+ /** Variadic copy constructor from a Node.
+ *
+ * Initializes the node-links and copies the data storage area
+ * from the copied nodes.
+ *
+ */
+ template <typename... Args> explicit Node(Args&&... args)
+ {
+ parent = child[LEFT] = child[RIGHT] = NULL;
+ new (&data) T(std::forward<Args>(args)...);
+ }
+
+ /** Copy constructor from a Node.
+ *
+ * Initializes the node-links and copies the data storage area
+ * from the copied node.
+ *
+ * non-const form - needed for variadic arguments form above
+ */
+ explicit Node(Node<T>&r)
+ {
+ // Don't want to copy the links out of the other node because
+ // they're from a different tree.
+ parent = child[LEFT] = child[RIGHT] = NULL;
+
+ new (&data) T(r.data);
+ };
+
/** Copy constructor from a Node.
*
* Initializes the node-links and copies the data storage area
* from the copied node.
*/
- explicit Node(const Node<T>& r)
+ explicit Node(const Node<T>&r)
{
// Don't want to copy the links out of the other node because
// they're from a different tree.
@@ -139,6 +169,8 @@ namespace Util
new (&data) T(v);
};
+
+
/** Access the data storage area as a T&. */
T& data_T()
{
diff --git a/src/include/util/impl/stlmap.H b/src/include/util/impl/stlmap.H
index 392762892..cdf5824e4 100644
--- a/src/include/util/impl/stlmap.H
+++ b/src/include/util/impl/stlmap.H
@@ -5,7 +5,9 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
-/* COPYRIGHT International Business Machines Corp. 2012,2014 */
+/* Contributors Listed Below - COPYRIGHT 2012,2016 */
+/* [+] International Business Machines Corp. */
+/* */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
@@ -38,6 +40,7 @@
#include <util/traits/remove_const.H>
#include <algorithm>
+
#ifndef __UTIL_SPLAYTREE_NS
#define __UTIL_SPLAYTREE_NS ::Util::__Util_SplayTree_Impl
#endif
@@ -329,6 +332,28 @@ namespace Util
return (result.first)->second;
}
+ template <class... Args>
+ std::pair <iterator,bool> emplace ( Args&&... args )
+ {
+ _Node *p = new _Node(std::forward<Args>(args)...);
+
+ _Tree::node * hint_node = nullptr;
+
+ bool rc = iv_tree.find_hint((_Tree::node*)p, hint_node);
+ if (!rc)
+ {
+ // node not found, so insert new one
+ iv_tree.insert((_Tree::node*)p);
+ return make_pair(iterator(_TreeItr(&iv_tree, (_Tree::node*)p)), true);
+ }
+ else
+ {
+ // node already exists, delete new one
+ delete p;
+ return make_pair(iterator(_TreeItr(&iv_tree, (_Tree::node*)hint_node)), false);
+ }
+ }
+
std::pair<iterator,bool> insert(const value_type& x)
{
_Tree::node* n = NULL;
OpenPOWER on IntegriCloud