public string getKey(int add) { string res = ""; int div = 1; int wildcardCount = wildcardList.Count - 1; int i = pattern.Length - 1; while (i >= 0) { if (pattern[i] != ']') { res += pattern[i--]; } else { Wildcard wc = (Wildcard)wildcardList[wildcardCount--]; if (add < div) { res += wc.getChar(); } else { res += wc.getChar((add / div) % wc.size()); div *= wc.size(); } while (pattern[i--] != '[') { ; } } } char[] r = res.ToCharArray(); Array.Reverse(r); return(new string(r)); }
public bool Contains(KeyPattern pattern) { if (pattern.wildcardList.Count != this.pattern.wildcardList.Count) { return(false); } if (pattern.GetPattern() != this.pattern.GetPattern()) { return(false); } bool equal = true; for (int k = 0; k < pattern.wildcardList.Count; k++) { Wildcard wc = ((Wildcard)pattern.wildcardList[k]); Wildcard thiswc = ((Wildcard)this.pattern.wildcardList[k]); if (wc.size() != (thiswc.size() / splittingQuotient[k])) { return(false); } bool bolContains2 = true; int begin = equal ? splittingCounter[k] : 0; for (int j = begin; j < splittingQuotient[k]; j++) { bool bolContains = true; for (int i = 0; i < wc.size(); i++) { if (wc.getChar(i - wc.count()) != thiswc.getChar(i + j * wc.size())) { bolContains = false; break; } } if (bolContains) { equal = (j == splittingCounter[k]); bolContains2 = true; break; } } if (!bolContains2) { return(false); } } return(!equal); }
/// <summary> /// See this[] /// </summary> /// <param name="index">The index</param> /// <returns>The sub key pattern</returns> private KeyPattern GetAtIndex(BigInteger index) { //calculate the wildcard positions on which we want to split: int[] splittingPositions = new int[pattern.wildcardList.Count]; for (int k = pattern.wildcardList.Count - 1; k >= 0; k--) { splittingPositions[k] = (int)(index % splittingQuotient[k]); index /= splittingQuotient[k]; } Debug.Assert(index == 0); //split up the sub pattern parts: KeyPattern subpart = new KeyPattern(pattern.GetPattern()); subpart.wildcardList = new ArrayList(); for (int k = 0; k < pattern.wildcardList.Count; k++) { Wildcard subwc = ((Wildcard)pattern.wildcardList[k]); char[] values = new char[256]; int sublength = subwc.size() / splittingQuotient[k]; for (int i = 0; i < sublength; i++) { values[i] = subwc.getChar(i + splittingPositions[k] * sublength); } Wildcard newwc = new Wildcard(values, sublength); subpart.wildcardList.Add(newwc); } return(subpart); }
public KeyPattern Pop() { if (stack.Count != 0) { counter++; return((KeyPattern)stack.Pop()); } if (end) { return(null); } KeyPattern part = new KeyPattern(pattern.GetPattern()); part.wildcardList = new ArrayList(); for (int k = 0; k < pattern.wildcardList.Count; k++) { Wildcard wc = ((Wildcard)pattern.wildcardList[k]); char[] values = new char[256]; int length = wc.size() / splittingQuotient[k]; for (int i = 0; i < length; i++) { values[i] = wc.getChar(i + splittingCounter[k] * length); } Wildcard newwc = new Wildcard(values, length); part.wildcardList.Add(newwc); } if (!SuccCounter()) { end = true; } counter++; return(part); }
public KeyPattern[] split() { KeyPattern[] patterns = new KeyPattern[2]; for (int i = 0; i < 2; i++) { patterns[i] = new KeyPattern(pattern); patterns[i].wildcardList = new ArrayList(); } bool s = false; for (int i = 0; i < wildcardList.Count; i++) { Wildcard wc = ((Wildcard)wildcardList[i]); if (!s && (wc.size() - wc.count()) > 1) { Wildcard[] wcs = wc.split(); patterns[0].wildcardList.Add(wcs[0]); patterns[1].wildcardList.Add(wcs[1]); s = true; } else { patterns[0].wildcardList.Add(new Wildcard(wc)); Wildcard copy = new Wildcard(wc); if (s) { copy.resetCounter(); } patterns[1].wildcardList.Add(copy); } } if (!s) { return(null); } return(patterns); }