Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
SkTMultiMap< T, Key, HashTraits > Class Template Reference

#include <SkTMultiMap.h>

Public Member Functions

 SkTMultiMap ()
 
 ~SkTMultiMap ()
 
void reset ()
 
void insert (const Key &key, T *value)
 
void remove (const Key &key, const T *value)
 
Tfind (const Key &key) const
 
template<class FindPredicate >
Tfind (const Key &key, const FindPredicate f)
 
template<class FindPredicate >
TfindAndRemove (const Key &key, const FindPredicate f)
 
int count () const
 

Detailed Description

template<typename T, typename Key, typename HashTraits = T>
class SkTMultiMap< T, Key, HashTraits >

A set that contains pointers to instances of T. Instances can be looked up with key Key. Multiple (possibly same) values can have the same key.

Definition at line 19 of file SkTMultiMap.h.

Constructor & Destructor Documentation

◆ SkTMultiMap()

template<typename T , typename Key , typename HashTraits = T>
SkTMultiMap< T, Key, HashTraits >::SkTMultiMap ( )
inline

Definition at line 29 of file SkTMultiMap.h.

29: fCount(0) {}

◆ ~SkTMultiMap()

template<typename T , typename Key , typename HashTraits = T>
SkTMultiMap< T, Key, HashTraits >::~SkTMultiMap ( )
inline

Definition at line 31 of file SkTMultiMap.h.

31 {
32 this->reset();
33 }
void reset()
Definition: SkTMultiMap.h:35

Member Function Documentation

◆ count()

template<typename T , typename Key , typename HashTraits = T>
int SkTMultiMap< T, Key, HashTraits >::count ( ) const
inline

Definition at line 131 of file SkTMultiMap.h.

131{ return fCount; }

◆ find() [1/2]

template<typename T , typename Key , typename HashTraits = T>
T * SkTMultiMap< T, Key, HashTraits >::find ( const Key key) const
inline

Definition at line 94 of file SkTMultiMap.h.

94 {
95 ValueList* list = fHash.find(key);
96 if (list) {
97 return list->fValue;
98 }
99 return nullptr;
100 }
T * find(const Key &key) const

◆ find() [2/2]

template<typename T , typename Key , typename HashTraits = T>
template<class FindPredicate >
T * SkTMultiMap< T, Key, HashTraits >::find ( const Key key,
const FindPredicate  f 
)
inline

Definition at line 103 of file SkTMultiMap.h.

103 {
104 ValueList* list = fHash.find(key);
105 while (list) {
106 if (f(list->fValue)){
107 return list->fValue;
108 }
109 list = list->fNext;
110 }
111 return nullptr;
112 }

◆ findAndRemove()

template<typename T , typename Key , typename HashTraits = T>
template<class FindPredicate >
T * SkTMultiMap< T, Key, HashTraits >::findAndRemove ( const Key key,
const FindPredicate  f 
)
inline

Definition at line 115 of file SkTMultiMap.h.

115 {
116 ValueList* list = fHash.find(key);
117
118 ValueList* prev = nullptr;
119 while (list) {
120 if (f(list->fValue)){
121 T* value = list->fValue;
122 this->internalRemove(prev, list, key);
123 return value;
124 }
125 prev = list;
126 list = list->fNext;
127 }
128 return nullptr;
129 }
static float prev(float f)
uint8_t value
#define T
Definition: precompiler.cc:65

◆ insert()

template<typename T , typename Key , typename HashTraits = T>
void SkTMultiMap< T, Key, HashTraits >::insert ( const Key key,
T value 
)
inline

Definition at line 48 of file SkTMultiMap.h.

48 {
49 ValueList* list = fHash.find(key);
50 if (list) {
51 // The new ValueList entry is inserted as the second element in the
52 // linked list, and it will contain the value of the first element.
53 ValueList* newEntry = new ValueList(list->fValue);
54 newEntry->fNext = list->fNext;
55 // The existing first ValueList entry is updated to contain the
56 // inserted value.
57 list->fNext = newEntry;
58 list->fValue = value;
59 } else {
60 fHash.add(new ValueList(value));
61 }
62
63 ++fCount;
64 }
void add(T *entry)

◆ remove()

template<typename T , typename Key , typename HashTraits = T>
void SkTMultiMap< T, Key, HashTraits >::remove ( const Key key,
const T value 
)
inline

Definition at line 66 of file SkTMultiMap.h.

66 {
67 ValueList* list = fHash.find(key);
68 // Temporarily making this safe for remove entries not in the map because of
69 // crbug.com/877915.
70#if 0
71 // Since we expect the caller to be fully aware of what is stored, just
72 // assert that the caller removes an existing value.
73 SkASSERT(list);
74 ValueList* prev = nullptr;
75 while (list->fValue != value) {
76 prev = list;
77 list = list->fNext;
78 }
79 this->internalRemove(prev, list, key);
80#else
81 ValueList* prev = nullptr;
82 while (list && list->fValue != value) {
83 prev = list;
84 list = list->fNext;
85 }
86 // Crash in Debug since it'd be great to detect a repro of 877915.
87 SkASSERT(list);
88 if (list) {
89 this->internalRemove(prev, list, key);
90 }
91#endif
92 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ reset()

template<typename T , typename Key , typename HashTraits = T>
void SkTMultiMap< T, Key, HashTraits >::reset ( )
inline

Definition at line 35 of file SkTMultiMap.h.

35 {
36 fHash.foreach([&](ValueList* vl) {
37 ValueList* next;
38 for (ValueList* it = vl; it; it = next) {
39 HashTraits::OnFree(it->fValue);
40 next = it->fNext;
41 delete it;
42 }
43 });
44 fHash.reset();
45 fCount = 0;
46 }
static float next(float f)
void foreach(Fn &&fn)

The documentation for this class was generated from the following file: