seaweedfs/weed/data/datum.go

92 lines
1.4 KiB
Go
Raw Normal View History

2023-02-13 08:01:14 +00:00
package data
import "fmt"
type Datum interface {
Compare(other Datum) (int, error)
}
type Datums []Datum
type DUint16 uint16
type DUint32 uint32
2023-02-17 05:34:23 +00:00
type DUint64 uint64
2023-02-13 08:01:14 +00:00
type dNull struct{}
var (
DNull Datum = dNull{}
)
func (d dNull) Compare(other Datum) (int, error) {
if other == DNull {
return 0, nil
}
return -1, nil
}
func NewDUint16(d DUint16) *DUint16 {
return &d
}
func NewDUint32(d DUint32) *DUint32 {
return &d
}
2023-02-17 05:34:23 +00:00
func NewDUint64(d DUint64) *DUint64 {
return &d
}
2023-02-13 08:01:14 +00:00
func (d *DUint16) Compare(other Datum) (int, error) {
if other == DNull {
return 1, nil
}
thisV := *d
var otherV DUint16
switch t := other.(type) {
case *DUint16:
otherV = *t
default:
return 0, fmt.Errorf("unsupported")
}
if thisV < otherV {
return -1, nil
}
if thisV > otherV {
return 1, nil
}
return 0, nil
}
func (d *DUint32) Compare(other Datum) (int, error) {
if other == DNull {
return 1, nil
}
thisV := *d
var otherV DUint32
switch t := other.(type) {
case *DUint32:
otherV = *t
}
if thisV < otherV {
return -1, nil
}
if thisV > otherV {
return 1, nil
}
return 0, nil
}
2023-02-17 05:34:23 +00:00
func (d *DUint64) Compare(other Datum) (int, error) {
if other == DNull {
return 1, nil
}
thisV := *d
var otherV DUint64
switch t := other.(type) {
case *DUint64:
otherV = *t
}
if thisV < otherV {
return -1, nil
}
if thisV > otherV {
return 1, nil
}
return 0, nil
}