dominion-dev / dominion-ecs-java

Insanely fast ECS (Entity Component System) for Java
https://dominion-dev.github.io
MIT License
288 stars 17 forks source link

I have another question about IndexKey #187

Closed endison1986 closed 7 months ago

endison1986 commented 7 months ago

@enricostara hi friend, I have another question about IndexKey I read the source code of IndexKey,why the constructor IndexKey(int value) donot initialize the data field. Will it cause it to obtain or overwrite the value of other IndexKey when it is used as the Key of the Map?

public final class IndexKey {
    private final int hashCode;
    private final byte[] data;

    public IndexKey(int value) {
        this.hashCode = value;
        data = null;
    }

    public IndexKey(int[] array) {...}

    public IndexKey(boolean[] checkArray, int min, int max, int length) {...}

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        return Arrays.equals(((IndexKey) o).data, data);
    }

    @Override
    public int hashCode() {
        return hashCode;
    }

    @Override
    public String toString() {...}
}