-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit 4de1ccd.
- Loading branch information
Showing
5 changed files
with
195 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package data | ||
|
||
//go:generate genny -in=generic_nullable_vector.go -out=nullable_vector.gen.go gen "gen=uint8,uint16,uint32,uint64,int8,int16,int32,int64,float32,float64,string,bool,time.Time,json.RawMessage" | ||
|
||
//go:generate genny -in=generic_vector.go -out=vector.gen.go gen "gen=uint8,uint16,uint32,uint64,int8,int16,int32,int64,float32,float64,string,bool,time.Time,json.RawMessage" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package data | ||
|
||
type nullablegenVector []*gen | ||
|
||
func newNullablegenVector(n int) *nullablegenVector { | ||
v := nullablegenVector(make([]*gen, n)) | ||
return &v | ||
} | ||
|
||
func newNullablegenVectorWithValues(s []*gen) *nullablegenVector { | ||
v := make([]*gen, len(s)) | ||
copy(v, s) | ||
return (*nullablegenVector)(&v) | ||
} | ||
|
||
func (v *nullablegenVector) Set(idx int, i interface{}) { | ||
if i == nil { | ||
(*v)[idx] = nil | ||
return | ||
} | ||
(*v)[idx] = i.(*gen) | ||
} | ||
|
||
func (v *nullablegenVector) SetConcrete(idx int, i interface{}) { | ||
val := i.(gen) | ||
(*v)[idx] = &val | ||
} | ||
|
||
func (v *nullablegenVector) Append(i interface{}) { | ||
if i == nil { | ||
*v = append(*v, nil) | ||
return | ||
} | ||
*v = append(*v, i.(*gen)) | ||
} | ||
|
||
func (v *nullablegenVector) At(i int) interface{} { | ||
return (*v)[i] | ||
} | ||
|
||
func (v *nullablegenVector) CopyAt(i int) interface{} { | ||
if (*v)[i] == nil { | ||
var g *gen | ||
return g | ||
} | ||
var g gen | ||
g = *(*v)[i] | ||
return &g | ||
} | ||
|
||
func (v *nullablegenVector) ConcreteAt(i int) (interface{}, bool) { | ||
var g gen | ||
val := (*v)[i] | ||
if val == nil { | ||
return g, false | ||
} | ||
g = *val | ||
return g, true | ||
} | ||
|
||
func (v *nullablegenVector) PointerAt(i int) interface{} { | ||
return &(*v)[i] | ||
} | ||
|
||
func (v *nullablegenVector) Len() int { | ||
return len(*v) | ||
} | ||
|
||
func (v *nullablegenVector) Type() FieldType { | ||
return vectorFieldType(v) | ||
} | ||
|
||
func (v *nullablegenVector) Extend(i int) { | ||
*v = append(*v, make([]*gen, i)...) | ||
} | ||
|
||
func (v *nullablegenVector) Insert(i int, val interface{}) { | ||
switch { | ||
case i < v.Len(): | ||
v.Extend(1) | ||
copy((*v)[i+1:], (*v)[i:]) | ||
v.Set(i, val) | ||
case i == v.Len(): | ||
v.Append(val) | ||
case i > v.Len(): | ||
panic("Invalid index; vector length should be greater or equal to that index") | ||
} | ||
} | ||
|
||
func (v *nullablegenVector) Delete(i int) { | ||
*v = append((*v)[:i], (*v)[i+1:]...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package data | ||
|
||
import ( | ||
"github.com/cheekybits/genny/generic" | ||
) | ||
|
||
type gen generic.Type | ||
|
||
type genVector []gen | ||
|
||
func newgenVector(n int) *genVector { | ||
v := genVector(make([]gen, n)) | ||
return &v | ||
} | ||
|
||
func newgenVectorWithValues(s []gen) *genVector { | ||
v := make([]gen, len(s)) | ||
copy(v, s) | ||
return (*genVector)(&v) | ||
} | ||
|
||
func (v *genVector) Set(idx int, i interface{}) { | ||
(*v)[idx] = i.(gen) | ||
} | ||
|
||
func (v *genVector) SetConcrete(idx int, i interface{}) { | ||
v.Set(idx, i) | ||
} | ||
|
||
func (v *genVector) Append(i interface{}) { | ||
*v = append(*v, i.(gen)) | ||
} | ||
|
||
func (v *genVector) At(i int) interface{} { | ||
return (*v)[i] | ||
} | ||
|
||
func (v *genVector) PointerAt(i int) interface{} { | ||
return &(*v)[i] | ||
} | ||
|
||
func (v *genVector) Len() int { | ||
return len(*v) | ||
} | ||
|
||
func (v *genVector) CopyAt(i int) interface{} { | ||
var g gen | ||
g = (*v)[i] | ||
return g | ||
} | ||
|
||
func (v *genVector) ConcreteAt(i int) (interface{}, bool) { | ||
return v.At(i), true | ||
} | ||
|
||
func (v *genVector) Type() FieldType { | ||
return vectorFieldType(v) | ||
} | ||
|
||
func (v *genVector) Extend(i int) { | ||
*v = append(*v, make([]gen, i)...) | ||
} | ||
|
||
func (v *genVector) Insert(i int, val interface{}) { | ||
switch { | ||
case i < v.Len(): | ||
v.Extend(1) | ||
copy((*v)[i+1:], (*v)[i:]) | ||
v.Set(i, val) | ||
case i == v.Len(): | ||
v.Append(val) | ||
case i > v.Len(): | ||
panic("Invalid index; vector length should be greater or equal to that index") | ||
} | ||
} | ||
|
||
func (v *genVector) Delete(i int) { | ||
*v = append((*v)[:i], (*v)[i+1:]...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters