From f41959ccb2d9d4c722fe8fc3351401d53bcf4900 Mon Sep 17 00:00:00 2001 From: Manjunath Kudlur Date: Fri, 6 Nov 2015 16:27:58 -0800 Subject: TensorFlow: Initial commit of TensorFlow library. TensorFlow is an open source software library for numerical computation using data flow graphs. Base CL: 107276108 --- tensorflow/core/graph/edgeset.cc | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tensorflow/core/graph/edgeset.cc (limited to 'tensorflow/core/graph/edgeset.cc') diff --git a/tensorflow/core/graph/edgeset.cc b/tensorflow/core/graph/edgeset.cc new file mode 100644 index 0000000000..83293c7b4e --- /dev/null +++ b/tensorflow/core/graph/edgeset.cc @@ -0,0 +1,56 @@ +#include "tensorflow/core/graph/edgeset.h" + +namespace tensorflow { + +std::pair EdgeSet::insert(value_type value) { + RegisterMutation(); + const_iterator ci; + ci.Init(this); + auto s = get_set(); + if (!s) { + for (int i = 0; i < kInline; i++) { + if (ptrs_[i] == value) { + ci.array_iter_ = &ptrs_[i]; + return std::make_pair(ci, false); + } + } + for (int i = 0; i < kInline; i++) { + if (ptrs_[i] == nullptr) { + ptrs_[i] = value; + ci.array_iter_ = &ptrs_[i]; + return std::make_pair(ci, true); + } + } + // array is full. convert to set. + s = new std::set; + for (int i = 0; i < kInline; i++) { + s->insert(static_cast(ptrs_[i])); + } + ptrs_[0] = this; + ptrs_[1] = s; + // fall through. + } + auto p = s->insert(value); + ci.tree_iter_ = p.first; + return std::make_pair(ci, p.second); +} + +EdgeSet::size_type EdgeSet::erase(key_type key) { + RegisterMutation(); + auto s = get_set(); + if (!s) { + for (int i = 0; i < kInline; i++) { + if (ptrs_[i] == key) { + size_t n = size(); + ptrs_[i] = ptrs_[n - 1]; + ptrs_[n - 1] = nullptr; + return 1; + } + } + return 0; + } else { + return s->erase(key); + } +} + +} // namespace tensorflow -- cgit v1.2.3