小编Kev*_*ter的帖子

非常大的收藏效率; 迭代和排序

我有一个csv解析器读取超过1500万行(有许多重复),一旦解析成结构,需要添加到集合中.每个结构都有属性Key(int),A(datetime)和B(int)(以及其他与此无关的属性).

要求A:集合需要通过密钥强制执行唯一性.

要求B:在后面的步骤中,我需要按属性A(时间戳)和B(int)排序的集合.

约束:结构最终需要逐个遍历,并引用邻居(LinkedList在这里提供最干净的解决方案); 此操作的重点是对集合进行分区.请假设这是最早发生分区的(即,它不能在解析阶段进行分区).

我发现SortedSet在需求A中工作得很好,并且它也非常高效,即使O(log n)插入比使用HashSet<T>O(1)慢得多,尽管我不关心排序关键. HashSet<T>当集合变得庞大时,它会陷入困境,这显然是一个已知的问题,而SortedSet<T>不会遇到这个缺点.

问题:当我到达需求B的步骤时,对集合进行排序(SortedSet<T>传递给方法IEnumerable<T>)需要花费大量时间(磨削20分钟以上,所有内存中,没有页面文件使用).

问题:哪个(哪些)集合最适合解决此问题?一个想法是使用两个集合:一个用于强制唯一性(如一个HashSet<int>SortedSet<int>一个键),另一个SortedSet<T>用于在解析阶段处理排序(即,尽可能向上游).但是应用程序已经占用大量内存,并且需要页面文件的性能损失令人望而却步.
对于一个通过一个特征强制实现唯一性但通过其他不相关特征排序的集合,我有什么选择? SortedSet<T>使用IComparer<T>(但不能同时IComparer<T>IEquitable<T>),所以如果它依靠的CompareTo强制唯一性,那么它似乎不适合我的要求.是继承SortedSet的方法吗?

编辑:排序代码:

SortedSet<Dto> parsedSet = {stuff};
var sortedLinkedStructs = new LinkedList<Dto>(parsedSet.OrderBy(t => t.Timestamp).ThenBy(i => i.SomeInt));
Run Code Online (Sandbox Code Playgroud)

结构:

public readonly struct Dto: IEquatable<Dto>, IComparer<Dto>, IComparable<Dto>
{
     public readonly datetime Timestamp;
     public readonly int SomeInt;
     public readonly int Key;

     ctor(ts, int, key){assigned}

     public bool …
Run Code Online (Sandbox Code Playgroud)

c# sorting sortedset

50
推荐指数
1
解决办法
3357
查看次数

BadImageException:'无法加载文件或程序集'Microsoft.VisualStudio.QualityTools.VideoRecorderEngine'或其依赖项之一.

将Visual Studio 2017更新到15.5后,我无法再调试单元测试(我可以运行测试,我可以调试非测试程序).

我一直得到以下例外情况:

Exception thrown: 'System.BadImageFormatException' in mscorlib.dll
Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.VideoRecorderEngine' or one of its dependencies. The module was expected to contain an assembly manifest.

Exception thrown: 'System.BadImageFormatException' in mscorlib.dll
Could not load file or assembly 'VSTestVideoRecorder' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Exception thrown: 'System.BadImageFormatException' in mscorlib.dll
Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.VideoRecorderEngine' or one of its dependencies. The module was expected …
Run Code Online (Sandbox Code Playgroud)

unit-testing visual-studio

9
推荐指数
1
解决办法
664
查看次数

Entity Framework中的SaveChanges是否会包装数据库事务中的所有更改

我在我的asp.net mvc web应用程序中有以下方法,我使用Ado.net实体框架来映射我当前的数据库表: -

public void changeDeviceSwitch(int fromID , int toID)
{
     var currentdevices = tms.TMSSwitchPorts.Where(a => a.SwitchID == fromID);
     foreach (var d in currentdevices)
     {
          tms.TMSSwitchPorts.Remove(d);            
     }
     foreach (var d in currentdevices)
     {
          TMSSwitchPort tsp = new TMSSwitchPort() 
                { SwitchID = toID,
                  TechnologyID = d.TechnologyID,
                  PortNumber = d.PortNumber };
          tms.TMSSwitchPorts.Add(d);
     }
     tms.SaveChanges();    
}
Run Code Online (Sandbox Code Playgroud)

我的上述方法将在数据库中生成多个删除和添加操作.所以说它会导致5个删除操作和5个插入操作,在这种情况下会调用我的情况下的SaveChangies(),将10个操作包装在一个数据库事务中?所以要么所有的更改都发生了,要么都没有?谢谢

asp.net-mvc entity-framework transactions asp.net-mvc-5

3
推荐指数
1
解决办法
829
查看次数