MCPcopy Create free account
hub / github.com/ZDoom/Raze / InitHashChains

Method InitHashChains

source/common/filesystem/source/filesystem.cpp:771–820  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

769//==========================================================================
770
771void FileSystem::InitHashChains (void)
772{
773 unsigned int i, j;
774
775 NumEntries = (uint32_t)FileInfo.size();
776 Hashes.resize(8 * NumEntries);
777 // Mark all buckets as empty
778 memset(Hashes.data(), -1, Hashes.size() * sizeof(Hashes[0]));
779 FirstLumpIndex = &Hashes[0];
780 NextLumpIndex = &Hashes[NumEntries];
781 FirstLumpIndex_FullName = &Hashes[NumEntries * 2];
782 NextLumpIndex_FullName = &Hashes[NumEntries * 3];
783 FirstLumpIndex_NoExt = &Hashes[NumEntries * 4];
784 NextLumpIndex_NoExt = &Hashes[NumEntries * 5];
785 FirstLumpIndex_ResId = &Hashes[NumEntries * 6];
786 NextLumpIndex_ResId = &Hashes[NumEntries * 7];
787
788
789 // Now set up the chains
790 for (i = 0; i < (unsigned)NumEntries; i++)
791 {
792 j = MakeHash (FileInfo[i].shortName.String, 8) % NumEntries;
793 NextLumpIndex[i] = FirstLumpIndex[j];
794 FirstLumpIndex[j] = i;
795
796 // Do the same for the full paths
797 if (FileInfo[i].LongName[0] != 0)
798 {
799 j = MakeHash(FileInfo[i].LongName) % NumEntries;
800 NextLumpIndex_FullName[i] = FirstLumpIndex_FullName[j];
801 FirstLumpIndex_FullName[j] = i;
802
803 std::string nameNoExt = FileInfo[i].LongName;
804 auto dot = nameNoExt.find_last_of('.');
805 auto slash = nameNoExt.find_last_of('/');
806 if ((dot > slash || slash == std::string::npos) && dot != std::string::npos) nameNoExt.resize(dot);
807
808 j = MakeHash(nameNoExt.c_str()) % NumEntries;
809 NextLumpIndex_NoExt[i] = FirstLumpIndex_NoExt[j];
810 FirstLumpIndex_NoExt[j] = i;
811
812 j = FileInfo[i].resourceId % NumEntries;
813 NextLumpIndex_ResId[i] = FirstLumpIndex_ResId[j];
814 FirstLumpIndex_ResId[j] = i;
815
816 }
817 }
818 FileInfo.shrink_to_fit();
819 Files.shrink_to_fit();
820}
821
822//==========================================================================
823//

Callers 2

ReadAllRFSFunction · 0.80
LoadDefinitionsFunction · 0.80

Calls 6

MakeHashFunction · 0.85
c_strMethod · 0.80
shrink_to_fitMethod · 0.80
sizeMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected