-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHashAddress.cs
44 lines (34 loc) · 1017 Bytes
/
HashAddress.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
40
41
42
43
44
namespace HydraScript.Domain.BackEnd.Impl.Addresses;
public class HashAddress(int seed) : IAddress
{
private readonly int _seed = seed;
private string? _name;
private readonly Guid _id = Guid.NewGuid();
public IAddress Next { get; set; } = default!;
public string Name
{
get
{
if (_name is null)
{
var baseName = $"{unchecked((uint)GetHashCode())}{_id:N}";
var nameArray = Random.Shared.GetItems(baseName.AsSpan(), 10);
_name = "_t" + new string(nameArray);
}
return _name;
}
}
public bool Equals(IAddress? other)
{
if (other is HashAddress hashed)
return _seed == hashed._seed && _id == hashed._id;
return false;
}
public override int GetHashCode()
{
var i1 = _seed ^ 17;
var i2 = 31 * _seed + i1;
return HashCode.Combine(i1, i2);
}
public override string ToString() => "\t";
}