diff options
author | Manjunath Kudlur <keveman@gmail.com> | 2015-11-06 16:27:58 -0800 |
---|---|---|
committer | Manjunath Kudlur <keveman@gmail.com> | 2015-11-06 16:27:58 -0800 |
commit | f41959ccb2d9d4c722fe8fc3351401d53bcf4900 (patch) | |
tree | ef0ca22cb2a5ac4bdec9d080d8e0788a53ed496d /tensorflow/core/graph/edgeset.cc |
TensorFlow: Initial commit of TensorFlow library.
TensorFlow is an open source software library for numerical computation
using data flow graphs.
Base CL: 107276108
Diffstat (limited to 'tensorflow/core/graph/edgeset.cc')
-rw-r--r-- | tensorflow/core/graph/edgeset.cc | 56 |
1 files changed, 56 insertions, 0 deletions
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::const_iterator, bool> 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<const Edge*>; + for (int i = 0; i < kInline; i++) { + s->insert(static_cast<const Edge*>(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 |