Skip to content

Implemented a Generic Bucket sorting alorithm#280

Open
firstkindgamer wants to merge 1 commit intoDeadcows:masterfrom
firstkindgamer:firstkindgamer-patch-2
Open

Implemented a Generic Bucket sorting alorithm#280
firstkindgamer wants to merge 1 commit intoDeadcows:masterfrom
firstkindgamer:firstkindgamer-patch-2

Conversation

@firstkindgamer
Copy link
Copy Markdown
Contributor

Adds a method to convert a collection to a bucket dictionary.
Allows user to define storage type, and algorithm for creating dictionary keys.

Issues:

Generic Usage Cannot be inferred from type arguments.
Buckets are created from adding to collection, highly inefficient for list types

Adds a method to convert a collection to a bucket dictionary.

Issues: 
Generic Usage Cannot be inferred from type arguments
buckets are created from adding lists, highly inefficient for bucket collection types
@firstkindgamer
Copy link
Copy Markdown
Contributor Author

firstkindgamer commented Apr 1, 2026

Hello again DeadCow, In my time coding since I've last commited, there has been plenty of times where I needed to take a collection, and divide it by a comparator (good for comparing data against a different type of data).

Wish I knew more about implementing generic methods, but I hope this offers a benefit to the current toolbox.

@Deadcows
Copy link
Copy Markdown
Owner

Deadcows commented Apr 4, 2026

Hey! Thank you for the contribution, it looks interesting!
I'm thinking now, it looks really similar to linq's GroupBy functionality, can you explain why you would prefer your implementation, or give a concrete usage example?

For example, Items grouped by the ItemType enum, and with an conversion to Dictionary with List values if you specifically need it:

var itemsByType = Items.GroupBy(i => i.ItemType);
var itemsByType = Items.GroupBy(i => i.ItemType).ToDictionary(g => g.Key, g => g.ToList());

@firstkindgamer
Copy link
Copy Markdown
Contributor Author

Hey! Thank you for the contribution, it looks interesting! I'm thinking now, it looks really similar to linq's GroupBy functionality, can you explain why you would prefer your implementation, or give a concrete usage example?

For example, Items grouped by the ItemType enum, and with an conversion to Dictionary with List values if you specifically need it:

var itemsByType = Items.GroupBy(i => i.ItemType);
var itemsByType = Items.GroupBy(i => i.ItemType).ToDictionary(g => g.Key, g => g.ToList());

I actually didn't know of the GroupBy linq method, this does seem pretty related hmm. The GroupBy method seems more generic. The only reason to use this method over the GroupBy method would be that you could use your own IList classes, such as ObservableArray, or a SearchTree. The GroupBy method is defiantly preferred, as with this method you have to specify all the type args in <>. The decision is up to you, I'm a bit inexperienced with advanced gameplay systems.

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

Successfully merging this pull request may close these issues.

2 participants