Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Oct 1, 2023
1 parent 7f4a81c commit d3993c3
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 66 deletions.
12 changes: 6 additions & 6 deletions include/momo/HashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -794,13 +794,13 @@ class HashMap
return mHashSet.Remove(key);
}

template<typename PairPredicate>
internal::EnableIf<internal::IsInvocable<const PairPredicate&, bool, const Key&, const Value&>::value,
size_t> Remove(const PairPredicate& pairPred)
template<typename PairFilter>
internal::EnableIf<internal::IsInvocable<const PairFilter&, bool, const Key&, const Value&>::value,
size_t> Remove(const PairFilter& pairFilter)
{
auto itemPred = [&pairPred] (const KeyValuePair& item)
{ return pairPred(*item.GetKeyPtr(), *static_cast<const Value*>(item.GetValuePtr())); };
return mHashSet.Remove(itemPred);
auto itemFilter = [&pairFilter] (const KeyValuePair& item)
{ return pairFilter(*item.GetKeyPtr(), *static_cast<const Value*>(item.GetValuePtr())); };
return mHashSet.Remove(itemFilter);
}

ExtractedPair Extract(ConstPosition pos)
Expand Down
8 changes: 4 additions & 4 deletions include/momo/HashMultiMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1063,15 +1063,15 @@ class HashMultiMap
return pvMakeIterator(KeyIteratorProxy(hashMapIter), valueIndex, true);
}

template<typename PairPredicate>
internal::EnableIf<internal::IsInvocable<const PairPredicate&, bool, const Key&, const Value&>::value,
size_t> Remove(const PairPredicate& pairPred)
template<typename PairFilter>
internal::EnableIf<internal::IsInvocable<const PairFilter&, bool, const Key&, const Value&>::value,
size_t> Remove(const PairFilter& pairFilter)
{
size_t initValueCount = mValueCount;
Iterator iter = GetBegin();
while (!!iter)
{
if (pairPred(iter->key, static_cast<const Value&>(iter->value)))
if (pairFilter(iter->key, static_cast<const Value&>(iter->value)))
iter = Remove(iter);
else
++iter;
Expand Down
8 changes: 4 additions & 4 deletions include/momo/HashSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,15 +873,15 @@ class HashSet
return true;
}

template<typename Predicate>
internal::EnableIf<internal::IsInvocable<const Predicate&, bool, const Item&>::value,
size_t> Remove(const Predicate& pred)
template<typename ItemFilter>
internal::EnableIf<internal::IsInvocable<const ItemFilter&, bool, const Item&>::value,
size_t> Remove(const ItemFilter& itemFilter)
{
size_t initCount = GetCount();
ConstIterator iter = GetBegin();
while (!!iter)
{
if (pred(*iter))
if (itemFilter(*iter))
iter = Remove(iter);
else
++iter;
Expand Down
12 changes: 6 additions & 6 deletions include/momo/TreeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,13 +712,13 @@ class TreeMap
return mTreeSet.Remove(key);
}

template<typename PairPredicate>
internal::EnableIf<internal::IsInvocable<const PairPredicate&, bool, const Key&, const Value&>::value,
size_t> Remove(const PairPredicate& pairPred)
template<typename PairFilter>
internal::EnableIf<internal::IsInvocable<const PairFilter&, bool, const Key&, const Value&>::value,
size_t> Remove(const PairFilter& pairFilter)
{
auto itemPred = [&pairPred] (const KeyValuePair& item)
{ return pairPred(*item.GetKeyPtr(), *static_cast<const Value*>(item.GetValuePtr())); };
return mTreeSet.Remove(itemPred);
auto itemFilter = [&pairFilter] (const KeyValuePair& item)
{ return pairFilter(*item.GetKeyPtr(), *static_cast<const Value*>(item.GetValuePtr())); };
return mTreeSet.Remove(itemFilter);
}

ExtractedPair Extract(ConstIterator iter)
Expand Down
8 changes: 4 additions & 4 deletions include/momo/TreeSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,15 +925,15 @@ class TreeSet
return remCount;
}

template<typename Predicate>
internal::EnableIf<internal::IsInvocable<const Predicate&, bool, const Item&>::value,
size_t> Remove(const Predicate& pred)
template<typename ItemFilter>
internal::EnableIf<internal::IsInvocable<const ItemFilter&, bool, const Item&>::value,
size_t> Remove(const ItemFilter& itemFilter)
{
size_t initCount = GetCount();
ConstIterator iter = GetBegin();
while (iter != GetEnd())
{
if (pred(*iter))
if (itemFilter(*iter))
iter = Remove(iter);
else
++iter;
Expand Down
20 changes: 10 additions & 10 deletions include/momo/stdish/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -958,12 +958,12 @@ class map : public internal::map_base<TKey, TMapped, TLessFunc, TAllocator, TTre
return pvInsertOrAssign(hint, key, std::forward<MappedArg>(mappedArg)).first;
}

template<typename Predicate>
friend size_type erase_if(map& cont, const Predicate& pred)
template<typename ValueFilter>
friend size_type erase_if(map& cont, const ValueFilter& valueFilter)
{
auto pairPred = [&pred] (const key_type& key, const mapped_type& mapped)
{ return pred(const_reference(key, mapped)); };
return cont.get_nested_container().Remove(pairPred);
auto pairFilter = [&valueFilter] (const key_type& key, const mapped_type& mapped)
{ return valueFilter(const_reference(key, mapped)); };
return cont.get_nested_container().Remove(pairFilter);
}

private:
Expand Down Expand Up @@ -1094,12 +1094,12 @@ class multimap : public internal::map_base<TKey, TMapped, TLessFunc, TAllocator,
return BaseMap::emplace(std::forward<ValueArgs>(valueArgs)...).first;
}

template<typename Predicate>
friend size_type erase_if(multimap& cont, const Predicate& pred)
template<typename ValueFilter>
friend size_type erase_if(multimap& cont, const ValueFilter& valueFilter)
{
auto pairPred = [&pred] (const key_type& key, const mapped_type& mapped)
{ return pred(const_reference(key, mapped)); };
return cont.get_nested_container().Remove(pairPred);
auto pairFilter = [&valueFilter] (const key_type& key, const mapped_type& mapped)
{ return valueFilter(const_reference(key, mapped)); };
return cont.get_nested_container().Remove(pairFilter);
}
};

