Multiple orders in a single list

I have a problem with a ranking system I am using.

Scenario:

An online game with around 10k players calculates a real time ranking of points when a certain event occurs. Events don’t occur that often, around 1 time per minute. This ranking is kept in the cache for quick calculations, sorting and access.

Now players can form groups and play against each other, but the scoring system is the same, only the ranking is based for the players in that group.

At first I created for every group a separate ranking, effectively having the same scores as the complete ranking, but with different positions in the ranking.

This is trivial because there are over 1.000 groups and every time an event occurs all the groups would have to be updated.

So what I did now is when the group ranking is requested take only the players that are in that group from the complete ranking and show them. The positions would have to be re-counted.

That re-counting is where the problem is. Because the sub-list is by-reference from the complete ranking list I cannot change the position of the player in the sub-ranking without updating it in the complete ranking, because it’s just a reference.

I came up with two solutions:

  • Create a copy from the record every time it is requested and do some output caching (not very desirable because the rankings are live)
  • Create a copy and store this in a cache which is reset when an event occurs.
  • Create a sub-list with just the positions which is updated when an event occurs.

And the last solution: do the position counting in the output instead in the business side. This would be the best solution, only problem is that on some pages this text appears: “You are on position # in the ranking” where # is your ranking position. This number would be tedious to get then.

Does anybody have any suggestions to this problem?

There may be minor performance considerations involved with it, but this sounds like the sort of thing LINQ is very useful for. The basic idea is this:

var enormousList = new List<record>();

//var enormousList = ... (over 5 million records)
var subList = enormousList.Where(onerecord => onerecord.clanName == "RAGIN CAJUN");

// At this point in the program, NO filtration has occurred just yet and little processing
// power has been used.

// This enumerates the list once for the "ragin cajun" filter, so this may take a while.
var sublistCount = subList.Count(); //take note that Count is a function here, not a property. 
var pageSize = 50;
var hudDisplayPage = enormousList.Take(pageSize).Select((record, idx) =>
{
    return new HudPage(idx, record.clanName, record.playerName);
});
// for those who couldn't keep track; hudDisplayPage is now an IEnumerable (which you can use for-each on) containing
// 50 records of the list fitting the description. These are dynamic constructs; even now, hudDisplayPage hasn't
// yet been evaluated. If you want to cache one of these values so you're not doing the processing again later...
var saved = hudDisplayPage.ToArray();

This sort of system should make it relatively easy to take slices out of your data, and precache whichever ones are likely to be needed many times.
Also, take note of this handy tip (but ONLY for queries that end up being a performance hit)

var saved = hudDisplayPage.AsParallel().ToArray();

That line should essentially multithread your filtration process, so that all cores of your processor are on it.

I can’t say I know enough about your problem to write out its solution in code; but it seems like your issue is mainly in figuring out the list processing, against a single list you don’t want to modify or copy. Hope I haven’t misunderstood your issue!

5

As you say yourself, the best solution is to do the counting in the output, instead of storing it in the various lists. That way you don’t have to store (and recalculate) the ranking numbers on each event for each (sub-)list, but you only calculate them when needed.

For the “You are on position # in the ranking” text, you could have a method in the class that represents the ranking list, like this: RankingList::getRankingOf(Player). Only if this information is costly to obtain and you only need the ranking from the overall list, you could consider caching the current ranking numbers in the overall list (as an optimisation strategy).

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật