X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fparser%2Fgenerator%2Ftable%2FItemSet.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fparser%2Fgenerator%2Ftable%2FItemSet.java;h=0b824090792900650f369a47ea70b71a1ebe6b6f;hb=649890ad306df48440a97893d7d53fb8a6386a4e;hp=0000000000000000000000000000000000000000;hpb=655590362c7017aff657d1ff30e6c63f03b6dd75;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/parser/generator/table/ItemSet.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/parser/generator/table/ItemSet.java new file mode 100644 index 000000000..0b8240907 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/parser/generator/table/ItemSet.java @@ -0,0 +1,61 @@ +package org.simantics.scl.compiler.parser.generator.table; + +import java.util.Arrays; +import java.util.Collection; + +import org.simantics.scl.compiler.parser.generator.grammar.AnaGrammar; + +public class ItemSet { + public final Item[] items; + int hash; + + public ItemSet(Item[] items) { + this.items = items; + Arrays.sort(items); + } + + public ItemSet(Collection items) { + this(items.toArray(new Item[items.size()])); + } + + private static final int PROD = 31*31; + + @Override + public int hashCode() { + if(hash == 0) { + int h = 1; + for(Item item : items) + h = PROD*h + item.hashCode(); + hash = h; + } + return hash; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + if(obj == null || obj.getClass() != getClass()) + return false; + ItemSet other = (ItemSet)obj; + if(other.items.length != items.length) + return false; + for(int i=0;i