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

Method hasKey

kernel/linear_algebra/CacheImplementation.h:54–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52
53template<class KeyClass, class ValueClass>
54bool Cache<KeyClass, ValueClass>::hasKey (const KeyClass& key) const
55{
56 _itKey = _key.end(); // referring to past-the-end element in the list
57 typename std::list<KeyClass>::const_iterator itKey;
58 _itValue = _value.begin();
59 /* As _key is a sorted list, the following could actually be implemented
60 in logarithmic time, by bisection. However, for lists this does not work.
61 But often, we can still terminate the linear loop before having visited
62 all elements. */
63 for (itKey = _key.begin(); itKey != _key.end(); itKey++)
64 {
65 int c = key.compare(*itKey);
66 if (c == 0)
67 {
68 _itKey = itKey;
69 return true;
70 }
71 if (c == -1) return false;
72 _itValue++;
73 }
74 return false;
75}
76
77template<class KeyClass, class ValueClass>
78ValueClass Cache<KeyClass, ValueClass>::getValue (const KeyClass& /*key*/) const

Callers 1

Calls 3

endMethod · 0.45
beginMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected