Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AList #7

Open
ZigmundL opened this issue Apr 22, 2020 · 1 comment
Open

AList #7

ZigmundL opened this issue Apr 22, 2020 · 1 comment

Comments

@ZigmundL
Copy link

ZigmundL commented Apr 22, 2020

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
Copy link
Owner

qwertie commented Apr 24, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants