| 430 | |
| 431 | template<typename T> |
| 432 | inline int DictEncoder<T>::Put(const T& value) { |
| 433 | NodeIndex* bucket = &buckets_[Hash(value) & (HASH_TABLE_SIZE - 1)]; |
| 434 | NodeIndex i = *bucket; |
| 435 | // Look for the value in the dictionary. |
| 436 | while (i != Node::INVALID_INDEX) { |
| 437 | const Node* n = &nodes_[i]; |
| 438 | if (LIKELY(n->value == value)) { |
| 439 | // Value already in dictionary. |
| 440 | buffered_indices_.push_back(i); |
| 441 | return 0; |
| 442 | } |
| 443 | i = n->next; |
| 444 | } |
| 445 | // Value not found. Add it to the dictionary if there's space. |
| 446 | i = nodes_.size(); |
| 447 | if (UNLIKELY(i >= Node::INVALID_INDEX)) return -1; |
| 448 | buffered_indices_.push_back(i); |
| 449 | return AddToTable(value, bucket); |
| 450 | } |
| 451 | |
| 452 | template<typename T> |
| 453 | inline uint32_t DictEncoder<T>::Hash(const T& value) const { |