Skip to content

Commit 2b0e3e7

Browse files
authored
Use hashContinue in hash functions (#14463)
1 parent 209aece commit 2b0e3e7

File tree

11 files changed

+31
-20
lines changed

11 files changed

+31
-20
lines changed

OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,12 @@ protected
12821282

12831283
function keyHash
12841284
input Key key;
1285-
output Integer hash = stringHashDjb2(keyString(key));
1285+
output Integer hash;
1286+
algorithm
1287+
hash := stringHashDjb2(intString(listHead(key)));
1288+
for k in listRest(key) loop
1289+
hash := stringHashDjb2Continue(intString(k), hash);
1290+
end for;
12861291
end keyHash;
12871292

12881293
function keyEqual

OMCompiler/Compiler/NFFrontEnd/NFDimension.mo

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,12 @@ public
454454

455455
function hashList
456456
input list<Dimension> dims;
457-
output Integer i = stringHashDjb2(toStringList(dims));
457+
output Integer hash;
458+
algorithm
459+
hash := stringHashDjb2(toString(listHead(dims)));
460+
for dim in listRest(dims) loop
461+
hash := stringHashDjb2Continue(toString(dim), hash);
462+
end for;
458463
end hashList;
459464

460465
function toStringList

OMCompiler/Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ public
416416
function hash
417417
input Expression exp;
418418
output Integer hash = stringHashDjb2(toString(exp));
419+
// TODO use stringHashDjb2Continue
419420
end hash;
420421

421422
function isEqual

OMCompiler/Compiler/NFFrontEnd/NFUnit.mo

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,7 @@ end isMaster;
203203

204204
public function hashUnit
205205
input Unit inKey;
206-
output Integer outHash;
207-
protected
208-
String str;
209-
algorithm
210-
str := unit2string(inKey);
211-
outHash := stringHashDjb2(str);
206+
output Integer outHash = stringHashDjb2(unit2string(inKey));
212207
end hashUnit;
213208

214209
public function unitEqual

OMCompiler/Compiler/Script/CevalScriptBackend.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4364,7 +4364,7 @@ algorithm
43644364

43654365
isWindows := Autoconf.os == "Windows_NT";
43664366

4367-
fmutmp := substring(intString(stringHashDjb2(filenameprefix)), 1, 3) + ".fmutmp";
4367+
fmutmp := Util.hashFileNamePrefix(filenameprefix) + ".fmutmp";
43684368
logfile := filenameprefix + ".log";
43694369
dir := fmutmp+"/sources/";
43704370

OMCompiler/Compiler/SimCode/SimCodeMain.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ algorithm
762762
SimCode.VarInfo varInfo;
763763
case (SimCode.SIMCODE(),"C")
764764
algorithm
765-
fileNamePrefixHash := substring(intString(stringHashDjb2(simCode.fileNamePrefix)), 1, 3);
765+
fileNamePrefixHash := Util.hashFileNamePrefix(simCode.fileNamePrefix);
766766
fmutmp := fileNamePrefixHash + ".fmutmp";
767767
if System.directoryExists(fmutmp) then
768768
if not System.removeDirectory(fmutmp) then

OMCompiler/Compiler/SimCode/SimCodeUtil.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ algorithm
738738
end if;
739739

740740
// fix issue https://github.com/OpenModelica/OpenModelica/issues/12916
741-
fileNamePrefixHash := substring(intString(stringHashDjb2(filenamePrefix)), 1, 3);
741+
fileNamePrefixHash := Util.hashFileNamePrefix(filenamePrefix);
742742

743743
// Set fullPathPrefix for FMUs
744744
if isFMU then

OMCompiler/Compiler/Template/CodegenFMU.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ match simCode
6464
case sc as SIMCODE(modelInfo=modelInfo as MODELINFO(__)) then
6565
let guid = getUUIDStr()
6666
let target = simulationCodeTarget()
67-
let fileNamePrefixHash = '<%substring(intString(stringHashDjb2(fileNamePrefix)), 1, 3)%>'
67+
let fileNamePrefixHash = Util.hashFileNamePrefix(fileNamePrefix)
6868
let fileNamePrefixTmpDir = '<%fileNamePrefixHash%>.fmutmp/sources/<%fileNamePrefix%>'
6969
let()= textFile(simulationLiteralsFile(fileNamePrefix, literals), '<%fileNamePrefixTmpDir%>_literals.h')
7070
let()= textFile(simulationFunctionsHeaderFile(fileNamePrefix, modelInfo.functions, recordDecls, sc.generic_loop_calls), '<%fileNamePrefixTmpDir%>_functions.h')
@@ -1252,7 +1252,7 @@ end mapInitialUnknownsIndependentCrefs;
12521252
template getPlatformString2(String modelNamePrefix, String platform, String fileNamePrefix, String fmuTargetName, String dirExtra, String libsPos1, String libsPos2, String omhome, String FMUVersion)
12531253
"returns compilation commands for the platform. "
12541254
::=
1255-
let fmudirname = '<%substring(intString(stringHashDjb2(fileNamePrefix)), 1, 3)%>.fmutmp'
1255+
let fmudirname = '<%Util.hashFileNamePrefix(fileNamePrefix)%>.fmutmp'
12561256
match platform
12571257
case "win32"
12581258
case "win64" then
@@ -1349,7 +1349,7 @@ template fmuMakefile(String target, SimCode simCode, String FMUVersion, list<Str
13491349
let libsStr = (makefileParams.libs |> lib => lib ;separator=" ")
13501350
let libsPos1 = if not dirExtra then libsStr //else ""
13511351
let libsPos2 = if dirExtra then libsStr // else ""
1352-
let fmudirname = '<%substring(intString(stringHashDjb2(fileNamePrefix)), 1, 3)%>.fmutmp'
1352+
let fmudirname = '<%Util.hashFileNamePrefix(fileNamePrefix)%>.fmutmp'
13531353
let compilecmds = getPlatformString2(modelNamePrefix(simCode), makefileParams.platform, fileNamePrefix, fmuTargetName, dirExtra, libsPos1, libsPos2, makefileParams.omhome, FMUVersion)
13541354
let mkdir = match makefileParams.platform case "win32" case "win64" then '"mkdir.exe"' else 'mkdir'
13551355
<<

OMCompiler/Compiler/Template/SimCodeTV.mo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,6 +3555,11 @@ package Util
35553555
output Boolean outBoolean;
35563556
end stringBool;
35573557

3558+
function hashFileNamePrefix
3559+
input String inFileNamePrefix;
3560+
output String hashStr;
3561+
end hashFileNamePrefix;
3562+
35583563
end Util;
35593564

35603565
package List

OMCompiler/Compiler/Util/HashTable5.mo

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,7 @@ end FuncExpStr;
8181
protected function hashFunc
8282
"Calculates a hash value for Key"
8383
input Key cr;
84-
output Integer res;
85-
protected
86-
String crstr;
87-
algorithm
88-
crstr := Dump.printComponentRefStr(cr);
89-
res := stringHashDjb2(crstr);
84+
output Integer res = stringHashDjb2(Dump.printComponentRefStr(cr));
9085
end hashFunc;
9186

9287
public function emptyHashTable

0 commit comments

Comments
 (0)