2
0

probability.go 469 B

1234567891011121314151617181920212223
  1. package sentio
  2. import (
  3. "cmp"
  4. "slices"
  5. )
  6. func CompareProbabilityStamps(a, b *Probability_Stamp) int {
  7. return cmp.Compare(a.Time.AsTime().Unix(), b.Time.AsTime().Unix())
  8. }
  9. func (x *Probability) First() (*Probability_Stamp, bool) {
  10. return x.Next(0)
  11. }
  12. func (x *Probability) Next(n int) (*Probability_Stamp, bool) {
  13. if x.Stamps == nil || len(x.Stamps) <= n {
  14. return nil, false
  15. }
  16. slices.SortFunc(x.Stamps, CompareProbabilityStamps)
  17. return x.Stamps[n], true
  18. }