mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
70 lines
1 KiB
Go
70 lines
1 KiB
Go
|
package data
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
type Datum interface {
|
||
|
Compare(other Datum) (int, error)
|
||
|
}
|
||
|
type Datums []Datum
|
||
|
|
||
|
type DUint16 uint16
|
||
|
type DUint32 uint32
|
||
|
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
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|