惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
P
Proofpoint News Feed
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
The Last Watchdog
The Last Watchdog
F
Fortinet All Blogs
S
Schneier on Security
Help Net Security
Help Net Security
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
I
InfoQ
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
Stack Overflow Blog
Stack Overflow Blog
T
Troy Hunt's Blog
人人都是产品经理
人人都是产品经理
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
Forbes - Security
Forbes - Security
Vercel News
Vercel News
S
Security Affairs
美团技术团队
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
U
Unit 42
Recorded Future
Recorded Future
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
P
Palo Alto Networks Blog
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 【当耐特】

博客园 - 维生素C.NET

[ie8特性1] 6个conection per domain的设计 asp.net 3.5 extensions readme Vista上无法使用WCF的处理方法 SQL Server 2005 Management Studio假死的情况 Internal .Net Framework Data Provider error 6 查找含有特定字符的存储过程 firefox, IE6, IE7在CSS hack上的入口点 不知道多少人存在这个误解: Google Reader/Google Notebook使用以前的英文界面的办法 编译IronRuby项目和修复其中的一些bugs IronRuby博客中文版-- IronRuby: a promising start IronRuby的下载 http的基础知识帮助减少代码量和复杂度的一个Demo - 维生素C.NET - 博客园 关于SQL Server的两个细节 在Longhorn Server上无法安装SQL Server 2008 (Katmai) 设置Longhorn Server中的图片缩略图显示 关于控件部分的看法--读Programming ASP.NET中文版 分享一本入门级好书:Programming ASP.NET中文版 555,又丢了一辆自行车
为LINQ提速的i4o和增强功能的SLINQ
维生素C.NET · 2007-06-28 · via 博客园 - 维生素C.NET

i4o是对LINQ的一个扩展,通过允许我们在对象上添加“索引”来提高LINQ运算速度,作者号称使用i4o后速度提升often over one thousand times。

我们在进行数据库查询优化时,往往第一想到的就是给Tables添加合适的Index来大幅度提升执行效率,i4o的实现也是类似这个方式,我们只要给class添加一个Indexable属性,然后使用IndexableCollection<T>来实现一个使用“索引”的类的集合就可以了,这样比起顺序性的搜索就在一定程度上提高了速度。

比如我们可以这样用:

1var customers = new IndexableCollection<CnblogUser>() 
2                new Customer {Key = 1, Name = "fanweixiao" },
3                new Customer {Key = 2, Name = "lovewangshu" }
4}
;


i4o中对Where的扩展

 1//extend the where when we are working with indexable collections! 
 2        public static IEnumerable<T> Where<T>
 3        (
 4            this IndexableCollection<T> sourceCollection,
 5            Expression<Func<T, bool>> expr
 6            )
 7        {
 8            //our indexes work from the hash values of that which is indexed, regardless of type
 9            int? hashRight = null;
10            bool noIndex = true;
11            //indexes only work on equality expressions here
12            if (expr.Body.NodeType == ExpressionType.Equal)
13            {
14                //Equality is a binary expression
15                BinaryExpression binExp = (BinaryExpression)expr.Body;
16                //Get some aliases for either side
17                Expression leftSide = binExp.Left;
18                Expression rightSide = binExp.Right;
19
20                hashRight = GetHashRight(leftSide, rightSide);
21
22                //if we were able to create a hash from the right side (likely)
23                if (hashRight.HasValue && HasIndexablePropertyOnLeft<T>(leftSide,sourceCollection))
24                {
25                    //cast to MemberExpression - it allows us to get the property
26                    MemberExpression propExp = (MemberExpression)leftSide;
27                    string property = propExp.Member.Name;
28                    Dictionary<int, List<T>> myIndex =
29                            sourceCollection.GetIndexByProperty(property);
30                    if (myIndex.ContainsKey(hashRight.Value))
31                    {
32                        IEnumerable<T> sourceEnum = myIndex[hashRight.Value].AsEnumerable<T>();
33                        IEnumerable<T> result = sourceEnum.Where<T>(expr.Compile());
34                        foreach (T item in result)
35                            yield return item;
36                    }

37                    noIndex = false//we found an index, whether it had values or not is another matter
38                }

39
40            }

41            if (noIndex) //no index?  just do it the normal slow way then
42            {
43                IEnumerable<T> sourceEnum = sourceCollection.AsEnumerable<T>();
44                IEnumerable<T> result = sourceEnum.Where<T>(expr.Compile());
45                foreach (T resultItem in result)
46                    yield return resultItem;
47            }

48
49        }

SLINQ则是可以让LINQ作用于streaming data上的,目前这个项目只算是个Demo版本,实现方式是为LINQ添加了一系列的扩展方法,有兴趣的朋友可以down下sourcecode来看看,需要注意的是要安装Visual Studio Orcas beta 1。

顺便帖两个codeplex上与LINQ相关的项目:

  1. LINQ是怎么来的?看LINQ-SQO
  2. 在C++/CLI上用LINQ:LINQ Extensions