![](/img/trans.png)
[英]Which data structure should be used for reading and storing about 5 million entries from a text file
[英]Which data structure should I use for having sorted data, where the key can be used on multiple entries
我有一些数据集要存储在哪里,我有一个密钥可以找到相关的对象,但是该密钥不是唯一的,并且同一密钥可以具有多个指针。
我希望能够将此数据放入类似于SortedList的结构中,但是它需要唯一的键才能工作。
是否有任何可用的C#对象允许我执行此操作。 在下面的示例中,我将字符串用作引用对象,但是它也可能是任何其他对象,就像SortedList可以包含任何类型的对象一样。
例如。
unknownDatastructure structure = new unknownDatastructure<string, string>();
structure.add("left","the remainder after a removal");
structure.add("left","a direction opposite of right");
structure.add("right","a direction opposite of left");
structure.add("right","opposite of being wrong");
而且我想返回一个与调用时匹配搜索键的对象数组,或者是第一个条目(我可以通过索引找到剩余的对象)。
例如。
List<string> results = structure.FindAll("Left");
如果列表将包含实际引用的对象,则在这种情况下为“清除的剩余部分”和“与权利相反的方向”。
int firstmatch = structure.FindIndex("Right");
其中int为2(0 =第一个左,1 =第二个左,2 =第一个右,3 =第二个右)。 我不在乎左2或右2的排序顺序,只需要能够找到第一个重复项,然后我就可以根据需要逐步浏览所有条目以创建“ FindAll”功能
Dictionary<K,V>
不支持重复键。 您将必须维护每个键的所有条目的列表:
Dictionary<string, List<string>>
只需创建自己的:
Dictionary<TKey, List<TValue>> dictionary;
然后,您的代码将类似于:
List<TValue> list;
if(!dictionary.TryGetValue(key, out list))
{
list = new List<TValue>();
dictionary[key] = list;
}
list.Add("whatever...");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.