예제 #1
0
 public DictionarySubclass(SCG.IDictionary <TKey, TValue> dictionary)
 {
     foreach (var pair in dictionary)
     {
         Add(pair.Key, pair.Value);
     }
 }
 public void IReadOnlyDictionary_Generic_Values_ContainsAllCorrectValues(int count)
 {
     SCG.IDictionary <TKey, TValue> dictionary = GenericIDictionaryFactory(count);
     SCG.IEnumerable <TValue>       expected   = dictionary.Select((pair) => pair.Value);
     SCG.IEnumerable <TValue>       values     = ((SCG.IReadOnlyDictionary <TKey, TValue>)dictionary).Values;
     Assert.True(expected.SequenceEqual(values));
 }
예제 #3
0
파일: Showing.cs 프로젝트: flyer87/C6
        public static bool Show <TKey, TValue>(SCG.IDictionary <TKey, TValue> dictionary, StringBuilder stringbuilder, ref int rest, IFormatProvider formatProvider)
        {
            throw new NotImplementedException();

            /*
             * var sorted = dictionary is ISortedDictionary<K, V>;
             * stringbuilder.Append(sorted ? "[ " : "{ ");
             * rest -= 4; // Account for "( " and " )"
             * var first = true;
             * var complete = true;
             *
             * foreach (var p in dictionary) {
             *  complete = false;
             *  if (rest <= 0)
             *      break;
             *  if (first)
             *      first = false;
             *  else {
             *      stringbuilder.Append(", ");
             *      rest -= 2;
             *  }
             *  complete = Show(p, stringbuilder, ref rest, formatProvider);
             * }
             *
             * if (!complete) {
             *  stringbuilder.Append("...");
             *  rest -= 3;
             * }
             *
             * stringbuilder.Append(sorted ? " ]" : " }");
             * return complete;
             */
        }
예제 #4
0
        private static void TestCopyConstructor <T>(int size, Func <int, T> keyValueSelector, Func <SCG.IDictionary <T, T>, SCG.IDictionary <T, T> > dictionarySelector, SCG.IEqualityComparer <T> comparer)
        {
            SCG.IDictionary <T, T> expected = CreateDictionary(size, keyValueSelector, comparer);
            SCG.IDictionary <T, T> input    = dictionarySelector(CreateDictionary(size, keyValueSelector, comparer));

            Assert.Equal(expected, new Dictionary <T, T>(input, comparer));
        }
 internal BootstrapConfigurationImpl(
    ISet<string> flags, 
    SCG.IDictionary<string, string> properties
 ) {
    this.flags = flags;
    this.properties = properties;
 }
예제 #6
0
    public static int Increment <TKey>(this SCG.IDictionary <TKey, int> dictionary, TKey key, int count = 1, int defaultValue = 0)
    {
        int value = dictionary.GetOrDefault(key, defaultValue) + count;

        dictionary[key] = value;
        return(value);
    }
 internal BootstrapConfigurationImpl(
     ISet <string> flags,
     SCG.IDictionary <string, string> properties
     )
 {
     this.flags      = flags;
     this.properties = properties;
 }
        public void LinkedDictionary_Generic_Constructor_IEqualityComparer(int count)
        {
            SCG.IEqualityComparer <TKey>    comparer = GetKeyIEqualityComparer();
            SCG.IDictionary <TKey, TValue>  source   = GenericIDictionaryFactory(count);
            LinkedDictionary <TKey, TValue> copied   = new LinkedDictionary <TKey, TValue>(source, comparer);

            Assert.Equal(source, copied);
            Assert.Equal(comparer, copied.EqualityComparer);
        }
예제 #9
0
    public static TValue GetOrDefault <TKey, TValue>(this SCG.IDictionary <TKey, TValue> dictionary, TKey key, TValue defaultValue = default(TValue))
    {
        TValue value;

        if (!dictionary.TryGetValue(key, out value))
        {
            value = defaultValue;
        }
        return(value);
    }
예제 #10
0
    public static TValue GetOrAdd <TKey, TValue>(this SCG.IDictionary <TKey, TValue> dictionary, TKey key, System.Func <TKey, TValue> defaultFactory)
    {
        TValue value;

        if (!dictionary.TryGetValue(key, out value))
        {
            dictionary.Add(key, value = defaultFactory(key));
        }
        return(value);
    }
예제 #11
0
 public BindingDictionary(SCG.IDictionary <Name, CommandEntry> dictionary) : base
         (dictionary.Where
             (x => !(string.IsNullOrWhiteSpace(x.Key) ||
                     string.IsNullOrWhiteSpace(x.Value.Command)
                     )
             )
         .ToBinding(x => x.Key.Trim(), x => x.Value)
         )
 {
 }
예제 #12
0
        public void IDictionary_Generic_CopyTo_NonContiguousDictionary(int count)
        {
            SCG.IDictionary <string, string>    collection = CreateDictionary(count, k => k.ToString());
            SCG.KeyValuePair <string, string>[] array      = new SCG.KeyValuePair <string, string> [count];
            collection.CopyTo(array, 0);
            int i = 0;

            foreach (SCG.KeyValuePair <string, string> obj in collection)
            {
                Assert.Equal(array[i++], obj);
            }
        }
예제 #13
0
 static KeywordRecognition()
 {
     kw1 = new HashSet <String>();
     kw1.AddAll(keywordArray);
     kw2 = new TreeSet <String>(new SC());
     kw2.AddAll(keywordArray);
     kw3 = new SortedArray <String>(new SC());
     kw3.AddAll(keywordArray);
     kw4 = new SCG.Dictionary <String, bool>();
     foreach (String keyword in keywordArray)
     {
         kw4.Add(keyword, false);
     }
 }
예제 #14
0
        static KeywordRecognition()
        {
            _keywords1 = new HashSet <string>();
            _keywords1.AddAll(_keywordArray);
            _keywords2 = new TreeSet <string>(new SC());
            _keywords2.AddAll(_keywordArray);
            _keywords3 = new SortedArray <string>(new SC());
            _keywords3.AddAll(_keywordArray);
            _keywords4 = new SCG.Dictionary <string, bool>();

            foreach (var keyword in _keywordArray)
            {
                _keywords4.Add(keyword, false);
            }
        }
예제 #15
0
 public static SCO.ReadOnlyDictionary <TKey, TValue> AsReadOnly <TKey, TValue>(this SCG.IDictionary <TKey, TValue> dictionary) => new SCO.ReadOnlyDictionary <TKey, TValue>(dictionary);
예제 #16
0
 /**
  * <summary>
  * Equality predicate for dictionaries.
  * </summary>
  * <param name="a">A dictionary.</param>
  * <param name="b">A dictionary.</param>
  * <typeparam name="TKey">Key type.</typeparam>
  * <typeparam name="TValue">Value type.</typeparam>
  * <returns>True if and only if key-value pairs equal.</returns>
  */
 public static bool Equals <TKey, TValue>(SCG.IDictionary <TKey, TValue> a, SCG.IDictionary <TKey, TValue> b)
 => ReferenceEquals(a, b) ||
 a.Count.Equals(b.Count) &&
 a.All
     (element
 public void LinkedDictionary_Generic_Constructor_IDictionary(int count)
 {
     SCG.IDictionary <TKey, TValue> source = GenericIDictionaryFactory(count);
     SCG.IDictionary <TKey, TValue> copied = new LinkedDictionary <TKey, TValue>(source);
     Assert.Equal(source, copied);
 }