8#ifndef SkTMultiMap_DEFINED
9#define SkTMultiMap_DEFINED
18 typename HashTraits=
T>
23 static const Key& GetKey(
const ValueList&
e) {
return HashTraits::GetKey(*
e.fValue); }
36 fHash.
foreach([&](ValueList* vl) {
38 for (ValueList* it = vl; it; it =
next) {
39 HashTraits::OnFree(it->fValue);
49 ValueList* list = fHash.
find(
key);
53 ValueList* newEntry =
new ValueList(list->fValue);
54 newEntry->fNext = list->fNext;
57 list->fNext = newEntry;
67 ValueList* list = fHash.
find(
key);
74 ValueList*
prev =
nullptr;
75 while (list->fValue !=
value) {
79 this->internalRemove(
prev, list,
key);
81 ValueList*
prev =
nullptr;
82 while (list && list->fValue !=
value) {
89 this->internalRemove(
prev, list,
key);
95 ValueList* list = fHash.
find(
key);
102 template<
class FindPredicate>
104 ValueList* list = fHash.
find(
key);
106 if (
f(list->fValue)){
114 template<
class FindPredicate>
116 ValueList* list = fHash.
find(
key);
118 ValueList*
prev =
nullptr;
120 if (
f(list->fValue)){
122 this->internalRemove(
prev, list,
key);
131 int count()
const {
return fCount; }
134 template <
typename Fn>
135 void foreach(Fn&& fn)
const {
136 fHash.
foreach([&](
const ValueList& vl) {
137 for (
const ValueList* it = &vl; it; it = it->fNext) {
144 for (ValueList* list = fHash.
find(
key); list; list = list->fNext) {
145 if (list->fValue ==
value) {
153 int countForKey(
const Key&
key)
const {
155 ValueList* list = fHash.
find(
key);
168 void internalRemove(ValueList*
prev, ValueList* elem,
const Key&
key) {
170 ValueList*
next = elem->fNext;
171 elem->fValue =
next->fValue;
172 elem->fNext =
next->fNext;
175 prev->fNext =
nullptr;
static float next(float f)
static float prev(float f)
T * find(const Key &key) const
void remove(const Key &key)
T * find(const Key &key, const FindPredicate f)
T * find(const Key &key) const
void insert(const Key &key, T *value)
void remove(const Key &key, const T *value)
T * findAndRemove(const Key &key, const FindPredicate f)
static uint32_t Hash(uint32_t key)