CompareRElayEvent() helpers.

This commit is contained in:
fiatjaf
2026-03-08 22:57:38 -03:00
parent 4719c0bc9f
commit 2c0d9712e3
+16
View File
@@ -71,6 +71,22 @@ func CompareEventReverse(b, a Event) int {
return cmp.Compare(a.CreatedAt, b.CreatedAt)
}
// CompareRelayEvent is meant to to be used with slices.Sort
func CompareRelayEvent(a, b RelayEvent) int {
if a.CreatedAt == b.CreatedAt {
return bytes.Compare(a.ID[:], b.ID[:])
}
return cmp.Compare(a.CreatedAt, b.CreatedAt)
}
// CompareRelayEventReverse is meant to to be used with slices.Sort
func CompareRelayEventReverse(b, a RelayEvent) int {
if a.CreatedAt == b.CreatedAt {
return bytes.Compare(a.ID[:], b.ID[:])
}
return cmp.Compare(a.CreatedAt, b.CreatedAt)
}
// AppendUnique adds items to an array only if they don't already exist in the array.
// Returns the modified array.
func AppendUnique[I comparable](arr []I, item ...I) []I {