public InferenceGraph(List <Set> ins, List <Set> outs, HashSet <string> precolored) { for (int i = 0; i < ins.Count; i++) { foreach (var item in ins[i]) { if (Map.TryAdd(item, ReverseMap.Count)) { ReverseMap.Add(item); } } foreach (var item in outs[i]) { if (Map.TryAdd(item, ReverseMap.Count)) { ReverseMap.Add(item); } } } foreach (var item in precolored) { if (Map.TryAdd(item, ReverseMap.Count)) { ReverseMap.Add(item); } } AdjacentListBuilder = Enumerable.Range(0, ReverseMap.Count).Select((i) => ImmutableHashSet.CreateBuilder <int>()).ToArray(); AdjacentList = new ImmutableHashSet <int> [ReverseMap.Count]; AdjacentMatrix = new bool[ReverseMap.Count, ReverseMap.Count]; MoveList = Enumerable.Range(0, ReverseMap.Count).Select((i) => new HashSet <Move>()).ToArray(); Degree = new int[ReverseMap.Count]; }
public bool TryAdd(long id, Type type) { if (!Map.TryGetValue(id, out Type added)) { Map.Add(id, type); ReverseMap.Add(type, id); Serializers.Add(type, type.GetConstructor(new[] { typeof(BlockDeserializeContext) })); return(true); } return(false); }
public bool TryAdd(long id, Type type) { Debug.Assert(typeof(IBlockSerialized).IsAssignableFrom(type)); if (!Map.TryGetValue(id, out Type added)) { Map.Add(id, type); ReverseMap.Add(type, id); Serializers.Add(type, type.GetConstructor(new[] { typeof(BlockDeserializeContext) })); return(true); } return(false); }
public string Preprocess(string input, string templateToken) { Builder.Clear(); var startIndexes = new List <int>(); if (templateToken != null) { var matches = Regex.Matches(input, templateToken); foreach (Match m in matches) { startIndexes.Add(m.Index); } } int tokens = 0; for (int i = 0; i < input.Length; i++) { if (templateToken != null && tokens < startIndexes.Count && startIndexes[tokens] == i) { Builder.Append(ProcessedToken); i += ProcessedToken.Length - 1; tokens++; continue; } char c = input[i]; if (CharacterMap.TryGetValue(c, out int charIndex)) { Builder.Append((char)charIndex); } else { if (CharCount == 65535) { throw new Exception("Character limited reached, cannot Munge"); } CharacterMap.Add(c, CharCount); Builder.Append((char)CharCount); CharCount++; ReverseMap.Add(c); } } return(Builder.ToString()); }
public static DependencyProperty EnsureResourceKeyProperty(DependencyProperty targetProperty) { DependencyProperty resourceKeyProperty; lock (locker) { if (!DirectMap.TryGetValue(targetProperty, out resourceKeyProperty)) { resourceKeyProperty = RegisterResourceKeyProperty(targetProperty); DirectMap.Add(targetProperty, resourceKeyProperty); ReverseMap.Add(resourceKeyProperty, targetProperty); } } return(resourceKeyProperty); }