mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
7b3ee6102d
I added constants for the previous export versions, and for the final generics export version. I also added a const for the current export version. We can increment the current export version for unstable changes in dev.typeparams, and eventally set it back to the generics version (2) before release. Added the same constants in typecheck/iexport.go, importer/iimport.go, and gcimporter/iimport.go, must be kept in sync. Put in the needed conditionals to be able to read old versions. Added new export/import test listimp.dir. Change-Id: I166d17d943e07951aa752562e952b067704aeeca Reviewed-on: https://go-review.googlesource.com/c/go/+/319931 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package a
|
|
|
|
type Ordered interface {
|
|
type int, int8, int16, int32, int64,
|
|
uint, uint8, uint16, uint32, uint64, uintptr,
|
|
float32, float64,
|
|
string
|
|
}
|
|
|
|
// List is a linked list of ordered values of type T.
|
|
type List[T Ordered] struct {
|
|
Next *List[T]
|
|
Val T
|
|
}
|
|
|
|
func (l *List[T]) Largest() T {
|
|
var max T
|
|
for p := l; p != nil; p = p.Next {
|
|
if p.Val > max {
|
|
max = p.Val
|
|
}
|
|
}
|
|
return max
|
|
}
|
|
|
|
type OrderedNum interface {
|
|
type int, int8, int16, int32, int64,
|
|
uint, uint8, uint16, uint32, uint64, uintptr,
|
|
float32, float64
|
|
}
|
|
|
|
// ListNum is a linked _List of ordered numeric values of type T.
|
|
type ListNum[T OrderedNum] struct {
|
|
Next *ListNum[T]
|
|
Val T
|
|
}
|
|
|
|
const Clip = 5
|
|
|
|
// clippedLargest returns the largest in the list of OrderNums, but a max of 5.
|
|
// TODO(danscales): fix export/import of an untype constant with typeparam type
|
|
func (l *ListNum[T]) ClippedLargest() T {
|
|
var max T
|
|
for p := l; p != nil; p = p.Next {
|
|
if p.Val > max && p.Val < T(Clip) {
|
|
max = p.Val
|
|
}
|
|
}
|
|
return max
|
|
}
|