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];
        }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
    }
    private static void ResourceKeyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var fe = d as FrameworkElement;

        if (fe != null)
        {
            lock (locker)
            {
                DependencyProperty targetProperty;
                if (ReverseMap.TryGetValue(e.Property, out targetProperty))
                {
                    fe.SetResourceReference(targetProperty, e.NewValue);
                }
            }
        }
    }
Ejemplo n.º 7
0
 public long?Get(Type type)
 {
     return(!ReverseMap.TryGetValue(type, out var result) ? (long?)null : result);
 }