Lines Matching defs:hashSet
85 * Returns an index between [0, hashSet->ddictPtrTableSize]
87 static size_t ZSTD_DDictHashSet_getIndex(const ZSTD_DDictHashSet* hashSet, U32 dictID) {
89 /* DDict ptr table size is a multiple of 2, use size - 1 as mask to get index within [0, hashSet->ddictPtrTableSize) */
90 return hash & (hashSet->ddictPtrTableSize - 1);
97 static size_t ZSTD_DDictHashSet_emplaceDDict(ZSTD_DDictHashSet* hashSet, const ZSTD_DDict* ddict) {
99 size_t idx = ZSTD_DDictHashSet_getIndex(hashSet, dictID);
100 const size_t idxRangeMask = hashSet->ddictPtrTableSize - 1;
101 RETURN_ERROR_IF(hashSet->ddictPtrCount == hashSet->ddictPtrTableSize, GENERIC, "Hash set is full!");
103 while (hashSet->ddictPtrTable[idx] != NULL) {
105 if (ZSTD_getDictID_fromDDict(hashSet->ddictPtrTable[idx]) == dictID) {
107 hashSet->ddictPtrTable[idx] = ddict;
114 hashSet->ddictPtrTable[idx] = ddict;
115 hashSet->ddictPtrCount++;
123 static size_t ZSTD_DDictHashSet_expand(ZSTD_DDictHashSet* hashSet, ZSTD_customMem customMem) {
124 size_t newTableSize = hashSet->ddictPtrTableSize * DDICT_HASHSET_RESIZE_FACTOR;
126 const ZSTD_DDict** oldTable = hashSet->ddictPtrTable;
127 size_t oldTableSize = hashSet->ddictPtrTableSize;
132 hashSet->ddictPtrTable = newTable;
133 hashSet->ddictPtrTableSize = newTableSize;
134 hashSet->ddictPtrCount = 0;
137 FORWARD_IF_ERROR(ZSTD_DDictHashSet_emplaceDDict(hashSet, oldTable[i]), "");
148 static const ZSTD_DDict* ZSTD_DDictHashSet_getDDict(ZSTD_DDictHashSet* hashSet, U32 dictID) {
149 size_t idx = ZSTD_DDictHashSet_getIndex(hashSet, dictID);
150 const size_t idxRangeMask = hashSet->ddictPtrTableSize - 1;
153 size_t currDictID = ZSTD_getDictID_fromDDict(hashSet->ddictPtrTable[idx]);
163 return hashSet->ddictPtrTable[idx];
188 static void ZSTD_freeDDictHashSet(ZSTD_DDictHashSet* hashSet, ZSTD_customMem customMem) {
190 if (hashSet && hashSet->ddictPtrTable) {
191 ZSTD_customFree((void*)hashSet->ddictPtrTable, customMem);
193 if (hashSet) {
194 ZSTD_customFree(hashSet, customMem);
201 static size_t ZSTD_DDictHashSet_addDDict(ZSTD_DDictHashSet* hashSet, const ZSTD_DDict* ddict, ZSTD_customMem customMem) {
202 DEBUGLOG(4, "Adding dict ID: %u to hashset with - Count: %zu Tablesize: %zu", ZSTD_getDictID_fromDDict(ddict), hashSet->ddictPtrCount, hashSet->ddictPtrTableSize);
203 if (hashSet->ddictPtrCount * DDICT_HASHSET_MAX_LOAD_FACTOR_COUNT_MULT / hashSet->ddictPtrTableSize * DDICT_HASHSET_MAX_LOAD_FACTOR_SIZE_MULT != 0) {
204 FORWARD_IF_ERROR(ZSTD_DDictHashSet_expand(hashSet, customMem), "");
206 FORWARD_IF_ERROR(ZSTD_DDictHashSet_emplaceDDict(hashSet, ddict), "");