Lean  $LEAN_TAG$
IExtendedDictionary.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using Python.Runtime;
17 
19 {
20  /// <summary>
21  /// Represents a generic collection of key/value pairs that implements python dictionary methods.
22  /// </summary>
23  public interface IExtendedDictionary<TKey, TValue>
24  {
25  /// <summary>
26  /// Removes all keys and values from the <see cref="IExtendedDictionary{TKey, TValue}"/>.
27  /// </summary>
28  void clear();
29 
30  /// <summary>
31  /// Creates a shallow copy of the <see cref="IExtendedDictionary{TKey, TValue}"/>.
32  /// </summary>
33  /// <returns>Returns a shallow copy of the dictionary. It doesn't modify the original dictionary.</returns>
34  PyDict copy();
35 
36  /// <summary>
37  /// Creates a new dictionary from the given sequence of elements.
38  /// </summary>
39  /// <param name="sequence">Sequence of elements which is to be used as keys for the new dictionary</param>
40  /// <returns>Returns a new dictionary with the given sequence of elements as the keys of the dictionary.</returns>
41  PyDict fromkeys(TKey[] sequence);
42 
43  /// <summary>
44  /// Creates a new dictionary from the given sequence of elements with a value provided by the user.
45  /// </summary>
46  /// <param name="sequence">Sequence of elements which is to be used as keys for the new dictionary</param>
47  /// <param name="value">Value which is set to each each element of the dictionary</param>
48  /// <returns>Returns a new dictionary with the given sequence of elements as the keys of the dictionary.
49  /// Each element of the newly created dictionary is set to the provided value.</returns>
50  PyDict fromkeys(TKey[] sequence, TValue value);
51 
52  /// <summary>
53  /// Returns the value for the specified key if key is in dictionary.
54  /// </summary>
55  /// <param name="key">Key to be searched in the dictionary</param>
56  /// <returns>The value for the specified key if key is in dictionary.
57  /// None if the key is not found and value is not specified.</returns>
58  TValue get(TKey key);
59 
60  /// <summary>
61  /// Returns the value for the specified key if key is in dictionary.
62  /// </summary>
63  /// <param name="key">Key to be searched in the dictionary</param>
64  /// <param name="value">Value to be returned if the key is not found. The default value is null.</param>
65  /// <returns>The value for the specified key if key is in dictionary.
66  /// value if the key is not found and value is specified.</returns>
67  TValue get(TKey key, TValue value);
68 
69  /// <summary>
70  /// Returns a view object that displays a list of dictionary's (key, value) tuple pairs.
71  /// </summary>
72  /// <returns>Returns a view object that displays a list of a given dictionary's (key, value) tuple pair.</returns>
73  PyList items();
74 
75  /// <summary>
76  /// Returns a view object that displays a list of all the keys in the dictionary
77  /// </summary>
78  /// <returns>Returns a view object that displays a list of all the keys.
79  /// When the dictionary is changed, the view object also reflect these changes.</returns>
80  PyList keys();
81 
82  /// <summary>
83  /// Returns and removes an arbitrary element (key, value) pair from the dictionary.
84  /// </summary>
85  /// <returns>Returns an arbitrary element (key, value) pair from the dictionary
86  /// removes an arbitrary element(the same element which is returned) from the dictionary.
87  /// Note: Arbitrary elements and random elements are not same.The popitem() doesn't return a random element.</returns>
88  PyTuple popitem();
89 
90  /// <summary>
91  /// Returns the value of a key (if the key is in dictionary). If not, it inserts key with a value to the dictionary.
92  /// </summary>
93  /// <param name="key">Key with null/None value is inserted to the dictionary if key is not in the dictionary.</param>
94  /// <returns>The value of the key if it is in the dictionary
95  /// None if key is not in the dictionary</returns>
96  TValue setdefault(TKey key);
97 
98  /// <summary>
99  /// Returns the value of a key (if the key is in dictionary). If not, it inserts key with a value to the dictionary.
100  /// </summary>
101  /// <param name="key">Key with a value default_value is inserted to the dictionary if key is not in the dictionary.</param>
102  /// <param name="default_value">Default value</param>
103  /// <returns>The value of the key if it is in the dictionary
104  /// default_value if key is not in the dictionary and default_value is specified</returns>
105  TValue setdefault(TKey key, TValue default_value);
106 
107  /// <summary>
108  /// Removes and returns an element from a dictionary having the given key.
109  /// </summary>
110  /// <param name="key">Key which is to be searched for removal</param>
111  /// <returns>If key is found - removed/popped element from the dictionary
112  /// If key is not found - KeyError exception is raised</returns>
113  TValue pop(TKey key);
114 
115  /// <summary>
116  /// Removes and returns an element from a dictionary having the given key.
117  /// </summary>
118  /// <param name="key">Key which is to be searched for removal</param>
119  /// <param name="default_value">Value which is to be returned when the key is not in the dictionary</param>
120  /// <returns>If key is found - removed/popped element from the dictionary
121  /// If key is not found - value specified as the second argument(default)</returns>
122  TValue pop(TKey key, TValue default_value);
123 
124  /// <summary>
125  /// Updates the dictionary with the elements from the another dictionary object or from an iterable of key/value pairs.
126  /// The update() method adds element(s) to the dictionary if the key is not in the dictionary.If the key is in the dictionary, it updates the key with the new value.
127  /// </summary>
128  /// <param name="other">Takes either a dictionary or an iterable object of key/value pairs (generally tuples).</param>
129  void update(PyObject other);
130 
131  /// <summary>
132  /// Returns a view object that displays a list of all the values in the dictionary.
133  /// </summary>
134  /// <returns>Returns a view object that displays a list of all values in a given dictionary.</returns>
135  PyList values();
136  }
137 }