-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprimitives.go
67 lines (56 loc) · 1.41 KB
/
primitives.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ranges
// OutputRange is any type that values can be output to.
type OutputRange[T any] interface {
Put(element T) error
}
// InputRange is any type you can read sequentially.
type InputRange[T any] interface {
Empty() bool
Front() T
PopFront()
}
// ForwardRange is an InputRange you can save the position of.
type ForwardRange[T any] interface {
InputRange[T]
Save() ForwardRange[T]
}
// BidirectionalRange is a ForwardRange that can be accessed from both directions.
type BidirectionalRange[T any] interface {
ForwardRange[T]
Back() T
PopBack()
SaveB() BidirectionalRange[T]
}
// RandomAccessRange is a Bidirectional ranges with a known length.
//
// Len() ought to be a constant-time access operation, as in O(1)
type RandomAccessRange[T any] interface {
BidirectionalRange[T]
Get(index int) T
Len() int
SaveR() RandomAccessRange[T]
}
// Signed is any signed integer type.
type Signed interface {
~int | ~int8 | ~int16 | ~int32 | ~int64
}
// Unsigned is any unsigned integer type.
type Unsigned interface {
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
// Integer integer type.
type Integer interface {
Signed | Unsigned
}
// Float is any floating point type.
type Float interface {
~float32 | ~float64
}
// Any basic real number type
type RealNumber interface {
Integer | Float
}
// Ordered is any type can can be compared with < and >
type Ordered interface {
RealNumber | ~string
}