EqualDistributionLib 1.0.1

dotnet add package EqualDistributionLib --version 1.0.1
                    
NuGet\Install-Package EqualDistributionLib -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EqualDistributionLib" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EqualDistributionLib" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="EqualDistributionLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EqualDistributionLib --version 1.0.1
                    
#r "nuget: EqualDistributionLib, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EqualDistributionLib@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EqualDistributionLib&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=EqualDistributionLib&version=1.0.1
                    
Install as a Cake Tool

Purpose

a library in C# that helps distributing items equally to bins based on a property value.

Examples

In memory example

	class TestItem(int key, string value) { public int key=key; public string value=value; }
	List<TestItem> items=[];
	Dictionary<int, ICollection<TestItem>> bins=new();
	int notInBin=0;
	items = Enumerable.Range(1, 1023).Select(i => new TestItem(Random.Shared.Next(0, 16), $"Item {i}")).ToList();
	// add some more randomness
	for (var i = 0; i < Random.Shared.Next(200, 500); ++i)
	{
		items.ElementAt(Random.Shared.Next(0, items.Count)).key = Random.Shared.Next(0, 16);
	}
	bins = items
		.Where(a => a.key < 10)
		.GroupBy(a => a.key)
		.ToDictionary(g => g.Key, g => (ICollection<TestItem>)g.ToList());
	notInBin = items.Count(a => !bins.ContainsKey(a.key));
	EqualDistribution.DumpBins(bins, Console.WriteLine);
	var result=await EqualDistribution.DistributeEquallyAsync(items, a => a.key, bins, null);
	EqualDistribution.DumpBins(bins, Console.WriteLine);

DB Example

You have a DB table processingTable with a column "processingDate". You have a huge number of items or processig an item requires many resources and want to distribute the processing across n-dates equally. You are use EF core to access the DB.

var grouped=dbContext.ProcessingTable
	.GroupBy(a=>a.ProcessingDate) // ProcesingDate must not be null
	.Select(g=>new BinItem() {Key=g.Key, Count=g.Count()})
	.ToArray()
var alreadyMoved=new HashSet<int>();
await EqualDistribution(grouped, (count, from,to)=> {
	var moved=0;
	(await processingTable
	.Where(a=>a.ProcessingDate==from && !alreadyMoved.Contains(a.Id))
	.Take(count)
	.ToListAsync())
	.ForEach(itemToMove=> {
		itemToMove.processingDate=to; // moves the processingDate
		// required or the next select will return out-of-synch results

	  		  alreadyMoved.Add(itemToMove.ID); 
			moved++;
	    });
		// altenative is to call SaveChangesAsynch() at the end of every move operation: slower but will keep partial improvements in case of some error saving all changes all at once
		// await SaveChangesAsync();
return moved;
});
await dbContext.SaveChangesAsync();

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 133 1/15/2026
1.0.0 121 1/15/2026