qwertie / LoycCore

The Loyc Core Libraries. Loyc.Essentials fills in gaps in the .NET Base Class Library; Loyc.Collections adds sophisticated data structures; and Loyc.Syntax contains the LES parser and other parsing-related services including base classes for LLLPG.
Other
44 stars 10 forks source link

AList #7

Open ZigmundL opened 4 years ago

ZigmundL commented 4 years ago

Hello. I have a list of 8.9kk objects which are loaded from sql database. I need to split this list into parts with some checks, conditions, shuffling and removals. Here is the first part:

 List<DbEntry> list = all.Where(e => e.city == "Liverpool").Take(150000).ToList();
RemoveP(list);

List<DbEntry> list2 = all.Where(e => e.city == "London").Take(150000).ToList();
RemoveL(list2);

 list.AddRange(list2);
list.Shuffle();

I need to take 2x 150k from all (8,9kk), then remove them from all-list. My methods RemoveP() and RemoveL() are "optimised" with exact city and citys row position(ids) in db - very specific. (for loops with predefined hardcoded limits, that set object=null then RemoveAll(x=>x==null); ). They are not very interesting, I could have archived this methods are done in ~10 mins each.

Then I've met your lib which looks promising.

I'm trying to follow your "simply to add "A" in front". And it's not working, saying that ToList() is not returning AList. Casting is not working too (AList)list.ToList(); How is this working?

qwertie commented 4 years ago

ToList is provided by LINQ and returns List<T>, not AList.

To ensure the data type is AList, you would have to call methods provided by AList.

For example, instead of ToList, use new AList<DbEntry>(all.Where(...)...).

If all is an AList, you could also write it like this:

var list = all.Clone();
list.RemoveAll(c => c.citt != "Liverpool");  // instead of `Where`
list = list.RemoveSection(0,150000);  // instead of `Take`
Console.WriteLine(string.Join(",",list));

But I would guess that the first approach is faster in this case.