-
Notifications
You must be signed in to change notification settings - Fork 0
/
DistributionElement.cs
39 lines (34 loc) · 1.05 KB
/
DistributionElement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
namespace RoundedDistributionComparison5
{
public struct DistributionElement<T>
where T : unmanaged
{
public T Key;
public double Remain;
public int Percent;
public DistributionElement(T key, double percent)
{
Key = key;
Percent = (int)Math.Truncate(percent);
Remain = percent - Percent;
}
public DistributionElement(T key, int percent)
{
Remain = 0;
Key = key;
Percent = percent;
}
public double InitAndGetRemain(T key, double value)
{
Key = key;
Percent = (int)value;
Remain = value - Percent;
return Remain;
}
public DistributionElement<T> DecreasePercent() => new(Key, Percent - 1);
public DistributionElement<T> IncreasePercent() => new(Key, Percent + 1);
public override string ToString() => $"{Percent} {Remain:F3}";
public override int GetHashCode() => Key.GetHashCode();
}
}