Expand Down
12 changes: 6 additions & 6 deletions include/momo/stdish/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,10 @@ class set
return mTreeSet.Remove(key);
}

template<typename Predicate>
friend size_type erase_if(set& cont, const Predicate& pred)
template<typename ValueFilter>
friend size_type erase_if(set& cont, const ValueFilter& valueFilter)
{
return cont.mTreeSet.Remove(pred);
return cont.mTreeSet.Remove(valueFilter);
}

node_type extract(const_iterator where)
Expand Down Expand Up @@ -662,10 +662,10 @@ class multiset : public set<TKey, TLessFunc, TAllocator, TTreeSet>
return Set::emplace(std::forward<ValueArgs>(valueArgs)...).first;
}

template<typename Predicate>
friend size_type erase_if(multiset& cont, const Predicate& pred)
template<typename ValueFilter>
friend size_type erase_if(multiset& cont, const ValueFilter& valueFilter)
{
return cont.get_nested_container().Remove(pred);
return cont.get_nested_container().Remove(valueFilter);
}
};

Expand Down
20 changes: 10 additions & 10 deletions include/momo/stdish/unordered_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,12 @@ class unordered_map
return mHashMap.Remove(key) ? 1 : 0;
}

template<typename Predicate>
friend size_type erase_if(unordered_map& cont, const Predicate& pred)
template<typename ValueFilter>
friend size_type erase_if(unordered_map& cont, const ValueFilter& valueFilter)
{
auto pairPred = [&pred] (const key_type& key, const mapped_type& mapped)
{ return pred(const_reference(key, mapped)); };
return cont.mHashMap.Remove(pairPred);
auto pairFilter = [&valueFilter] (const key_type& key, const mapped_type& mapped)
{ return valueFilter(const_reference(key, mapped)); };
return cont.mHashMap.Remove(pairFilter);
}

