private unsafe bool HasSameNameAs(CanonicalIdentifier id) { int myLength = this.length; int idLength = id.Name.Length; if(myLength != idLength) return false; string myName = this.name; string idName = id.Name; if(myName == null) { int myOffset = this.offset; if(this.text != null && this.text.Equals(idName, myOffset, myLength)) { this.name = idName; this.text = null; return true; } return false; } return myName == idName; }
private static void Rehash() { CanonicalIdentifier[] hTable = Identifier.HashTable; int n = hTable.Length; int n2 = n * 2; CanonicalIdentifier[] newhTable = new CanonicalIdentifier[n2]; for(int i = 0; i < n; i++) { CanonicalIdentifier id = hTable[i]; if(id.Name == null) continue; int j = id.HashCode % n2; CanonicalIdentifier id2 = newhTable[j]; while(id2.Name != null) { j = (j + 1) % n2; id2 = newhTable[j]; } newhTable[j] = id; } Identifier.HashTable = newhTable; }
private int GetUniqueIdKey() { lock(Identifier.Lock) { int hcode = this.hashCode; CanonicalIdentifier[] hTable = Identifier.HashTable; int length = hTable.Length; int i = hcode % length; CanonicalIdentifier id = hTable[i]; while(id.Name != null) { if(this.HasSameNameAs(id)) return id.UniqueIdKey; i = (i + 1) % length; id = hTable[i]; } int count = Identifier.count; int countp1 = count + 1; Identifier.count = countp1; string name = this.Name; //Get a local copy of the name and drop any reference to a DocumentText instance hTable[i] = new CanonicalIdentifier(name, countp1, hcode); if(countp1 > length / 2) Rehash(); //Threshold exceeded, need to rehash return countp1; } }