-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from gochore/v2
- Loading branch information
Showing
53 changed files
with
7,453 additions
and
11,434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
generage: | ||
rm -f *_sequence.go | ||
rm -f gen_*.go | ||
go run cmd/generate/main.go | ||
|
||
test: | ||
go test -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/gochore/timeseq/_draft/timeseq | ||
|
||
go 1.15 | ||
|
||
require github.com/gochore/pt v1.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/gochore/pt v1.1.2 h1:3qS64f1ZrFgp28dperUHfo7U22gL/QeGWsaxQ0veIBE= | ||
github.com/gochore/pt v1.1.2/go.mod h1:8fd2g+qoAO1QIorsgi9vLJCMudJ5m+nDhY8r1nPP6dg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// Code generated by cmd/generate. DO NOT EDIT. | ||
|
||
package timeseq | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package timeseq | ||
|
||
import ( | ||
"sort" | ||
"time" | ||
) | ||
|
||
// Sort will sort sequence by time | ||
func Sort(seq Sequence) { | ||
if seq == nil { | ||
return | ||
} | ||
sort.Sort(sortableSequence{seq}) | ||
} | ||
|
||
// Range return sub sequence | ||
func Range(seq Sequence, afterOrEqual, beforeOrEqual *time.Time) Sequence { | ||
i := 0 | ||
if afterOrEqual != nil { | ||
i = sort.Search(seq.Len(), func(i int) bool { | ||
return !seq.Time(i).Before(*afterOrEqual) | ||
}) | ||
} | ||
j := seq.Len() | ||
if beforeOrEqual != nil { | ||
j = sort.Search(seq.Len(), func(j int) bool { | ||
return !seq.Time(j).Before(*beforeOrEqual) | ||
}) | ||
if j < seq.Len() && seq.Time(j).Equal(*beforeOrEqual) { | ||
j++ | ||
} | ||
} | ||
return seq.Slice(i, j) | ||
} | ||
|
||
// First return the index of the first item | ||
func First(seq Sequence, afterOrEqual *time.Time) int { | ||
i := 0 | ||
if afterOrEqual != nil { | ||
i = sort.Search(seq.Len(), func(i int) bool { | ||
return !seq.Time(i).Before(*afterOrEqual) | ||
}) | ||
if i >= seq.Len() { | ||
i = -1 | ||
} | ||
} | ||
return i | ||
} | ||
|
||
// Last return the index of the last item | ||
func Last(seq Sequence, beforeOrEqual *time.Time) int { | ||
j := seq.Len() - 1 | ||
if beforeOrEqual != nil { | ||
j = sort.Search(seq.Len(), func(i int) bool { | ||
return !seq.Time(i).Before(*beforeOrEqual) | ||
}) | ||
if j == seq.Len() || j < seq.Len() && !seq.Time(j).Equal(*beforeOrEqual) { | ||
j-- | ||
} | ||
} | ||
return j | ||
} |
Oops, something went wrong.