MOMO_FORCEINLINE typename HashMap::ValueReferenceRKey operator[](key_type&& key)
Expand Down Expand Up @@ -1022,12 +1022,12 @@ class unordered_map_open : public unordered_map<TKey, TMapped, THashFunc, TEqual
left.swap(right);
}

template<typename Predicate>
friend size_type erase_if(unordered_map_open& cont, const Predicate& pred)
template<typename ValueFilter>
friend size_type erase_if(unordered_map_open& cont, const ValueFilter& valueFilter)
{
auto pairPred = [&pred] (const key_type& key, const mapped_type& mapped)
{ return pred(const_reference(key, mapped)); };
return cont.get_nested_container().Remove(pairPred);
auto pairFilter = [&valueFilter] (const key_type& key, const mapped_type& mapped)
{ return valueFilter(const_reference(key, mapped)); };
return cont.get_nested_container().Remove(pairFilter);
}
};

Expand Down
20 changes: 10 additions & 10 deletions include/momo/stdish/unordered_multimap.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,12 @@ class unordered_multimap
return mHashMultiMap.RemoveKey(key);
}

template<typename Predicate>
friend size_type erase_if(unordered_multimap& cont, const Predicate& pred)
template<typename ValueFilter>
friend size_type erase_if(unordered_multimap& cont, const ValueFilter& valueFilter)
{
auto pairPred = [&pred] (const key_type& key, const mapped_type& mapped)
{ return pred(const_reference(key, mapped)); };
return cont.mHashMultiMap.Remove(pairPred);
auto pairFilter = [&valueFilter] (const key_type& key, const mapped_type& mapped)
{ return valueFilter(const_reference(key, mapped)); };
return cont.mHashMultiMap.Remove(pairFilter);
}

//iterator insert(node_type&& node)
Expand Down Expand Up @@ -776,12 +776,12 @@ class unordered_multimap_open : public unordered_multimap<TKey, TMapped, THashFu
left.swap(right);
}

template<typename Predicate>
friend size_type erase_if(unordered_multimap_open& cont, const Predicate& pred)
template<typename ValueFilter>
friend size_type erase_if(unordered_multimap_open& cont, const ValueFilter& valueFilter)
{
auto pairPred = [&pred] (const key_type& key, const mapped_type& mapped)
{ return pred(const_reference(key, mapped)); };
return cont.get_nested_container().Remove(pairPred);
auto pairFilter = [&valueFilter] (const key_type& key, const mapped_type& mapped)
{ return valueFilter(const_reference(key, mapped)); };
return cont.get_nested_container().Remove(pairFilter);
}
};

Expand Down
12 changes: 6 additions & 6 deletions include/momo/stdish/unordered_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,10 @@ class unordered_set
return mHashSet.Remove(key) ? 1 : 0;
}

template<typename Predicate>
friend size_type erase_if(unordered_set& cont, const Predicate& pred)
template<typename ValueFilter>
friend size_type erase_if(unordered_set& cont, const ValueFilter& valueFilter)
{
return cont.mHashSet.Remove(pred);
return cont.mHashSet.Remove(valueFilter);
}

node_type extract(const_iterator where)
Expand Down Expand Up @@ -698,10 +698,10 @@ class unordered_set_open : public unordered_set<TKey, THashFunc, TEqualFunc, TAl
left.swap(right);
}

template<typename Predicate>
friend size_type erase_if(unordered_set_open& cont, const Predicate& pred)
template<typename ValueFilter>
friend size_type erase_if(unordered_set_open& cont, const ValueFilter& valueFilter)
{
return cont.get_nested_container().Remove(pred);
return cont.get_nested_container().Remove(valueFilter);
}
};

Expand Down

0 comments on commit d3993c3

Please sign in to comment.