| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #ifndef SkTMultiMap_DEFINED | 9 #ifndef SkTMultiMap_DEFINED |
| 10 #define SkTMultiMap_DEFINED | 10 #define SkTMultiMap_DEFINED |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 ~SkTMultiMap() { | 33 ~SkTMultiMap() { |
| 34 SkASSERT(fCount == 0); | 34 SkASSERT(fCount == 0); |
| 35 SkASSERT(fHash.count() == 0); | 35 SkASSERT(fHash.count() == 0); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void insert(const Key& key, T* value) { | 38 void insert(const Key& key, T* value) { |
| 39 ValueList* list = fHash.find(key); | 39 ValueList* list = fHash.find(key); |
| 40 if (list) { | 40 if (list) { |
| 41 // The new ValueList entry is inserted as the second element in the | 41 // The new ValueList entry is inserted as the second element in the |
| 42 // linked list, and it will contain the value of the first element. | 42 // linked list, and it will contain the value of the first element. |
| 43 ValueList* newEntry = SkNEW_ARGS(ValueList, (list->fValue)); | 43 ValueList* newEntry = new ValueList(list->fValue); |
| 44 newEntry->fNext = list->fNext; | 44 newEntry->fNext = list->fNext; |
| 45 // The existing first ValueList entry is updated to contain the | 45 // The existing first ValueList entry is updated to contain the |
| 46 // inserted value. | 46 // inserted value. |
| 47 list->fNext = newEntry; | 47 list->fNext = newEntry; |
| 48 list->fValue = value; | 48 list->fValue = value; |
| 49 } else { | 49 } else { |
| 50 fHash.add(SkNEW_ARGS(ValueList, (value))); | 50 fHash.add(new ValueList(value)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 ++fCount; | 53 ++fCount; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void remove(const Key& key, const T* value) { | 56 void remove(const Key& key, const T* value) { |
| 57 ValueList* list = fHash.find(key); | 57 ValueList* list = fHash.find(key); |
| 58 // Since we expect the caller to be fully aware of what is stored, just | 58 // Since we expect the caller to be fully aware of what is stored, just |
| 59 // assert that the caller removes an existing value. | 59 // assert that the caller removes an existing value. |
| 60 SkASSERT(list); | 60 SkASSERT(list); |
| 61 ValueList* prev = NULL; | 61 ValueList* prev = NULL; |
| 62 while (list->fValue != value) { | 62 while (list->fValue != value) { |
| 63 prev = list; | 63 prev = list; |
| 64 list = list->fNext; | 64 list = list->fNext; |
| 65 } | 65 } |
| 66 | 66 |
| 67 if (list->fNext) { | 67 if (list->fNext) { |
| 68 ValueList* next = list->fNext; | 68 ValueList* next = list->fNext; |
| 69 list->fValue = next->fValue; | 69 list->fValue = next->fValue; |
| 70 list->fNext = next->fNext; | 70 list->fNext = next->fNext; |
| 71 SkDELETE(next); | 71 delete next; |
| 72 } else if (prev) { | 72 } else if (prev) { |
| 73 prev->fNext = NULL; | 73 prev->fNext = NULL; |
| 74 SkDELETE(list); | 74 delete list; |
| 75 } else { | 75 } else { |
| 76 fHash.remove(key); | 76 fHash.remove(key); |
| 77 SkDELETE(list); | 77 delete list; |
| 78 } | 78 } |
| 79 | 79 |
| 80 --fCount; | 80 --fCount; |
| 81 } | 81 } |
| 82 | 82 |
| 83 T* find(const Key& key) const { | 83 T* find(const Key& key) const { |
| 84 ValueList* list = fHash.find(key); | 84 ValueList* list = fHash.find(key); |
| 85 if (list) { | 85 if (list) { |
| 86 return list->fValue; | 86 return list->fValue; |
| 87 } | 87 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 114 return count; | 114 return count; |
| 115 } | 115 } |
| 116 #endif | 116 #endif |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 SkTDynamicHash<ValueList, Key> fHash; | 119 SkTDynamicHash<ValueList, Key> fHash; |
| 120 int fCount; | 120 int fCount; |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 #endif | 123 #endif |
| OLD | NEW |