Get the previous element by the key.
- Parameters
-
- Returns
- Returns the previous element.
- Note
- It's slow, so do not use it unnecessary.
@breif Returns nullptr if not find key.
Returns nullptr if not a prev value;
Iter the list.
Definition at line 278 of file LinkedUnorderedMap.h.
279 {
283 if (!
has_key(key))
return nullptr;
284
285 std::shared_lock<std::shared_mutex> lock(
m_Mutex);
286
290 if (key ==
m_Keys.front())
return nullptr;
291
295 for (
auto it =
m_Keys.begin(); it !=
m_Keys.end(); ++it)
296 {
297 if (*it == key)
298 {
299 return &(*std::prev(it));
300 }
301 }
302
303 return nullptr;
304 }
std::shared_mutex m_Mutex
Mutex for this container.
bool has_key(const K &key)
Determine whether the key is in the container.
std::list< K > m_Keys
The container keeps iter in order.
References scl::linked_unordered_map< K, V >::has_key().