| 904 | |
| 905 | template <typename Spec> |
| 906 | bool VMap<Spec>::remove(VRef<K> key, VRef<K> &oldkey, VRef<V> &oldvalue) { |
| 907 | size_t hash = Spec::hash(key.as_ptr()); |
| 908 | size_t b = hash & (_nbuckets - 1); |
| 909 | _lock_bucket(b); |
| 910 | VRef<Node> node = _buckets[b]; |
| 911 | VRef<Node> last = vnull<Node>(); |
| 912 | while (!node.is_null()) { |
| 913 | Node *node_ptr = node.as_ptr(); |
| 914 | if (hash == node_ptr->hash |
| 915 | && Spec::equal(key.as_ptr(), node_ptr->key.as_ptr())) { |
| 916 | oldkey = node_ptr->key; |
| 917 | oldvalue = node_ptr->value; |
| 918 | // remove from list |
| 919 | if (last.is_null()) { |
| 920 | _buckets[b] = node_ptr->next; |
| 921 | } else { |
| 922 | last->next = node_ptr->next; |
| 923 | } |
| 924 | _unlock_bucket(b); |
| 925 | return true; |
| 926 | } |
| 927 | last = node; |
| 928 | node = node->next; |
| 929 | } |
| 930 | _unlock_bucket(b); |
| 931 | return false; |
| 932 | } |
| 933 | |
| 934 | template <typename Spec> |
| 935 | bool VMap<Spec>::find(VRef<K> key, VRef<V> &value) { |