OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fxcrt/fx_basic.h" | 7 #include "core/fxcrt/fx_basic.h" |
8 #include "core/fxcrt/plex.h" | 8 #include "core/fxcrt/plex.h" |
9 | 9 |
10 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize) | 10 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } | 51 } |
52 CAssoc* pAssocNext = pAssocRet->pNext; | 52 CAssoc* pAssocNext = pAssocRet->pNext; |
53 for (uint32_t nBucket = (HashKey(pAssocRet->key) % m_nHashTableSize) + 1; | 53 for (uint32_t nBucket = (HashKey(pAssocRet->key) % m_nHashTableSize) + 1; |
54 nBucket < m_nHashTableSize && !pAssocNext; nBucket++) { | 54 nBucket < m_nHashTableSize && !pAssocNext; nBucket++) { |
55 pAssocNext = m_pHashTable[nBucket]; | 55 pAssocNext = m_pHashTable[nBucket]; |
56 } | 56 } |
57 rNextPosition = (FX_POSITION)pAssocNext; | 57 rNextPosition = (FX_POSITION)pAssocNext; |
58 rKey = pAssocRet->key; | 58 rKey = pAssocRet->key; |
59 rValue = pAssocRet->value; | 59 rValue = pAssocRet->value; |
60 } | 60 } |
61 FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { | 61 bool CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { |
62 uint32_t nHash; | 62 uint32_t nHash; |
63 CAssoc* pAssoc = GetAssocAt(key, nHash); | 63 CAssoc* pAssoc = GetAssocAt(key, nHash); |
64 if (!pAssoc) { | 64 if (!pAssoc) { |
65 return FALSE; | 65 return false; |
66 } | 66 } |
67 rValue = pAssoc->value; | 67 rValue = pAssoc->value; |
68 return TRUE; | 68 return true; |
69 } | 69 } |
70 | 70 |
71 void* CFX_MapPtrToPtr::GetValueAt(void* key) const { | 71 void* CFX_MapPtrToPtr::GetValueAt(void* key) const { |
72 uint32_t nHash; | 72 uint32_t nHash; |
73 CAssoc* pAssoc = GetAssocAt(key, nHash); | 73 CAssoc* pAssoc = GetAssocAt(key, nHash); |
74 return pAssoc ? pAssoc->value : nullptr; | 74 return pAssoc ? pAssoc->value : nullptr; |
75 } | 75 } |
76 | 76 |
77 void*& CFX_MapPtrToPtr::operator[](void* key) { | 77 void*& CFX_MapPtrToPtr::operator[](void* key) { |
78 uint32_t nHash; | 78 uint32_t nHash; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 113 } |
114 } | 114 } |
115 CFX_MapPtrToPtr::CAssoc* pAssoc = m_pFreeList; | 115 CFX_MapPtrToPtr::CAssoc* pAssoc = m_pFreeList; |
116 m_pFreeList = m_pFreeList->pNext; | 116 m_pFreeList = m_pFreeList->pNext; |
117 m_nCount++; | 117 m_nCount++; |
118 ASSERT(m_nCount > 0); | 118 ASSERT(m_nCount > 0); |
119 pAssoc->key = 0; | 119 pAssoc->key = 0; |
120 pAssoc->value = 0; | 120 pAssoc->value = 0; |
121 return pAssoc; | 121 return pAssoc; |
122 } | 122 } |
123 void CFX_MapPtrToPtr::InitHashTable(uint32_t nHashSize, FX_BOOL bAllocNow) { | 123 void CFX_MapPtrToPtr::InitHashTable(uint32_t nHashSize, bool bAllocNow) { |
124 ASSERT(m_nCount == 0); | 124 ASSERT(m_nCount == 0); |
125 ASSERT(nHashSize > 0); | 125 ASSERT(nHashSize > 0); |
126 FX_Free(m_pHashTable); | 126 FX_Free(m_pHashTable); |
127 m_pHashTable = nullptr; | 127 m_pHashTable = nullptr; |
128 if (bAllocNow) { | 128 if (bAllocNow) { |
129 m_pHashTable = FX_Alloc(CAssoc*, nHashSize); | 129 m_pHashTable = FX_Alloc(CAssoc*, nHashSize); |
130 } | 130 } |
131 m_nHashTableSize = nHashSize; | 131 m_nHashTableSize = nHashSize; |
132 } | 132 } |
133 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) { | 133 bool CFX_MapPtrToPtr::RemoveKey(void* key) { |
134 if (!m_pHashTable) { | 134 if (!m_pHashTable) { |
135 return FALSE; | 135 return false; |
136 } | 136 } |
137 CAssoc** ppAssocPrev; | 137 CAssoc** ppAssocPrev; |
138 ppAssocPrev = &m_pHashTable[HashKey(key) % m_nHashTableSize]; | 138 ppAssocPrev = &m_pHashTable[HashKey(key) % m_nHashTableSize]; |
139 CAssoc* pAssoc; | 139 CAssoc* pAssoc; |
140 for (pAssoc = *ppAssocPrev; pAssoc; pAssoc = pAssoc->pNext) { | 140 for (pAssoc = *ppAssocPrev; pAssoc; pAssoc = pAssoc->pNext) { |
141 if (pAssoc->key == key) { | 141 if (pAssoc->key == key) { |
142 *ppAssocPrev = pAssoc->pNext; | 142 *ppAssocPrev = pAssoc->pNext; |
143 FreeAssoc(pAssoc); | 143 FreeAssoc(pAssoc); |
144 return TRUE; | 144 return true; |
145 } | 145 } |
146 ppAssocPrev = &pAssoc->pNext; | 146 ppAssocPrev = &pAssoc->pNext; |
147 } | 147 } |
148 return FALSE; | 148 return false; |
149 } | 149 } |
150 void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) { | 150 void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) { |
151 pAssoc->pNext = m_pFreeList; | 151 pAssoc->pNext = m_pFreeList; |
152 m_pFreeList = pAssoc; | 152 m_pFreeList = pAssoc; |
153 m_nCount--; | 153 m_nCount--; |
154 ASSERT(m_nCount >= 0); | 154 ASSERT(m_nCount >= 0); |
155 if (m_nCount == 0) { | 155 if (m_nCount == 0) { |
156 RemoveAll(); | 156 RemoveAll(); |
157 } | 157 } |
158 } | 158 } |
OLD | NEW |