| 18 | namespace tensorflow { |
| 19 | |
| 20 | std::pair<EdgeSet::const_iterator, bool> EdgeSet::insert(value_type value) { |
| 21 | RegisterMutation(); |
| 22 | const_iterator ci; |
| 23 | ci.Init(this); |
| 24 | auto s = get_set(); |
| 25 | if (!s) { |
| 26 | for (int i = 0; i < kInline; i++) { |
| 27 | if (ptrs_[i] == value) { |
| 28 | ci.array_iter_ = &ptrs_[i]; |
| 29 | return std::make_pair(ci, false); |
| 30 | } |
| 31 | } |
| 32 | for (int i = 0; i < kInline; i++) { |
| 33 | if (ptrs_[i] == nullptr) { |
| 34 | ptrs_[i] = value; |
| 35 | ci.array_iter_ = &ptrs_[i]; |
| 36 | return std::make_pair(ci, true); |
| 37 | } |
| 38 | } |
| 39 | // array is full. convert to set. |
| 40 | s = new gtl::FlatSet<const Edge*>; |
| 41 | s->insert(reinterpret_cast<const Edge**>(std::begin(ptrs_)), |
| 42 | reinterpret_cast<const Edge**>(std::end(ptrs_))); |
| 43 | ptrs_[0] = this; |
| 44 | ptrs_[1] = s; |
| 45 | // fall through. |
| 46 | } |
| 47 | auto p = s->insert(value); |
| 48 | ci.tree_iter_ = p.first; |
| 49 | return std::make_pair(ci, p.second); |
| 50 | } |
| 51 | |
| 52 | EdgeSet::size_type EdgeSet::erase(key_type key) { |
| 53 | RegisterMutation(); |