mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-14 04:14:28 +02:00
CompareEvent/Ptr/Reverse utils.
This commit is contained in:
41
utils.go
41
utils.go
@@ -35,3 +35,44 @@ func CompareEvent(a, b Event) int {
|
||||
}
|
||||
return cmp.Compare(a.CreatedAt, b.CreatedAt)
|
||||
}
|
||||
|
||||
func CompareEventReverse(b, a Event) int {
|
||||
if a.CreatedAt == b.CreatedAt {
|
||||
return strings.Compare(a.ID, b.ID)
|
||||
}
|
||||
return cmp.Compare(a.CreatedAt, b.CreatedAt)
|
||||
}
|
||||
|
||||
func CompareEventPtr(a, b *Event) int {
|
||||
if a == nil {
|
||||
if b == nil {
|
||||
return 0
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
} else if b == nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
if a.CreatedAt == b.CreatedAt {
|
||||
return strings.Compare(a.ID, b.ID)
|
||||
}
|
||||
return cmp.Compare(a.CreatedAt, b.CreatedAt)
|
||||
}
|
||||
|
||||
func CompareEventPtrReverse(b, a *Event) int {
|
||||
if a == nil {
|
||||
if b == nil {
|
||||
return 0
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
} else if b == nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
if a.CreatedAt == b.CreatedAt {
|
||||
return strings.Compare(a.ID, b.ID)
|
||||
}
|
||||
return cmp.Compare(a.CreatedAt, b.CreatedAt)
|
||||
}
|
||||
|
Reference in New Issue
Block a user