MCPcopy Create free account
hub / github.com/Singular/Singular / find

Method find

kernel/oswrapper/vspace.h:935–960  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

933
934template <typename Spec>
935bool 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
962struct DictSpec {
963 typedef VString Key;

Callers 1

traverse_tailFunction · 0.45

Calls 2

as_ptrMethod · 0.45
is_nullMethod · 0.45

Tested by

no test coverage detected