Skip to content

Commit ba22159

Browse files
committed
GetCacheKeyHashMap: Optimize it
We can create the hashmap already large enough, so there is no need to rehash it immediately afterwards again.
1 parent 6a0e2e8 commit ba22159

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6307,38 +6307,38 @@ threadsafe Function/WAVE GetCacheKeyHashMap()
63076307
return wv
63086308
endif
63096309

6310-
WAVE wv = HM_Create(size = 2^14, valueType = IGOR_TYPE_32BIT_INT | IGOR_TYPE_UNSIGNED)
6311-
63126310
WAVE/Z/T/SDFR=dfr keys
6313-
if(WaveExists(keys))
6314-
FillHashMapFromNoteIndexVector(wv, keys)
6315-
HM_RehashIfRequired(wv)
6316-
KillOrMoveToTrash(wv = keys)
6317-
endif
6311+
WAVE wv = GetHashMapFromNoteIndexVector(keys, IGOR_TYPE_32BIT_INT | IGOR_TYPE_UNSIGNED)
6312+
KillOrMoveToTrash(wv = keys)
63186313

63196314
MoveWave wv, dfr:hashmap
63206315

63216316
return wv
63226317
End
63236318

6324-
/// @brief Fill the hashmap with the wave entries as keys and their index as values
6319+
/// @brief Return a hashmap with the wave entries as keys and their index as values
63256320
///
63266321
/// Ignores empty values
6327-
threadsafe static Function FillHashMapFromNoteIndexVector(WAVE/WAVE hashmap, WAVE/T entries)
6322+
threadsafe static Function/WAVE GetHashMapFromNoteIndexVector(WAVE/Z/T entries, variable valueType)
63286323

63296324
variable numEntries
6325+
variable size = 2^14
6326+
6327+
numEntries = WaveExists(entries) ? GetNumberFromWaveNote(entries, NOTE_INDEX) : 0
6328+
ASSERT_TS(IsFinite(numEntries), "the wave entries exists but does not hold a NOTE_INDEX")
63306329

6331-
numEntries = GetNumberFromWaveNote(entries, NOTE_INDEX)
6332-
ASSERT_TS(IsFinite(numEntries), "entries does not hold a NOTE_INDEX")
6330+
size = max(size, HM_CalculateOptimumSize(numEntries))
6331+
WAVE hashmap = HM_Create(size = size, valueType = valueType)
63336332

63346333
if(numEntries == 0)
6335-
// nothing to do
6336-
return NaN
6334+
return hashmap
63376335
endif
63386336

63396337
Make/N=(numEntries)/FREE indexHelper
63406338

63416339
indexHelper[] = (strlen(entries[p]) > 0) ? HM_AddEntry(hashmap, entries[p], var = p) : 0
6340+
6341+
return hashmap
63426342
End
63436343

63446344
/// @brief Return the wave reference wave holding the cache stats

Packages/tests/Basic/UTF_Cache.ipf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Function UpgradePathWithFilledKeys()
262262

263263
WAVE keys_new = GetCacheKeyHashMap()
264264
CHECK_WAVE(keys_old, NULL_WAVE)
265+
CHECK_EQUAL_VAR(MIES_HM#HM_GetSize(keys_new), 2^14)
265266

266267
WAVE/Z result = HM_GetAllKeys(keys_new)
267268
CHECK_WAVE(result, TEXT_WAVE)

0 commit comments

Comments
 (0)