ident: system identifier generator

This is pretty fast and guarantees uniqueness when initialised correctly.

Signed-off-by: Yonah <contrib@gensokyo.uk>
This commit is contained in:
2026-03-22 22:22:04 +09:00
parent 22b8cc3884
commit 338cb1e000
5 changed files with 81 additions and 14 deletions

View File

@@ -89,8 +89,10 @@ func TestFS(t *testing.T) {
{"valid", ident.F[ident.S, *ident.S]{
I: &ident.S{
Site: ident.TrivialSite,
Host: ident.TrivialHost,
PartG: ident.PartG{
Site: ident.TrivialSite,
Host: ident.TrivialHost,
},
Time: uint64(time.Date(
0xfd, 7, 15,
@@ -130,8 +132,10 @@ func TestFM(t *testing.T) {
},
System: ident.S{
Site: ident.TrivialSite,
Host: ident.TrivialHost,
PartG: ident.PartG{
Site: ident.TrivialSite,
Host: ident.TrivialHost,
},
Time: uint64(time.Date(
0xfd, 7, 15,
@@ -207,3 +211,19 @@ func TestErrors(t *testing.T) {
})
}
}
func BenchmarkGeneratorS(b *testing.B) {
var s ident.S
g := ident.New(ident.TrivialSite, ident.TrivialHost)
for b.Loop() {
g.S(&s)
}
}
func BenchmarkGeneratorM(b *testing.B) {
var pm ident.PartM
g := ident.New(ident.TrivialSite, ident.TrivialHost)
for b.Loop() {
g.M(&pm, 0xbadf00d)
}
}