Skip to content

Commit

Permalink
CompareEvent() for helping with slices.BinarySearch()
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Sep 15, 2024
1 parent 87e696e commit a54852f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nostr

import (
"cmp"
"encoding/hex"
"net/url"
"strings"
Expand All @@ -27,3 +28,10 @@ func IsValid32ByteHex(thing string) bool {
_, err := hex.DecodeString(thing)
return err == nil
}

func CompareEvent(a, b Event) int {
if a.CreatedAt == b.CreatedAt {
return strings.Compare(a.ID, b.ID)
}
return cmp.Compare(a.CreatedAt, b.CreatedAt)
}

0 comments on commit a54852f

Please sign in to comment.