deterministicHashCode

This commit is contained in:
2023-10-23 09:45:18 -07:00
parent 42d202e287
commit 05c27a891b
11 changed files with 240 additions and 63 deletions

View File

@ -20,15 +20,27 @@ internal abstract class Id
return result;
}
internal static NameWithoutExtension GetNameWithoutExtension(IMetadataConfiguration configuration, string file)
internal static FilePath GetFilePath(FilePath filePath, string file)
{
NameWithoutExtension result;
FilePath result;
string fileName = Path.GetFileName(file);
string fileExtensionLowered = Path.GetExtension(file).ToLower();
result = new(filePath.DirectoryName, fileExtensionLowered, file, filePath.Id, filePath.IsIdFormat, filePath.IsPaddedIdFormat, fileName, filePath.NameWithoutExtension);
return result;
}
internal static FilePath GetFilePath(IMetadataConfiguration configuration, string file)
{
FilePath result;
int? id;
short? multiplier;
char negativeMarker;
int absoluteValueOfId;
string fileName = Path.GetFileName(file);
string fileExtensionLowered = Path.GetExtension(file).ToLower();
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
short sortOrderOnlyLengthIndex = IId.GetSortOrderOnlyLengthIndex(configuration.Offset);
string fileDirectoryName = Path.GetDirectoryName(file) ?? throw new NullReferenceException();
bool nameWithoutExtensionIsIdFormat = IId.NameWithoutExtensionIsIdFormat(fileNameWithoutExtension);
bool nameWithoutExtensionIsPaddedIdFormat = IId.NameWithoutExtensionIsPaddedIdFormat(fileNameWithoutExtension, sortOrderOnlyLengthIndex);
if (!nameWithoutExtensionIsIdFormat && !nameWithoutExtensionIsPaddedIdFormat)
@ -58,7 +70,26 @@ internal abstract class Id
id = null;
}
}
result = new(fileNameWithoutExtension, id, nameWithoutExtensionIsIdFormat, nameWithoutExtensionIsPaddedIdFormat);
result = new(fileDirectoryName, fileExtensionLowered, file, id, nameWithoutExtensionIsIdFormat, nameWithoutExtensionIsPaddedIdFormat, fileName, fileNameWithoutExtension);
return result;
}
internal static int GetDeterministicHashCode(byte[] value)
{
int result;
unchecked
{
int hash1 = (5381 << 16) + 5381;
int hash2 = hash1;
for (int i = 0; i < value.Length; i += 2)
{
hash1 = ((hash1 << 5) + hash1) ^ value[i];
if (i == value.Length - 1)
break;
hash2 = ((hash2 << 5) + hash2) ^ value[i + 1];
}
result = hash1 + (hash2 * 1566083941);
}
return result;
}