12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package data
- import "fmt"
- type Datum interface {
- Compare(other Datum) (int, error)
- }
- type Datums []Datum
- type DUint16 uint16
- type DUint32 uint32
- type DUint64 uint64
- 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 NewDUint64(d DUint64) *DUint64 {
- 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
- }
- 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
- }
|