Add hashCode() to FullDataPointIdMap

This commit is contained in:
James Seibel
2024-09-26 07:42:24 -05:00
parent fd0a4c55ac
commit c06283d403
@@ -73,6 +73,8 @@ public class FullDataPointIdMap
private final ArrayList<Entry> entryList = new ArrayList<>();
private final HashMap<Entry, Integer> idMap = new HashMap<>();
private int cachedHashCode = 0;
//=============//
@@ -159,6 +161,9 @@ public class FullDataPointIdMap
id = this.entryList.size();
this.entryList.add(biomeBlockStateEntry);
this.idMap.put(biomeBlockStateEntry, id);
// invalidate the cached hash code
this.cachedHashCode = 0;
}
return id;
@@ -186,6 +191,9 @@ public class FullDataPointIdMap
int id = this.entryList.size();
this.entryList.add(biomeBlockStateEntry);
this.idMap.put(biomeBlockStateEntry, id);
// invalidate the cached hash code
this.cachedHashCode = 0;
}
finally
{
@@ -275,6 +283,7 @@ public class FullDataPointIdMap
this.pos = pos;
this.entryList.clear();
this.idMap.clear();
this.cachedHashCode = 0;
}
@@ -390,6 +399,26 @@ public class FullDataPointIdMap
return false;
}
/** Only includes the base data in this object, not the mapping */
@Override
public int hashCode()
{
if (this.cachedHashCode == 0)
{
this.generateHashCode();
}
return this.cachedHashCode;
}
private void generateHashCode()
{
int result = DhSectionPos.hashCode(this.pos);
for (int i = 0; i < this.entryList.size(); i++)
{
result = 31 * result + this.entryList.hashCode();
}
this.cachedHashCode = result;
}
//==============//