| 228 | } |
| 229 | |
| 230 | Status DoInsert(const Tensor& keys, const Tensor& values) override { |
| 231 | if (!table_) { |
| 232 | return errors::FailedPrecondition("HashTable is not prepared."); |
| 233 | } |
| 234 | |
| 235 | const auto key_values = keys.flat<K>(); |
| 236 | const auto value_values = values.flat<V>(); |
| 237 | for (int64 i = 0; i < key_values.size(); ++i) { |
| 238 | const K key = SubtleMustCopyIfIntegral(key_values(i)); |
| 239 | const V value = SubtleMustCopyIfIntegral(value_values(i)); |
| 240 | const V& previous_value = gtl::LookupOrInsert(table_.get(), key, value); |
| 241 | if (previous_value != value) { |
| 242 | return errors::FailedPrecondition( |
| 243 | "HashTable has different value for same key. Key ", key, " has ", |
| 244 | previous_value, " and trying to add value ", value); |
| 245 | } |
| 246 | } |
| 247 | return Status::OK(); |
| 248 | } |
| 249 | |
| 250 | Status DoFind(const Tensor& key, Tensor* value, |
| 251 | const Tensor& default_value) override { |
nothing calls this directly
no test coverage detected