I4oIt is an extension of LINQ. By allowing us to add "indexes" to objects, we can improve the speed of LINQ operations. The author claims that the speed of often will be improved after i4o is used.Over one thousandTimes.
When optimizing database queries, we often think of adding appropriate indexes to tables to greatly improve execution efficiency. The i4o implementation is similar to this method, we only need to add an Indexable attribute to the class, and then use indexablecollection <t> to implement a set of classes that use "indexes, in this way, the search speed is improved to a certain extent than the sequential search speed.
For example, we can use:
1 VaR MERs = New Indexablecollection < Cnbloguser > () {
2 New Customer {Key= 1, Name= "Fanweixiao"} ,
3 New Customer {Key= 2, Name= "Lovewangshu"}
4 } ;
Where extension in i4o
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 duplicate ity 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 }
WhileSlinqThis is to allow LINQ to act on streaming data. Currently, this project is only a demo version, and the implementation method is to add a series of extension methods for LINQ, if you are interested, you can go down to sourcecode and check whether Visual Studio orcas Beta 1 is installed.
By the way, I will post two projects related to LINQ on codeplex:
- How does LINQ come from? View LINQ-SQO
- Use LINQ: LINQ extensions on C ++/CLI