aboutsummaryrefslogtreecommitdiff
path: root/weed/data/datum.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/data/datum.go')
-rw-r--r--weed/data/datum.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/weed/data/datum.go b/weed/data/datum.go
new file mode 100644
index 000000000..5805b691d
--- /dev/null
+++ b/weed/data/datum.go
@@ -0,0 +1,69 @@
+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
+}