| 933 | |
| 934 | template <typename Spec> |
| 935 | bool VMap<Spec>::find(VRef<K> key, VRef<V> &value) { |
| 936 | size_t hash = Spec::hash(key.as_ptr()); |
| 937 | size_t b = hash & (_nbuckets - 1); |
| 938 | _lock_bucket(b); |
| 939 | VRef<Node> node = _buckets[b]; |
| 940 | VRef<Node> last = vnull<Node>(); |
| 941 | while (!node.is_null()) { |
| 942 | Node *node_ptr = node.as_ptr(); |
| 943 | if (hash == node_ptr->hash |
| 944 | && Spec::equal(key.as_ptr(), node_ptr->key.as_ptr())) { |
| 945 | value = node_ptr->value; |
| 946 | // move to front |
| 947 | if (!last.is_null()) { |
| 948 | last->next = node_ptr->next; |
| 949 | node_ptr->next = _buckets[b]; |
| 950 | } |
| 951 | _buckets[b] = node; |
| 952 | _unlock_bucket(b); |
| 953 | return true; |
| 954 | } |
| 955 | last = node; |
| 956 | node = node->next; |
| 957 | } |
| 958 | _unlock_bucket(b); |
| 959 | return false; |
| 960 | } |
| 961 | |
| 962 | struct DictSpec { |
| 963 | typedef VString Key; |
no test coverage detected