Skip to content

Commit

Permalink
add int and unsigned int 8,16,32, and 64 types, and float 32 and 64
Browse files Browse the repository at this point in the history
  • Loading branch information
corymickelson committed Sep 26, 2019
1 parent d43ab0a commit 107c889
Show file tree
Hide file tree
Showing 8 changed files with 471 additions and 59 deletions.
15 changes: 10 additions & 5 deletions data/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (

type (
node struct {
t pkg.FieldType
nullable pkg.Nullable
mutex sync.RWMutex
id uint64
min uint64
max uint64
version uint
t pkg.FieldType // 32
v interface{} // 16
name string
v interface{}
version uint // 32
mutex sync.RWMutex
nullable pkg.Nullable
parent pkg.Composer
next pkg.Composer
prev pkg.Composer
Expand Down Expand Up @@ -81,6 +81,7 @@ func Index(b bool) Opt {
}

// Set the nullable property of a node
// nullable is copied NOT referenced by the node
func Nullable(nullable *pkg.Nullable) Opt {
return func(n *node) (*node, error) {
n.nullable = *nullable
Expand All @@ -89,6 +90,7 @@ func Nullable(nullable *pkg.Nullable) Opt {
}

// Add the type [t] of value held by this node.
// t is copied NOT referenced by the node
func Type(t *pkg.FieldType) Opt {
return func(n *node) (*node, error) {
n.t = *t
Expand Down Expand Up @@ -127,6 +129,8 @@ func (i *node) Value() interface{} {
}

// Get a nodes children
// returns a reference to the children map
// The child should NOT be mutated, a reference is used to mitigate a potentially large copy operation
func (i *node) Children() *map[uint64]pkg.Composer {
return &i.children
}
Expand Down Expand Up @@ -374,6 +378,7 @@ func (i *node) Excludes() []bool {
func (i *node) Nullable() pkg.Nullable {
return i.nullable
}

// func (i *node) LockWhile(fn func()) {
// n := root(i)
// n.mutex.RLock()
Expand Down
32 changes: 32 additions & 0 deletions io/output/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func (i *Memory) fillShape(out chan interface{}, quit chan error, n pkg.Composer
if field.Type.Kind() == reflect.Float64 {
cpy.FieldByIndex(field.Index).SetFloat(n.Value().(float64))
}
case float32:
if field.Type.Kind() == reflect.Float32 {
cpy.FieldByIndex(field.Index).Set(reflect.ValueOf(n.Value().(float32)))
}
case bool:
if field.Type.Kind() == reflect.Bool {
cpy.FieldByIndex(field.Index).SetBool(n.Value().(bool))
Expand All @@ -205,6 +209,34 @@ func (i *Memory) fillShape(out chan interface{}, quit chan error, n pkg.Composer
if field.Type.Kind() == reflect.Int64 {
cpy.FieldByIndex(field.Index).SetInt(n.Value().(int64))
}
case int32:
if field.Type.Kind() == reflect.Int32 {
cpy.FieldByIndex(field.Index).Set(reflect.ValueOf(n.Value().(int32)))
}
case int16:
if field.Type.Kind() == reflect.Int16 {
cpy.FieldByIndex(field.Index).Set(reflect.ValueOf(n.Value().(int16)))
}
case int8:
if field.Type.Kind() == reflect.Int8 {
cpy.FieldByIndex(field.Index).Set(reflect.ValueOf(n.Value().(int8)))
}
case uint64:
if field.Type.Kind() == reflect.Uint64 {
cpy.FieldByIndex(field.Index).SetUint(n.Value().(uint64))
}
case uint32:
if field.Type.Kind() == reflect.Uint32 {
cpy.FieldByIndex(field.Index).Set(reflect.ValueOf(n.Value().(uint32)))
}
case uint16:
if field.Type.Kind() == reflect.Uint16 {
cpy.FieldByIndex(field.Index).Set(reflect.ValueOf(n.Value().(uint16)))
}
case uint8:
if field.Type.Kind() == reflect.Uint8 {
cpy.FieldByIndex(field.Index).Set(reflect.ValueOf(n.Value().(uint8)))
}
default:
quit <- errors.New("output/Memory: unknown type, supported types are: string, float64, int64, bool, time.Time")
}
Expand Down
76 changes: 73 additions & 3 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,22 @@ func (p *parser) parseRow(row []string) error {
d.Msg = "parser/parse: time was expected"
n = nilNode
}
case pkg.FLOAT32:
switch item.(type) {
case float32:
n, err = data.NewNode(&id, data.V(item.(float32)))
default:
d.Msg = "parser/parse: float32 was expected"
n = nilNode
}
case pkg.FLOAT:
fallthrough
case pkg.FLOAT64:
switch item.(type) {
case float64:
n, err = data.NewNode(&id, data.V(item.(float64)))
default:
d.Msg = "parser/parse: float was expected"
d.Msg = "parser/parse: float64 was expected"
n = nilNode
}
case pkg.CUSTOM:
Expand All @@ -175,12 +185,72 @@ func (p *parser) parseRow(row []string) error {
d.Msg = "parser/parse: bool was expected"
n = nilNode
}
case pkg.UINT:
fallthrough
case pkg.UINT64:
switch item.(type) {
case uint64:
n, err = data.NewNode(&id, data.V(item.(uint64)))
default:
d.Msg = "parser/parse: uint64 was expected"
n = nilNode
}
case pkg.INT:
fallthrough
case pkg.INT64:
switch item.(type) {
case int64:
n, err = data.NewNode(&id, data.V(item.(int64)))
default:
d.Msg = "parser/parse: bool was expected"
d.Msg = "parser/parse: int64 was expected"
n = nilNode
}
case pkg.UINT32:
switch item.(type) {
case uint32:
n, err = data.NewNode(&id, data.V(item.(uint32)))
default:
d.Msg = "parser/parse: uint32 was expected"
n = nilNode
}
case pkg.INT32:
switch item.(type) {
case int32:
n, err = data.NewNode(&id, data.V(item.(int32)))
default:
d.Msg = "parser/parse: int32 was expected"
n = nilNode
}
case pkg.UINT16:
switch item.(type) {
case uint16:
n, err = data.NewNode(&id, data.V(item.(uint16)))
default:
d.Msg = "parser/parse: uint32 was expected"
n = nilNode
}
case pkg.INT16:
switch item.(type) {
case int16:
n, err = data.NewNode(&id, data.V(item.(int16)))
default:
d.Msg = "parser/parse: int16 was expected"
n = nilNode
}
case pkg.UINT8:
switch item.(type) {
case uint8:
n, err = data.NewNode(&id, data.V(item.(uint8)))
default:
d.Msg = "parser/parse: uint8 was expected"
n = nilNode
}
case pkg.INT8:
switch item.(type) {
case int8:
n, err = data.NewNode(&id, data.V(item.(int8)))
default:
d.Msg = "parser/parse: int8 was expected"
n = nilNode
}
default:
Expand All @@ -203,7 +273,7 @@ func (p *parser) parseRow(row []string) error {
}
return p.linkRow(colRow)
}
func (p *parser) linkRow(row []pkg.Composer) error {
func (p *parser) linkRow(row []pkg.Composer) error {
var (
i = 0
err error = nil
Expand Down
37 changes: 35 additions & 2 deletions pkg/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ type (
)

const (
INT FieldType = iota
// INT FieldType = iota
INT8 FieldType = iota
INT16
INT
INT32
INT64
UINT8
UINT16
UINT
UINT32
UINT64
FLOAT32
FLOAT
FLOAT64
STRING
TIMESTAMP
DATE
Expand All @@ -23,5 +35,26 @@ const (
)

func (dt FieldType) String() string {
return [...]string{"INT", "FLOAT", "STRING", "TIMESTAMP", "DATE", "CUSTOM", "BOOL", "NULL", "UNKNOWN"}[dt]
return [...]string{
"INT8",
"INT16",
"INT",
"INT32",
"INT64",
"UINT8",
"UINT16",
"UINT",
"UINT32",
"UINT64",
"FLOAT32",
"FLOAT",
"FLOAT64",
"STRING",
"TIMESTAMP",
"DATE",
"CUSTOM",
"BOOL",
"NULL",
"UNKNOWN",
}[dt]
}
6 changes: 3 additions & 3 deletions pkg/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package pkg

type (
Nullable struct {
Variants []string
ReplaceWith *string
Allowed bool
Variants []string // 24
ReplaceWith *string // 8
Allowed bool // 1
}
// Composer is the primary building block of the exttra tree
Composer interface {
Expand Down
Loading

0 comments on commit 107c889

Please sign in to comment.