Merge pull request #695 from rafael-atticlabs/complexTypesHaveCS

Complex Types embed a ChunkStore
This commit is contained in:
Rafael Weinstein
2015-12-01 10:59:16 -08:00
108 changed files with 1949 additions and 1532 deletions

View File

@@ -3,6 +3,7 @@
package common
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -38,14 +39,16 @@ type Geoposition struct {
_Latitude float32
_Longitude float32
cs chunks.ChunkStore
ref *ref.Ref
}
func NewGeoposition() Geoposition {
func NewGeoposition(cs chunks.ChunkStore) Geoposition {
return Geoposition{
_Latitude: float32(0),
_Longitude: float32(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -55,10 +58,11 @@ type GeopositionDef struct {
Longitude float32
}
func (def GeopositionDef) New() Geoposition {
func (def GeopositionDef) New(cs chunks.ChunkStore) Geoposition {
return Geoposition{
_Latitude: def.Latitude,
_Longitude: def.Longitude,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -80,9 +84,9 @@ func init() {
types.RegisterStruct(__typeForGeoposition, builderForGeoposition, readerForGeoposition)
}
func builderForGeoposition(values []types.Value) types.Value {
func builderForGeoposition(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Geoposition{ref: &ref.Ref{}}
s := Geoposition{ref: &ref.Ref{}, cs: cs}
s._Latitude = float32(values[i].(types.Float32))
i++
s._Longitude = float32(values[i].(types.Float32))
@@ -143,14 +147,16 @@ type Georectangle struct {
_TopLeft Geoposition
_BottomRight Geoposition
cs chunks.ChunkStore
ref *ref.Ref
}
func NewGeorectangle() Georectangle {
func NewGeorectangle(cs chunks.ChunkStore) Georectangle {
return Georectangle{
_TopLeft: NewGeoposition(),
_BottomRight: NewGeoposition(),
_TopLeft: NewGeoposition(cs),
_BottomRight: NewGeoposition(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -160,10 +166,11 @@ type GeorectangleDef struct {
BottomRight GeopositionDef
}
func (def GeorectangleDef) New() Georectangle {
func (def GeorectangleDef) New(cs chunks.ChunkStore) Georectangle {
return Georectangle{
_TopLeft: def.TopLeft.New(),
_BottomRight: def.BottomRight.New(),
_TopLeft: def.TopLeft.New(cs),
_BottomRight: def.BottomRight.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -185,9 +192,9 @@ func init() {
types.RegisterStruct(__typeForGeorectangle, builderForGeorectangle, readerForGeorectangle)
}
func builderForGeorectangle(values []types.Value) types.Value {
func builderForGeorectangle(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Georectangle{ref: &ref.Ref{}}
s := Georectangle{ref: &ref.Ref{}, cs: cs}
s._TopLeft = values[i].(Geoposition)
i++
s._BottomRight = values[i].(Geoposition)

View File

@@ -52,10 +52,11 @@ type Incident struct {
_Geoposition Geoposition
_PdID string
cs chunks.ChunkStore
ref *ref.Ref
}
func NewIncident() Incident {
func NewIncident(cs chunks.ChunkStore) Incident {
return Incident{
_ID: int64(0),
_Category: "",
@@ -66,9 +67,10 @@ func NewIncident() Incident {
_PdDistrict: "",
_Resolution: "",
_Address: "",
_Geoposition: NewGeoposition(),
_Geoposition: NewGeoposition(cs),
_PdID: "",
cs: cs,
ref: &ref.Ref{},
}
}
@@ -87,7 +89,7 @@ type IncidentDef struct {
PdID string
}
func (def IncidentDef) New() Incident {
func (def IncidentDef) New(cs chunks.ChunkStore) Incident {
return Incident{
_ID: def.ID,
_Category: def.Category,
@@ -98,8 +100,9 @@ func (def IncidentDef) New() Incident {
_PdDistrict: def.PdDistrict,
_Resolution: def.Resolution,
_Address: def.Address,
_Geoposition: def.Geoposition.New(),
_Geoposition: def.Geoposition.New(cs),
_PdID: def.PdID,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -130,9 +133,9 @@ func init() {
types.RegisterStruct(__typeForIncident, builderForIncident, readerForIncident)
}
func builderForIncident(values []types.Value) types.Value {
func builderForIncident(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Incident{ref: &ref.Ref{}}
s := Incident{ref: &ref.Ref{}, cs: cs}
s._ID = int64(values[i].(types.Int64))
i++
s._Category = values[i].(types.String).String()
@@ -318,21 +321,22 @@ func (s Incident) SetPdID(val string) Incident {
type ListOfRefOfIncident struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfRefOfIncident() ListOfRefOfIncident {
return ListOfRefOfIncident{types.NewTypedList(__typeForListOfRefOfIncident), &ref.Ref{}}
func NewListOfRefOfIncident(cs chunks.ChunkStore) ListOfRefOfIncident {
return ListOfRefOfIncident{types.NewTypedList(cs, __typeForListOfRefOfIncident), cs, &ref.Ref{}}
}
type ListOfRefOfIncidentDef []ref.Ref
func (def ListOfRefOfIncidentDef) New() ListOfRefOfIncident {
func (def ListOfRefOfIncidentDef) New(cs chunks.ChunkStore) ListOfRefOfIncident {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = NewRefOfIncident(d)
}
return ListOfRefOfIncident{types.NewTypedList(__typeForListOfRefOfIncident, l...), &ref.Ref{}}
return ListOfRefOfIncident{types.NewTypedList(cs, __typeForListOfRefOfIncident, l...), cs, &ref.Ref{}}
}
func (l ListOfRefOfIncident) Def() ListOfRefOfIncidentDef {
@@ -373,8 +377,8 @@ func init() {
types.RegisterValue(__typeForListOfRefOfIncident, builderForListOfRefOfIncident, readerForListOfRefOfIncident)
}
func builderForListOfRefOfIncident(v types.Value) types.Value {
return ListOfRefOfIncident{v.(types.List), &ref.Ref{}}
func builderForListOfRefOfIncident(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfRefOfIncident{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfRefOfIncident(v types.Value) types.Value {
@@ -394,27 +398,27 @@ func (l ListOfRefOfIncident) Get(i uint64) RefOfIncident {
}
func (l ListOfRefOfIncident) Slice(idx uint64, end uint64) ListOfRefOfIncident {
return ListOfRefOfIncident{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfRefOfIncident{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfIncident) Set(i uint64, val RefOfIncident) ListOfRefOfIncident {
return ListOfRefOfIncident{l.l.Set(i, val), &ref.Ref{}}
return ListOfRefOfIncident{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfIncident) Append(v ...RefOfIncident) ListOfRefOfIncident {
return ListOfRefOfIncident{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfRefOfIncident{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfIncident) Insert(idx uint64, v ...RefOfIncident) ListOfRefOfIncident {
return ListOfRefOfIncident{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfRefOfIncident{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfIncident) Remove(idx uint64, end uint64) ListOfRefOfIncident {
return ListOfRefOfIncident{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfRefOfIncident{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfIncident) RemoveAt(idx uint64) ListOfRefOfIncident {
return ListOfRefOfIncident{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfRefOfIncident{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfIncident) fromElemSlice(p []RefOfIncident) []types.Value {
@@ -453,7 +457,7 @@ func (l ListOfRefOfIncident) Filter(cb ListOfRefOfIncidentFilterCallback) ListOf
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(RefOfIncident), i)
})
return ListOfRefOfIncident{out, &ref.Ref{}}
return ListOfRefOfIncident{out, l.cs, &ref.Ref{}}
}
// RefOfIncident
@@ -505,7 +509,7 @@ func builderForRefOfIncident(r ref.Ref) types.Value {
return NewRefOfIncident(r)
}
func (r RefOfIncident) TargetValue(cs chunks.ChunkSource) Incident {
func (r RefOfIncident) TargetValue(cs chunks.ChunkStore) Incident {
return types.ReadValue(r.target, cs).(Incident)
}

View File

@@ -3,6 +3,7 @@
package common
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -48,18 +49,20 @@ type RemotePhoto struct {
_Sizes MapOfSizeToString
_Tags SetOfString
cs chunks.ChunkStore
ref *ref.Ref
}
func NewRemotePhoto() RemotePhoto {
func NewRemotePhoto(cs chunks.ChunkStore) RemotePhoto {
return RemotePhoto{
_Id: "",
_Title: "",
_Url: "",
_Geoposition: NewGeoposition(),
_Sizes: NewMapOfSizeToString(),
_Tags: NewSetOfString(),
_Geoposition: NewGeoposition(cs),
_Sizes: NewMapOfSizeToString(cs),
_Tags: NewSetOfString(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -73,14 +76,15 @@ type RemotePhotoDef struct {
Tags SetOfStringDef
}
func (def RemotePhotoDef) New() RemotePhoto {
func (def RemotePhotoDef) New(cs chunks.ChunkStore) RemotePhoto {
return RemotePhoto{
_Id: def.Id,
_Title: def.Title,
_Url: def.Url,
_Geoposition: def.Geoposition.New(),
_Sizes: def.Sizes.New(),
_Tags: def.Tags.New(),
_Geoposition: def.Geoposition.New(cs),
_Sizes: def.Sizes.New(cs),
_Tags: def.Tags.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -106,9 +110,9 @@ func init() {
types.RegisterStruct(__typeForRemotePhoto, builderForRemotePhoto, readerForRemotePhoto)
}
func builderForRemotePhoto(values []types.Value) types.Value {
func builderForRemotePhoto(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := RemotePhoto{ref: &ref.Ref{}}
s := RemotePhoto{ref: &ref.Ref{}, cs: cs}
s._Id = values[i].(types.String).String()
i++
s._Title = values[i].(types.String).String()
@@ -228,14 +232,16 @@ type Size struct {
_Width uint32
_Height uint32
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSize() Size {
func NewSize(cs chunks.ChunkStore) Size {
return Size{
_Width: uint32(0),
_Height: uint32(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -245,10 +251,11 @@ type SizeDef struct {
Height uint32
}
func (def SizeDef) New() Size {
func (def SizeDef) New(cs chunks.ChunkStore) Size {
return Size{
_Width: def.Width,
_Height: def.Height,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -270,9 +277,9 @@ func init() {
types.RegisterStruct(__typeForSize, builderForSize, readerForSize)
}
func builderForSize(values []types.Value) types.Value {
func builderForSize(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Size{ref: &ref.Ref{}}
s := Size{ref: &ref.Ref{}, cs: cs}
s._Width = uint32(values[i].(types.UInt32))
i++
s._Height = uint32(values[i].(types.UInt32))
@@ -331,21 +338,22 @@ func (s Size) SetHeight(val uint32) Size {
type MapOfSizeToString struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfSizeToString() MapOfSizeToString {
return MapOfSizeToString{types.NewTypedMap(__typeForMapOfSizeToString), &ref.Ref{}}
func NewMapOfSizeToString(cs chunks.ChunkStore) MapOfSizeToString {
return MapOfSizeToString{types.NewTypedMap(cs, __typeForMapOfSizeToString), cs, &ref.Ref{}}
}
type MapOfSizeToStringDef map[SizeDef]string
func (def MapOfSizeToStringDef) New() MapOfSizeToString {
func (def MapOfSizeToStringDef) New(cs chunks.ChunkStore) MapOfSizeToString {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, k.New(), types.NewString(v))
kv = append(kv, k.New(cs), types.NewString(v))
}
return MapOfSizeToString{types.NewTypedMap(__typeForMapOfSizeToString, kv...), &ref.Ref{}}
return MapOfSizeToString{types.NewTypedMap(cs, __typeForMapOfSizeToString, kv...), cs, &ref.Ref{}}
}
func (m MapOfSizeToString) Def() MapOfSizeToStringDef {
@@ -387,8 +395,8 @@ func init() {
types.RegisterValue(__typeForMapOfSizeToString, builderForMapOfSizeToString, readerForMapOfSizeToString)
}
func builderForMapOfSizeToString(v types.Value) types.Value {
return MapOfSizeToString{v.(types.Map), &ref.Ref{}}
func builderForMapOfSizeToString(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfSizeToString{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfSizeToString(v types.Value) types.Value {
@@ -420,13 +428,13 @@ func (m MapOfSizeToString) MaybeGet(p Size) (string, bool) {
}
func (m MapOfSizeToString) Set(k Size, v string) MapOfSizeToString {
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), &ref.Ref{}}
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
return MapOfSizeToString{m.m.Remove(p), &ref.Ref{}}
return MapOfSizeToString{m.m.Remove(p), m.cs, &ref.Ref{}}
}
type MapOfSizeToStringIterCallback func(k Size, v string) (stop bool)
@@ -457,30 +465,31 @@ func (m MapOfSizeToString) Filter(cb MapOfSizeToStringFilterCallback) MapOfSizeT
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(Size), v.(types.String).String())
})
return MapOfSizeToString{out, &ref.Ref{}}
return MapOfSizeToString{out, m.cs, &ref.Ref{}}
}
// SetOfString
type SetOfString struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfString() SetOfString {
return SetOfString{types.NewTypedSet(__typeForSetOfString), &ref.Ref{}}
func NewSetOfString(cs chunks.ChunkStore) SetOfString {
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString), cs, &ref.Ref{}}
}
type SetOfStringDef map[string]bool
func (def SetOfStringDef) New() SetOfString {
func (def SetOfStringDef) New(cs chunks.ChunkStore) SetOfString {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = types.NewString(d)
i++
}
return SetOfString{types.NewTypedSet(__typeForSetOfString, l...), &ref.Ref{}}
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString, l...), cs, &ref.Ref{}}
}
func (s SetOfString) Def() SetOfStringDef {
@@ -522,8 +531,8 @@ func init() {
types.RegisterValue(__typeForSetOfString, builderForSetOfString, readerForSetOfString)
}
func builderForSetOfString(v types.Value) types.Value {
return SetOfString{v.(types.Set), &ref.Ref{}}
func builderForSetOfString(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfString{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfString(v types.Value) types.Value {
@@ -570,23 +579,23 @@ func (s SetOfString) Filter(cb SetOfStringFilterCallback) SetOfString {
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(types.String).String())
})
return SetOfString{out, &ref.Ref{}}
return SetOfString{out, s.cs, &ref.Ref{}}
}
func (s SetOfString) Insert(p ...string) SetOfString {
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Remove(p ...string) SetOfString {
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Union(others ...SetOfString) SetOfString {
return SetOfString{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Subtract(others ...SetOfString) SetOfString {
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Any() string {

View File

@@ -197,7 +197,7 @@ func (qt *QuadTreeDef) makeChildren() {
qt.Tiles[br] = CreateNewQuadTreeDef(qt.Depth+1, qt.Path+"d", brRect)
}
func (qt *QuadTreeDef) SaveToNoms(cs chunks.ChunkSink, start time.Time, quiet bool) *SQuadTree {
func (qt *QuadTreeDef) SaveToNoms(cs chunks.ChunkStore, start time.Time, quiet bool) *SQuadTree {
wChan := make(chan *SQuadTree, 1024)
var wg sync.WaitGroup
for i := 0; i < 32; i++ {
@@ -220,7 +220,7 @@ func (qt *QuadTreeDef) SaveToNoms(cs chunks.ChunkSink, start time.Time, quiet bo
return sqt
}
func (qt *QuadTreeDef) saveNodeToNoms(wChan chan *SQuadTree, cs chunks.ChunkSink, start time.Time, quiet bool) *SQuadTree {
func (qt *QuadTreeDef) saveNodeToNoms(wChan chan *SQuadTree, cs chunks.ChunkStore, start time.Time, quiet bool) *SQuadTree {
tileRefs := MapOfStringToRefOfSQuadTreeDef{}
nrefs := make(ListOfRefOfValueDef, 0, len(qt.Nodes))
if qt.hasTiles() {
@@ -241,7 +241,7 @@ func (qt *QuadTreeDef) saveNodeToNoms(wChan chan *SQuadTree, cs chunks.ChunkSink
NumDescendents: qt.NumDescendents,
Path: qt.Path,
Georectangle: qt.Georectangle,
}.New()
}.New(cs)
sqtp := &sqt
wChan <- sqtp

View File

@@ -56,14 +56,16 @@ type Node struct {
_Geoposition Geoposition
_Reference RefOfValue
cs chunks.ChunkStore
ref *ref.Ref
}
func NewNode() Node {
func NewNode(cs chunks.ChunkStore) Node {
return Node{
_Geoposition: NewGeoposition(),
_Geoposition: NewGeoposition(cs),
_Reference: NewRefOfValue(ref.Ref{}),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -73,10 +75,11 @@ type NodeDef struct {
Reference ref.Ref
}
func (def NodeDef) New() Node {
func (def NodeDef) New(cs chunks.ChunkStore) Node {
return Node{
_Geoposition: def.Geoposition.New(),
_Geoposition: def.Geoposition.New(cs),
_Reference: NewRefOfValue(def.Reference),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -98,9 +101,9 @@ func init() {
types.RegisterStruct(__typeForNode, builderForNode, readerForNode)
}
func builderForNode(values []types.Value) types.Value {
func builderForNode(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Node{ref: &ref.Ref{}}
s := Node{ref: &ref.Ref{}, cs: cs}
s._Geoposition = values[i].(Geoposition)
i++
s._Reference = values[i].(RefOfValue)
@@ -167,18 +170,20 @@ type QuadTree struct {
_Path string
_Georectangle Georectangle
cs chunks.ChunkStore
ref *ref.Ref
}
func NewQuadTree() QuadTree {
func NewQuadTree(cs chunks.ChunkStore) QuadTree {
return QuadTree{
_Nodes: NewListOfNode(),
_Tiles: NewMapOfStringToQuadTree(),
_Nodes: NewListOfNode(cs),
_Tiles: NewMapOfStringToQuadTree(cs),
_Depth: uint8(0),
_NumDescendents: uint32(0),
_Path: "",
_Georectangle: NewGeorectangle(),
_Georectangle: NewGeorectangle(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -192,14 +197,15 @@ type QuadTreeDef struct {
Georectangle GeorectangleDef
}
func (def QuadTreeDef) New() QuadTree {
func (def QuadTreeDef) New(cs chunks.ChunkStore) QuadTree {
return QuadTree{
_Nodes: def.Nodes.New(),
_Tiles: def.Tiles.New(),
_Nodes: def.Nodes.New(cs),
_Tiles: def.Tiles.New(cs),
_Depth: def.Depth,
_NumDescendents: def.NumDescendents,
_Path: def.Path,
_Georectangle: def.Georectangle.New(),
_Georectangle: def.Georectangle.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -225,9 +231,9 @@ func init() {
types.RegisterStruct(__typeForQuadTree, builderForQuadTree, readerForQuadTree)
}
func builderForQuadTree(values []types.Value) types.Value {
func builderForQuadTree(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := QuadTree{ref: &ref.Ref{}}
s := QuadTree{ref: &ref.Ref{}, cs: cs}
s._Nodes = values[i].(ListOfNode)
i++
s._Tiles = values[i].(MapOfStringToQuadTree)
@@ -351,18 +357,20 @@ type SQuadTree struct {
_Path string
_Georectangle Georectangle
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSQuadTree() SQuadTree {
func NewSQuadTree(cs chunks.ChunkStore) SQuadTree {
return SQuadTree{
_Nodes: NewListOfRefOfValue(),
_Tiles: NewMapOfStringToRefOfSQuadTree(),
_Nodes: NewListOfRefOfValue(cs),
_Tiles: NewMapOfStringToRefOfSQuadTree(cs),
_Depth: uint8(0),
_NumDescendents: uint32(0),
_Path: "",
_Georectangle: NewGeorectangle(),
_Georectangle: NewGeorectangle(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -376,14 +384,15 @@ type SQuadTreeDef struct {
Georectangle GeorectangleDef
}
func (def SQuadTreeDef) New() SQuadTree {
func (def SQuadTreeDef) New(cs chunks.ChunkStore) SQuadTree {
return SQuadTree{
_Nodes: def.Nodes.New(),
_Tiles: def.Tiles.New(),
_Nodes: def.Nodes.New(cs),
_Tiles: def.Tiles.New(cs),
_Depth: def.Depth,
_NumDescendents: def.NumDescendents,
_Path: def.Path,
_Georectangle: def.Georectangle.New(),
_Georectangle: def.Georectangle.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -409,9 +418,9 @@ func init() {
types.RegisterStruct(__typeForSQuadTree, builderForSQuadTree, readerForSQuadTree)
}
func builderForSQuadTree(values []types.Value) types.Value {
func builderForSQuadTree(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := SQuadTree{ref: &ref.Ref{}}
s := SQuadTree{ref: &ref.Ref{}, cs: cs}
s._Nodes = values[i].(ListOfRefOfValue)
i++
s._Tiles = values[i].(MapOfStringToRefOfSQuadTree)
@@ -574,7 +583,7 @@ func builderForRefOfValue(r ref.Ref) types.Value {
return NewRefOfValue(r)
}
func (r RefOfValue) TargetValue(cs chunks.ChunkSource) types.Value {
func (r RefOfValue) TargetValue(cs chunks.ChunkStore) types.Value {
return types.ReadValue(r.target, cs)
}
@@ -586,21 +595,22 @@ func (r RefOfValue) SetTargetValue(val types.Value, cs chunks.ChunkSink) RefOfVa
type ListOfNode struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfNode() ListOfNode {
return ListOfNode{types.NewTypedList(__typeForListOfNode), &ref.Ref{}}
func NewListOfNode(cs chunks.ChunkStore) ListOfNode {
return ListOfNode{types.NewTypedList(cs, __typeForListOfNode), cs, &ref.Ref{}}
}
type ListOfNodeDef []NodeDef
func (def ListOfNodeDef) New() ListOfNode {
func (def ListOfNodeDef) New(cs chunks.ChunkStore) ListOfNode {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = d.New()
l[i] = d.New(cs)
}
return ListOfNode{types.NewTypedList(__typeForListOfNode, l...), &ref.Ref{}}
return ListOfNode{types.NewTypedList(cs, __typeForListOfNode, l...), cs, &ref.Ref{}}
}
func (l ListOfNode) Def() ListOfNodeDef {
@@ -641,8 +651,8 @@ func init() {
types.RegisterValue(__typeForListOfNode, builderForListOfNode, readerForListOfNode)
}
func builderForListOfNode(v types.Value) types.Value {
return ListOfNode{v.(types.List), &ref.Ref{}}
func builderForListOfNode(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfNode{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfNode(v types.Value) types.Value {
@@ -662,27 +672,27 @@ func (l ListOfNode) Get(i uint64) Node {
}
func (l ListOfNode) Slice(idx uint64, end uint64) ListOfNode {
return ListOfNode{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfNode{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfNode) Set(i uint64, val Node) ListOfNode {
return ListOfNode{l.l.Set(i, val), &ref.Ref{}}
return ListOfNode{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfNode) Append(v ...Node) ListOfNode {
return ListOfNode{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfNode{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfNode) Insert(idx uint64, v ...Node) ListOfNode {
return ListOfNode{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfNode{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfNode) Remove(idx uint64, end uint64) ListOfNode {
return ListOfNode{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfNode{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfNode) RemoveAt(idx uint64) ListOfNode {
return ListOfNode{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfNode{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfNode) fromElemSlice(p []Node) []types.Value {
@@ -721,28 +731,29 @@ func (l ListOfNode) Filter(cb ListOfNodeFilterCallback) ListOfNode {
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(Node), i)
})
return ListOfNode{out, &ref.Ref{}}
return ListOfNode{out, l.cs, &ref.Ref{}}
}
// MapOfStringToQuadTree
type MapOfStringToQuadTree struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToQuadTree() MapOfStringToQuadTree {
return MapOfStringToQuadTree{types.NewTypedMap(__typeForMapOfStringToQuadTree), &ref.Ref{}}
func NewMapOfStringToQuadTree(cs chunks.ChunkStore) MapOfStringToQuadTree {
return MapOfStringToQuadTree{types.NewTypedMap(cs, __typeForMapOfStringToQuadTree), cs, &ref.Ref{}}
}
type MapOfStringToQuadTreeDef map[string]QuadTreeDef
func (def MapOfStringToQuadTreeDef) New() MapOfStringToQuadTree {
func (def MapOfStringToQuadTreeDef) New(cs chunks.ChunkStore) MapOfStringToQuadTree {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), v.New())
kv = append(kv, types.NewString(k), v.New(cs))
}
return MapOfStringToQuadTree{types.NewTypedMap(__typeForMapOfStringToQuadTree, kv...), &ref.Ref{}}
return MapOfStringToQuadTree{types.NewTypedMap(cs, __typeForMapOfStringToQuadTree, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToQuadTree) Def() MapOfStringToQuadTreeDef {
@@ -784,8 +795,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToQuadTree, builderForMapOfStringToQuadTree, readerForMapOfStringToQuadTree)
}
func builderForMapOfStringToQuadTree(v types.Value) types.Value {
return MapOfStringToQuadTree{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToQuadTree(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToQuadTree{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToQuadTree(v types.Value) types.Value {
@@ -811,19 +822,19 @@ func (m MapOfStringToQuadTree) Get(p string) QuadTree {
func (m MapOfStringToQuadTree) MaybeGet(p string) (QuadTree, bool) {
v, ok := m.m.MaybeGet(types.NewString(p))
if !ok {
return NewQuadTree(), false
return NewQuadTree(m.cs), false
}
return v.(QuadTree), ok
}
func (m MapOfStringToQuadTree) Set(k string, v QuadTree) MapOfStringToQuadTree {
return MapOfStringToQuadTree{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToQuadTree{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToQuadTree) Remove(p string) MapOfStringToQuadTree {
return MapOfStringToQuadTree{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToQuadTree{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToQuadTreeIterCallback func(k string, v QuadTree) (stop bool)
@@ -854,28 +865,29 @@ func (m MapOfStringToQuadTree) Filter(cb MapOfStringToQuadTreeFilterCallback) Ma
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(QuadTree))
})
return MapOfStringToQuadTree{out, &ref.Ref{}}
return MapOfStringToQuadTree{out, m.cs, &ref.Ref{}}
}
// ListOfRefOfValue
type ListOfRefOfValue struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfRefOfValue() ListOfRefOfValue {
return ListOfRefOfValue{types.NewTypedList(__typeForListOfRefOfValue), &ref.Ref{}}
func NewListOfRefOfValue(cs chunks.ChunkStore) ListOfRefOfValue {
return ListOfRefOfValue{types.NewTypedList(cs, __typeForListOfRefOfValue), cs, &ref.Ref{}}
}
type ListOfRefOfValueDef []ref.Ref
func (def ListOfRefOfValueDef) New() ListOfRefOfValue {
func (def ListOfRefOfValueDef) New(cs chunks.ChunkStore) ListOfRefOfValue {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = NewRefOfValue(d)
}
return ListOfRefOfValue{types.NewTypedList(__typeForListOfRefOfValue, l...), &ref.Ref{}}
return ListOfRefOfValue{types.NewTypedList(cs, __typeForListOfRefOfValue, l...), cs, &ref.Ref{}}
}
func (l ListOfRefOfValue) Def() ListOfRefOfValueDef {
@@ -916,8 +928,8 @@ func init() {
types.RegisterValue(__typeForListOfRefOfValue, builderForListOfRefOfValue, readerForListOfRefOfValue)
}
func builderForListOfRefOfValue(v types.Value) types.Value {
return ListOfRefOfValue{v.(types.List), &ref.Ref{}}
func builderForListOfRefOfValue(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfRefOfValue{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfRefOfValue(v types.Value) types.Value {
@@ -937,27 +949,27 @@ func (l ListOfRefOfValue) Get(i uint64) RefOfValue {
}
func (l ListOfRefOfValue) Slice(idx uint64, end uint64) ListOfRefOfValue {
return ListOfRefOfValue{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfRefOfValue{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfValue) Set(i uint64, val RefOfValue) ListOfRefOfValue {
return ListOfRefOfValue{l.l.Set(i, val), &ref.Ref{}}
return ListOfRefOfValue{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfValue) Append(v ...RefOfValue) ListOfRefOfValue {
return ListOfRefOfValue{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfRefOfValue{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfValue) Insert(idx uint64, v ...RefOfValue) ListOfRefOfValue {
return ListOfRefOfValue{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfRefOfValue{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfValue) Remove(idx uint64, end uint64) ListOfRefOfValue {
return ListOfRefOfValue{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfRefOfValue{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfValue) RemoveAt(idx uint64) ListOfRefOfValue {
return ListOfRefOfValue{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfRefOfValue{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfValue) fromElemSlice(p []RefOfValue) []types.Value {
@@ -996,28 +1008,29 @@ func (l ListOfRefOfValue) Filter(cb ListOfRefOfValueFilterCallback) ListOfRefOfV
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(RefOfValue), i)
})
return ListOfRefOfValue{out, &ref.Ref{}}
return ListOfRefOfValue{out, l.cs, &ref.Ref{}}
}
// MapOfStringToRefOfSQuadTree
type MapOfStringToRefOfSQuadTree struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToRefOfSQuadTree() MapOfStringToRefOfSQuadTree {
return MapOfStringToRefOfSQuadTree{types.NewTypedMap(__typeForMapOfStringToRefOfSQuadTree), &ref.Ref{}}
func NewMapOfStringToRefOfSQuadTree(cs chunks.ChunkStore) MapOfStringToRefOfSQuadTree {
return MapOfStringToRefOfSQuadTree{types.NewTypedMap(cs, __typeForMapOfStringToRefOfSQuadTree), cs, &ref.Ref{}}
}
type MapOfStringToRefOfSQuadTreeDef map[string]ref.Ref
func (def MapOfStringToRefOfSQuadTreeDef) New() MapOfStringToRefOfSQuadTree {
func (def MapOfStringToRefOfSQuadTreeDef) New(cs chunks.ChunkStore) MapOfStringToRefOfSQuadTree {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), NewRefOfSQuadTree(v))
}
return MapOfStringToRefOfSQuadTree{types.NewTypedMap(__typeForMapOfStringToRefOfSQuadTree, kv...), &ref.Ref{}}
return MapOfStringToRefOfSQuadTree{types.NewTypedMap(cs, __typeForMapOfStringToRefOfSQuadTree, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToRefOfSQuadTree) Def() MapOfStringToRefOfSQuadTreeDef {
@@ -1059,8 +1072,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToRefOfSQuadTree, builderForMapOfStringToRefOfSQuadTree, readerForMapOfStringToRefOfSQuadTree)
}
func builderForMapOfStringToRefOfSQuadTree(v types.Value) types.Value {
return MapOfStringToRefOfSQuadTree{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToRefOfSQuadTree(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToRefOfSQuadTree{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToRefOfSQuadTree(v types.Value) types.Value {
@@ -1092,13 +1105,13 @@ func (m MapOfStringToRefOfSQuadTree) MaybeGet(p string) (RefOfSQuadTree, bool) {
}
func (m MapOfStringToRefOfSQuadTree) Set(k string, v RefOfSQuadTree) MapOfStringToRefOfSQuadTree {
return MapOfStringToRefOfSQuadTree{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToRefOfSQuadTree{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToRefOfSQuadTree) Remove(p string) MapOfStringToRefOfSQuadTree {
return MapOfStringToRefOfSQuadTree{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToRefOfSQuadTree{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToRefOfSQuadTreeIterCallback func(k string, v RefOfSQuadTree) (stop bool)
@@ -1129,7 +1142,7 @@ func (m MapOfStringToRefOfSQuadTree) Filter(cb MapOfStringToRefOfSQuadTreeFilter
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(RefOfSQuadTree))
})
return MapOfStringToRefOfSQuadTree{out, &ref.Ref{}}
return MapOfStringToRefOfSQuadTree{out, m.cs, &ref.Ref{}}
}
// RefOfSQuadTree
@@ -1181,7 +1194,7 @@ func builderForRefOfSQuadTree(r ref.Ref) types.Value {
return NewRefOfSQuadTree(r)
}
func (r RefOfSQuadTree) TargetValue(cs chunks.ChunkSource) SQuadTree {
func (r RefOfSQuadTree) TargetValue(cs chunks.ChunkStore) SQuadTree {
return types.ReadValue(r.target, cs).(SQuadTree)
}

View File

@@ -14,6 +14,7 @@ import (
"strings"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/tealeg/xlsx"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/clients/util"
"github.com/attic-labs/noms/d"
"github.com/attic-labs/noms/dataset"
@@ -70,7 +71,7 @@ func main() {
ref.FromHash(h).String(),
DateDef{time.Now().Format(time.RFC3339)},
companiesRef,
}.New())
}.New(ds.Store()))
d.Exp.True(ok, "Could not commit due to conflicting edit")
}
@@ -93,7 +94,7 @@ func importCompanies(ds dataset.Dataset, fileName string) ref.Ref {
numRounds := 0
for i, row := range roundsSheet.Rows {
if i != 0 {
round := NewRoundFromRow(row)
round := NewRoundFromRow(ds.Store(), row)
pl := round.CompanyPermalink()
roundsByPermalink[pl] = append(roundsByPermalink[pl], round)
numRounds++
@@ -101,16 +102,16 @@ func importCompanies(ds dataset.Dataset, fileName string) ref.Ref {
}
// Read in Companies and map to permalink
companyRefs := NewMapOfStringToRefOfCompany()
companyRefs := NewMapOfStringToRefOfCompany(ds.Store())
companySheet := xlFile.Sheet["Companies"]
for i, row := range companySheet.Rows {
fmt.Printf("\rImporting %d of %d rounds... (%.2f%%)", i, len(companySheet.Rows), float64(i)/float64(len(companySheet.Rows))*float64(100))
if i != 0 {
company := NewCompanyFromRow(row)
company := NewCompanyFromRow(ds.Store(), row)
permalink := company.Permalink()
rounds := roundsByPermalink[permalink]
roundRefs := NewSetOfRefOfRound()
roundRefs := NewSetOfRefOfRound(ds.Store())
for _, r := range rounds {
ref := types.WriteValue(r, ds.Store())
roundRefs = roundRefs.Insert(NewRefOfRound(ref))
@@ -139,7 +140,7 @@ func getExistingCompaniesRef(ds dataset.Dataset, h hash.Hash) ref.Ref {
return ref.Ref{}
}
func NewCompanyFromRow(row *xlsx.Row) Company {
func NewCompanyFromRow(cs chunks.ChunkStore, row *xlsx.Row) Company {
cells := row.Cells
company := CompanyDef{
@@ -161,10 +162,10 @@ func NewCompanyFromRow(row *xlsx.Row) Company {
FirstFundingAt: parseTimeStamp(cells[15], "Company.FirstFundingAt"),
LastFundingAt: parseTimeStamp(cells[16], "Company.LastFundingAt"),
}
return company.New()
return company.New(cs)
}
func NewRoundFromRow(row *xlsx.Row) Round {
func NewRoundFromRow(cs chunks.ChunkStore, row *xlsx.Row) Round {
cells := row.Cells
var raisedAmountUsd float64
@@ -186,7 +187,7 @@ func NewRoundFromRow(row *xlsx.Row) Round {
// Skip FundedYear: 14
RaisedAmountUsd: raisedAmountUsd,
}
return round.New()
return round.New(cs)
}
func parseListOfCategory(s string) SetOfStringDef {

View File

@@ -42,15 +42,17 @@ type Import struct {
_Date Date
_Companies RefOfMapOfStringToRefOfCompany
cs chunks.ChunkStore
ref *ref.Ref
}
func NewImport() Import {
func NewImport(cs chunks.ChunkStore) Import {
return Import{
_FileSHA1: "",
_Date: NewDate(),
_Date: NewDate(cs),
_Companies: NewRefOfMapOfStringToRefOfCompany(ref.Ref{}),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -61,11 +63,12 @@ type ImportDef struct {
Companies ref.Ref
}
func (def ImportDef) New() Import {
func (def ImportDef) New(cs chunks.ChunkStore) Import {
return Import{
_FileSHA1: def.FileSHA1,
_Date: def.Date.New(),
_Date: def.Date.New(cs),
_Companies: NewRefOfMapOfStringToRefOfCompany(def.Companies),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -88,9 +91,9 @@ func init() {
types.RegisterStruct(__typeForImport, builderForImport, readerForImport)
}
func builderForImport(values []types.Value) types.Value {
func builderForImport(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Import{ref: &ref.Ref{}}
s := Import{ref: &ref.Ref{}, cs: cs}
s._FileSHA1 = values[i].(types.String).String()
i++
s._Date = values[i].(Date)
@@ -166,13 +169,15 @@ func (s Import) SetCompanies(val RefOfMapOfStringToRefOfCompany) Import {
type Date struct {
_RFC3339 string
cs chunks.ChunkStore
ref *ref.Ref
}
func NewDate() Date {
func NewDate(cs chunks.ChunkStore) Date {
return Date{
_RFC3339: "",
cs: cs,
ref: &ref.Ref{},
}
}
@@ -181,9 +186,10 @@ type DateDef struct {
RFC3339 string
}
func (def DateDef) New() Date {
func (def DateDef) New(cs chunks.ChunkStore) Date {
return Date{
_RFC3339: def.RFC3339,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -204,9 +210,9 @@ func init() {
types.RegisterStruct(__typeForDate, builderForDate, readerForDate)
}
func builderForDate(values []types.Value) types.Value {
func builderForDate(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Date{ref: &ref.Ref{}}
s := Date{ref: &ref.Ref{}, cs: cs}
s._RFC3339 = values[i].(types.String).String()
i++
return s
@@ -296,7 +302,7 @@ func builderForRefOfMapOfStringToRefOfCompany(r ref.Ref) types.Value {
return NewRefOfMapOfStringToRefOfCompany(r)
}
func (r RefOfMapOfStringToRefOfCompany) TargetValue(cs chunks.ChunkSource) MapOfStringToRefOfCompany {
func (r RefOfMapOfStringToRefOfCompany) TargetValue(cs chunks.ChunkStore) MapOfStringToRefOfCompany {
return types.ReadValue(r.target, cs).(MapOfStringToRefOfCompany)
}
@@ -308,21 +314,22 @@ func (r RefOfMapOfStringToRefOfCompany) SetTargetValue(val MapOfStringToRefOfCom
type MapOfStringToRefOfCompany struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToRefOfCompany() MapOfStringToRefOfCompany {
return MapOfStringToRefOfCompany{types.NewTypedMap(__typeForMapOfStringToRefOfCompany), &ref.Ref{}}
func NewMapOfStringToRefOfCompany(cs chunks.ChunkStore) MapOfStringToRefOfCompany {
return MapOfStringToRefOfCompany{types.NewTypedMap(cs, __typeForMapOfStringToRefOfCompany), cs, &ref.Ref{}}
}
type MapOfStringToRefOfCompanyDef map[string]ref.Ref
func (def MapOfStringToRefOfCompanyDef) New() MapOfStringToRefOfCompany {
func (def MapOfStringToRefOfCompanyDef) New(cs chunks.ChunkStore) MapOfStringToRefOfCompany {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), NewRefOfCompany(v))
}
return MapOfStringToRefOfCompany{types.NewTypedMap(__typeForMapOfStringToRefOfCompany, kv...), &ref.Ref{}}
return MapOfStringToRefOfCompany{types.NewTypedMap(cs, __typeForMapOfStringToRefOfCompany, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToRefOfCompany) Def() MapOfStringToRefOfCompanyDef {
@@ -364,8 +371,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToRefOfCompany, builderForMapOfStringToRefOfCompany, readerForMapOfStringToRefOfCompany)
}
func builderForMapOfStringToRefOfCompany(v types.Value) types.Value {
return MapOfStringToRefOfCompany{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToRefOfCompany(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToRefOfCompany{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToRefOfCompany(v types.Value) types.Value {
@@ -397,13 +404,13 @@ func (m MapOfStringToRefOfCompany) MaybeGet(p string) (RefOfCompany, bool) {
}
func (m MapOfStringToRefOfCompany) Set(k string, v RefOfCompany) MapOfStringToRefOfCompany {
return MapOfStringToRefOfCompany{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToRefOfCompany{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToRefOfCompany) Remove(p string) MapOfStringToRefOfCompany {
return MapOfStringToRefOfCompany{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToRefOfCompany{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToRefOfCompanyIterCallback func(k string, v RefOfCompany) (stop bool)
@@ -434,7 +441,7 @@ func (m MapOfStringToRefOfCompany) Filter(cb MapOfStringToRefOfCompanyFilterCall
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(RefOfCompany))
})
return MapOfStringToRefOfCompany{out, &ref.Ref{}}
return MapOfStringToRefOfCompany{out, m.cs, &ref.Ref{}}
}
// RefOfCompany
@@ -486,7 +493,7 @@ func builderForRefOfCompany(r ref.Ref) types.Value {
return NewRefOfCompany(r)
}
func (r RefOfCompany) TargetValue(cs chunks.ChunkSource) Company {
func (r RefOfCompany) TargetValue(cs chunks.ChunkStore) Company {
return types.ReadValue(r.target, cs).(Company)
}

View File

@@ -71,15 +71,16 @@ type Company struct {
_LastFundingAt int64
_Rounds SetOfRefOfRound
cs chunks.ChunkStore
ref *ref.Ref
}
func NewCompany() Company {
func NewCompany(cs chunks.ChunkStore) Company {
return Company{
_Permalink: "",
_Name: "",
_HomepageUrl: "",
_CategoryList: NewSetOfString(),
_CategoryList: NewSetOfString(cs),
_Market: "",
_FundingTotalUsd: float64(0),
_Status: "",
@@ -91,8 +92,9 @@ func NewCompany() Company {
_FoundedAt: int64(0),
_FirstFundingAt: int64(0),
_LastFundingAt: int64(0),
_Rounds: NewSetOfRefOfRound(),
_Rounds: NewSetOfRefOfRound(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -116,12 +118,12 @@ type CompanyDef struct {
Rounds SetOfRefOfRoundDef
}
func (def CompanyDef) New() Company {
func (def CompanyDef) New(cs chunks.ChunkStore) Company {
return Company{
_Permalink: def.Permalink,
_Name: def.Name,
_HomepageUrl: def.HomepageUrl,
_CategoryList: def.CategoryList.New(),
_CategoryList: def.CategoryList.New(cs),
_Market: def.Market,
_FundingTotalUsd: def.FundingTotalUsd,
_Status: def.Status,
@@ -133,7 +135,8 @@ func (def CompanyDef) New() Company {
_FoundedAt: def.FoundedAt,
_FirstFundingAt: def.FirstFundingAt,
_LastFundingAt: def.LastFundingAt,
_Rounds: def.Rounds.New(),
_Rounds: def.Rounds.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -169,9 +172,9 @@ func init() {
types.RegisterStruct(__typeForCompany, builderForCompany, readerForCompany)
}
func builderForCompany(values []types.Value) types.Value {
func builderForCompany(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Company{ref: &ref.Ref{}}
s := Company{ref: &ref.Ref{}, cs: cs}
s._Permalink = values[i].(types.String).String()
i++
s._Name = values[i].(types.String).String()
@@ -434,10 +437,11 @@ type Round struct {
_FundedAt int64
_RaisedAmountUsd float64
cs chunks.ChunkStore
ref *ref.Ref
}
func NewRound() Round {
func NewRound(cs chunks.ChunkStore) Round {
return Round{
_CompanyPermalink: "",
_FundingRoundPermalink: "",
@@ -446,6 +450,7 @@ func NewRound() Round {
_FundedAt: int64(0),
_RaisedAmountUsd: float64(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -459,7 +464,7 @@ type RoundDef struct {
RaisedAmountUsd float64
}
func (def RoundDef) New() Round {
func (def RoundDef) New(cs chunks.ChunkStore) Round {
return Round{
_CompanyPermalink: def.CompanyPermalink,
_FundingRoundPermalink: def.FundingRoundPermalink,
@@ -467,6 +472,7 @@ func (def RoundDef) New() Round {
_FundingRoundCode: def.FundingRoundCode,
_FundedAt: def.FundedAt,
_RaisedAmountUsd: def.RaisedAmountUsd,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -492,9 +498,9 @@ func init() {
types.RegisterStruct(__typeForRound, builderForRound, readerForRound)
}
func builderForRound(values []types.Value) types.Value {
func builderForRound(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Round{ref: &ref.Ref{}}
s := Round{ref: &ref.Ref{}, cs: cs}
s._CompanyPermalink = values[i].(types.String).String()
i++
s._FundingRoundPermalink = values[i].(types.String).String()
@@ -609,23 +615,24 @@ func (s Round) SetRaisedAmountUsd(val float64) Round {
type SetOfString struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfString() SetOfString {
return SetOfString{types.NewTypedSet(__typeForSetOfString), &ref.Ref{}}
func NewSetOfString(cs chunks.ChunkStore) SetOfString {
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString), cs, &ref.Ref{}}
}
type SetOfStringDef map[string]bool
func (def SetOfStringDef) New() SetOfString {
func (def SetOfStringDef) New(cs chunks.ChunkStore) SetOfString {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = types.NewString(d)
i++
}
return SetOfString{types.NewTypedSet(__typeForSetOfString, l...), &ref.Ref{}}
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString, l...), cs, &ref.Ref{}}
}
func (s SetOfString) Def() SetOfStringDef {
@@ -667,8 +674,8 @@ func init() {
types.RegisterValue(__typeForSetOfString, builderForSetOfString, readerForSetOfString)
}
func builderForSetOfString(v types.Value) types.Value {
return SetOfString{v.(types.Set), &ref.Ref{}}
func builderForSetOfString(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfString{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfString(v types.Value) types.Value {
@@ -715,23 +722,23 @@ func (s SetOfString) Filter(cb SetOfStringFilterCallback) SetOfString {
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(types.String).String())
})
return SetOfString{out, &ref.Ref{}}
return SetOfString{out, s.cs, &ref.Ref{}}
}
func (s SetOfString) Insert(p ...string) SetOfString {
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Remove(p ...string) SetOfString {
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Union(others ...SetOfString) SetOfString {
return SetOfString{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Subtract(others ...SetOfString) SetOfString {
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Any() string {
@@ -758,23 +765,24 @@ func (s SetOfString) fromElemSlice(p []string) []types.Value {
type SetOfRefOfRound struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfRefOfRound() SetOfRefOfRound {
return SetOfRefOfRound{types.NewTypedSet(__typeForSetOfRefOfRound), &ref.Ref{}}
func NewSetOfRefOfRound(cs chunks.ChunkStore) SetOfRefOfRound {
return SetOfRefOfRound{types.NewTypedSet(cs, __typeForSetOfRefOfRound), cs, &ref.Ref{}}
}
type SetOfRefOfRoundDef map[ref.Ref]bool
func (def SetOfRefOfRoundDef) New() SetOfRefOfRound {
func (def SetOfRefOfRoundDef) New(cs chunks.ChunkStore) SetOfRefOfRound {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = NewRefOfRound(d)
i++
}
return SetOfRefOfRound{types.NewTypedSet(__typeForSetOfRefOfRound, l...), &ref.Ref{}}
return SetOfRefOfRound{types.NewTypedSet(cs, __typeForSetOfRefOfRound, l...), cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Def() SetOfRefOfRoundDef {
@@ -816,8 +824,8 @@ func init() {
types.RegisterValue(__typeForSetOfRefOfRound, builderForSetOfRefOfRound, readerForSetOfRefOfRound)
}
func builderForSetOfRefOfRound(v types.Value) types.Value {
return SetOfRefOfRound{v.(types.Set), &ref.Ref{}}
func builderForSetOfRefOfRound(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfRefOfRound{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfRefOfRound(v types.Value) types.Value {
@@ -864,23 +872,23 @@ func (s SetOfRefOfRound) Filter(cb SetOfRefOfRoundFilterCallback) SetOfRefOfRoun
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(RefOfRound))
})
return SetOfRefOfRound{out, &ref.Ref{}}
return SetOfRefOfRound{out, s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Insert(p ...RefOfRound) SetOfRefOfRound {
return SetOfRefOfRound{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfRound{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Remove(p ...RefOfRound) SetOfRefOfRound {
return SetOfRefOfRound{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfRound{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Union(others ...SetOfRefOfRound) SetOfRefOfRound {
return SetOfRefOfRound{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfRound{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Subtract(others ...SetOfRefOfRound) SetOfRefOfRound {
return SetOfRefOfRound{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfRound{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Any() RefOfRound {
@@ -952,7 +960,7 @@ func builderForRefOfRound(r ref.Ref) types.Value {
return NewRefOfRound(r)
}
func (r RefOfRound) TargetValue(cs chunks.ChunkSource) Round {
func (r RefOfRound) TargetValue(cs chunks.ChunkStore) Round {
return types.ReadValue(r.target, cs).(Round)
}

View File

@@ -63,11 +63,11 @@ func main() {
addTimeRounds := func(tn int64, roundRaiseDef RoundRaiseDef) {
t := time.Unix(tn, 0)
year := int32(t.Year())
yk := NewKey().SetYear(year)
yk := NewKey(ds).SetYear(year)
c <- entry{yk, roundRaiseDef}
q := timeToQuarter(t)
qk := NewKey().SetQuarter(QuarterDef{Year: year, Quarter: q}.New())
qk := NewKey(ds).SetQuarter(QuarterDef{Year: year, Quarter: q}.New(ds))
c <- entry{qk, roundRaiseDef}
}
@@ -75,7 +75,7 @@ func main() {
v.IterAllP(64, func(permalink string, r RefOfCompany) {
company := r.TargetValue(ds)
categoryList := company.CategoryList()
regionKey := NewKey().SetRegion(company.Region())
regionKey := NewKey(ds).SetRegion(company.Region())
company.Rounds().IterAll(func(r RefOfRound) {
round := r.TargetValue(ds)
roundRaiseDef := RoundRaiseDef{
@@ -83,7 +83,7 @@ func main() {
Details: r.TargetRef(),
}
categoryList.IterAllP(64, func(category string) {
key := NewKey().SetCategory(category)
key := NewKey(ds).SetCategory(category)
c <- entry{key, roundRaiseDef}
})
@@ -91,7 +91,7 @@ func main() {
addTimeRounds(round.FundedAt(), roundRaiseDef)
roundType := classifyRoundType(round)
roundTypeKey := NewKey().SetRoundType(roundType)
roundTypeKey := NewKey(ds).SetRoundType(roundType)
c <- entry{roundTypeKey, roundRaiseDef}
})
})
@@ -111,7 +111,7 @@ func main() {
mapOfRoundsDef[keyRef] = setDef
}
output := mapOfRoundsDef.New()
output := mapOfRoundsDef.New(ds)
_, ok = outputDataset.Commit(output)
d.Exp.True(ok, "Could not commit due to conflicting edit")

View File

@@ -104,14 +104,16 @@ type Quarter struct {
_Year int32
_Quarter QuarterEnum
cs chunks.ChunkStore
ref *ref.Ref
}
func NewQuarter() Quarter {
func NewQuarter(cs chunks.ChunkStore) Quarter {
return Quarter{
_Year: int32(0),
_Quarter: NewQuarterEnum(),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -121,10 +123,11 @@ type QuarterDef struct {
Quarter QuarterEnum
}
func (def QuarterDef) New() Quarter {
func (def QuarterDef) New(cs chunks.ChunkStore) Quarter {
return Quarter{
_Year: def.Year,
_Quarter: def.Quarter,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -146,9 +149,9 @@ func init() {
types.RegisterStruct(__typeForQuarter, builderForQuarter, readerForQuarter)
}
func builderForQuarter(values []types.Value) types.Value {
func builderForQuarter(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Quarter{ref: &ref.Ref{}}
s := Quarter{ref: &ref.Ref{}, cs: cs}
s._Year = int32(values[i].(types.Int32))
i++
s._Quarter = values[i].(QuarterEnum)
@@ -208,13 +211,15 @@ func (s Quarter) SetQuarter(val QuarterEnum) Quarter {
type Key struct {
__unionIndex uint32
__unionValue types.Value
cs chunks.ChunkStore
ref *ref.Ref
}
func NewKey() Key {
func NewKey(cs chunks.ChunkStore) Key {
return Key{
__unionIndex: 0,
__unionValue: types.NewString(""),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -224,10 +229,11 @@ type KeyDef struct {
__unionValue types.Value
}
func (def KeyDef) New() Key {
func (def KeyDef) New(cs chunks.ChunkStore) Key {
return Key{
__unionIndex: def.__unionIndex,
__unionValue: def.__unionValue,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -249,9 +255,9 @@ func init() {
types.RegisterStruct(__typeForKey, builderForKey, readerForKey)
}
func builderForKey(values []types.Value) types.Value {
func builderForKey(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Key{ref: &ref.Ref{}}
s := Key{ref: &ref.Ref{}, cs: cs}
s.__unionIndex = uint32(values[i].(types.UInt32))
i++
s.__unionValue = values[i]
@@ -307,7 +313,7 @@ func (def KeyDef) Category() (val string, ok bool) {
return def.__unionValue.(types.String).String(), true
}
func (def KeyDef) SetCategory(val string) KeyDef {
func (def KeyDef) SetCategory(cs chunks.ChunkStore, val string) KeyDef {
def.__unionIndex = 0
def.__unionValue = types.NewString(val)
return def
@@ -334,9 +340,9 @@ func (def KeyDef) Quarter() (val QuarterDef, ok bool) {
return def.__unionValue.(Quarter).Def(), true
}
func (def KeyDef) SetQuarter(val QuarterDef) KeyDef {
func (def KeyDef) SetQuarter(cs chunks.ChunkStore, val QuarterDef) KeyDef {
def.__unionIndex = 1
def.__unionValue = val.New()
def.__unionValue = val.New(cs)
return def
}
@@ -361,7 +367,7 @@ func (def KeyDef) Region() (val string, ok bool) {
return def.__unionValue.(types.String).String(), true
}
func (def KeyDef) SetRegion(val string) KeyDef {
func (def KeyDef) SetRegion(cs chunks.ChunkStore, val string) KeyDef {
def.__unionIndex = 2
def.__unionValue = types.NewString(val)
return def
@@ -388,7 +394,7 @@ func (def KeyDef) RoundType() (val RoundTypeEnum, ok bool) {
return def.__unionValue.(RoundTypeEnum), true
}
func (def KeyDef) SetRoundType(val RoundTypeEnum) KeyDef {
func (def KeyDef) SetRoundType(cs chunks.ChunkStore, val RoundTypeEnum) KeyDef {
def.__unionIndex = 3
def.__unionValue = val
return def
@@ -415,7 +421,7 @@ func (def KeyDef) Year() (val int32, ok bool) {
return int32(def.__unionValue.(types.Int32)), true
}
func (def KeyDef) SetYear(val int32) KeyDef {
func (def KeyDef) SetYear(cs chunks.ChunkStore, val int32) KeyDef {
def.__unionIndex = 4
def.__unionValue = types.Int32(val)
return def
@@ -484,14 +490,16 @@ type RoundRaise struct {
_Raised float64
_Details RefOfRound
cs chunks.ChunkStore
ref *ref.Ref
}
func NewRoundRaise() RoundRaise {
func NewRoundRaise(cs chunks.ChunkStore) RoundRaise {
return RoundRaise{
_Raised: float64(0),
_Details: NewRefOfRound(ref.Ref{}),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -501,10 +509,11 @@ type RoundRaiseDef struct {
Details ref.Ref
}
func (def RoundRaiseDef) New() RoundRaise {
func (def RoundRaiseDef) New(cs chunks.ChunkStore) RoundRaise {
return RoundRaise{
_Raised: def.Raised,
_Details: NewRefOfRound(def.Details),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -526,9 +535,9 @@ func init() {
types.RegisterStruct(__typeForRoundRaise, builderForRoundRaise, readerForRoundRaise)
}
func builderForRoundRaise(values []types.Value) types.Value {
func builderForRoundRaise(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := RoundRaise{ref: &ref.Ref{}}
s := RoundRaise{ref: &ref.Ref{}, cs: cs}
s._Raised = float64(values[i].(types.Float64))
i++
s._Details = values[i].(RefOfRound)
@@ -588,21 +597,22 @@ func (s RoundRaise) SetDetails(val RefOfRound) RoundRaise {
type MapOfStringToRefOfCompany struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToRefOfCompany() MapOfStringToRefOfCompany {
return MapOfStringToRefOfCompany{types.NewTypedMap(__typeForMapOfStringToRefOfCompany), &ref.Ref{}}
func NewMapOfStringToRefOfCompany(cs chunks.ChunkStore) MapOfStringToRefOfCompany {
return MapOfStringToRefOfCompany{types.NewTypedMap(cs, __typeForMapOfStringToRefOfCompany), cs, &ref.Ref{}}
}
type MapOfStringToRefOfCompanyDef map[string]ref.Ref
func (def MapOfStringToRefOfCompanyDef) New() MapOfStringToRefOfCompany {
func (def MapOfStringToRefOfCompanyDef) New(cs chunks.ChunkStore) MapOfStringToRefOfCompany {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), NewRefOfCompany(v))
}
return MapOfStringToRefOfCompany{types.NewTypedMap(__typeForMapOfStringToRefOfCompany, kv...), &ref.Ref{}}
return MapOfStringToRefOfCompany{types.NewTypedMap(cs, __typeForMapOfStringToRefOfCompany, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToRefOfCompany) Def() MapOfStringToRefOfCompanyDef {
@@ -644,8 +654,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToRefOfCompany, builderForMapOfStringToRefOfCompany, readerForMapOfStringToRefOfCompany)
}
func builderForMapOfStringToRefOfCompany(v types.Value) types.Value {
return MapOfStringToRefOfCompany{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToRefOfCompany(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToRefOfCompany{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToRefOfCompany(v types.Value) types.Value {
@@ -677,13 +687,13 @@ func (m MapOfStringToRefOfCompany) MaybeGet(p string) (RefOfCompany, bool) {
}
func (m MapOfStringToRefOfCompany) Set(k string, v RefOfCompany) MapOfStringToRefOfCompany {
return MapOfStringToRefOfCompany{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToRefOfCompany{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToRefOfCompany) Remove(p string) MapOfStringToRefOfCompany {
return MapOfStringToRefOfCompany{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToRefOfCompany{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToRefOfCompanyIterCallback func(k string, v RefOfCompany) (stop bool)
@@ -714,28 +724,29 @@ func (m MapOfStringToRefOfCompany) Filter(cb MapOfStringToRefOfCompanyFilterCall
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(RefOfCompany))
})
return MapOfStringToRefOfCompany{out, &ref.Ref{}}
return MapOfStringToRefOfCompany{out, m.cs, &ref.Ref{}}
}
// MapOfRefOfKeyToSetOfRoundRaise
type MapOfRefOfKeyToSetOfRoundRaise struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfRefOfKeyToSetOfRoundRaise() MapOfRefOfKeyToSetOfRoundRaise {
return MapOfRefOfKeyToSetOfRoundRaise{types.NewTypedMap(__typeForMapOfRefOfKeyToSetOfRoundRaise), &ref.Ref{}}
func NewMapOfRefOfKeyToSetOfRoundRaise(cs chunks.ChunkStore) MapOfRefOfKeyToSetOfRoundRaise {
return MapOfRefOfKeyToSetOfRoundRaise{types.NewTypedMap(cs, __typeForMapOfRefOfKeyToSetOfRoundRaise), cs, &ref.Ref{}}
}
type MapOfRefOfKeyToSetOfRoundRaiseDef map[ref.Ref]SetOfRoundRaiseDef
func (def MapOfRefOfKeyToSetOfRoundRaiseDef) New() MapOfRefOfKeyToSetOfRoundRaise {
func (def MapOfRefOfKeyToSetOfRoundRaiseDef) New(cs chunks.ChunkStore) MapOfRefOfKeyToSetOfRoundRaise {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, NewRefOfKey(k), v.New())
kv = append(kv, NewRefOfKey(k), v.New(cs))
}
return MapOfRefOfKeyToSetOfRoundRaise{types.NewTypedMap(__typeForMapOfRefOfKeyToSetOfRoundRaise, kv...), &ref.Ref{}}
return MapOfRefOfKeyToSetOfRoundRaise{types.NewTypedMap(cs, __typeForMapOfRefOfKeyToSetOfRoundRaise, kv...), cs, &ref.Ref{}}
}
func (m MapOfRefOfKeyToSetOfRoundRaise) Def() MapOfRefOfKeyToSetOfRoundRaiseDef {
@@ -777,8 +788,8 @@ func init() {
types.RegisterValue(__typeForMapOfRefOfKeyToSetOfRoundRaise, builderForMapOfRefOfKeyToSetOfRoundRaise, readerForMapOfRefOfKeyToSetOfRoundRaise)
}
func builderForMapOfRefOfKeyToSetOfRoundRaise(v types.Value) types.Value {
return MapOfRefOfKeyToSetOfRoundRaise{v.(types.Map), &ref.Ref{}}
func builderForMapOfRefOfKeyToSetOfRoundRaise(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfRefOfKeyToSetOfRoundRaise{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfRefOfKeyToSetOfRoundRaise(v types.Value) types.Value {
@@ -804,19 +815,19 @@ func (m MapOfRefOfKeyToSetOfRoundRaise) Get(p RefOfKey) SetOfRoundRaise {
func (m MapOfRefOfKeyToSetOfRoundRaise) MaybeGet(p RefOfKey) (SetOfRoundRaise, bool) {
v, ok := m.m.MaybeGet(p)
if !ok {
return NewSetOfRoundRaise(), false
return NewSetOfRoundRaise(m.cs), false
}
return v.(SetOfRoundRaise), ok
}
func (m MapOfRefOfKeyToSetOfRoundRaise) Set(k RefOfKey, v SetOfRoundRaise) MapOfRefOfKeyToSetOfRoundRaise {
return MapOfRefOfKeyToSetOfRoundRaise{m.m.Set(k, v), &ref.Ref{}}
return MapOfRefOfKeyToSetOfRoundRaise{m.m.Set(k, v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfRefOfKeyToSetOfRoundRaise) Remove(p RefOfKey) MapOfRefOfKeyToSetOfRoundRaise {
return MapOfRefOfKeyToSetOfRoundRaise{m.m.Remove(p), &ref.Ref{}}
return MapOfRefOfKeyToSetOfRoundRaise{m.m.Remove(p), m.cs, &ref.Ref{}}
}
type MapOfRefOfKeyToSetOfRoundRaiseIterCallback func(k RefOfKey, v SetOfRoundRaise) (stop bool)
@@ -847,7 +858,7 @@ func (m MapOfRefOfKeyToSetOfRoundRaise) Filter(cb MapOfRefOfKeyToSetOfRoundRaise
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(RefOfKey), v.(SetOfRoundRaise))
})
return MapOfRefOfKeyToSetOfRoundRaise{out, &ref.Ref{}}
return MapOfRefOfKeyToSetOfRoundRaise{out, m.cs, &ref.Ref{}}
}
// RefOfCompany
@@ -899,7 +910,7 @@ func builderForRefOfCompany(r ref.Ref) types.Value {
return NewRefOfCompany(r)
}
func (r RefOfCompany) TargetValue(cs chunks.ChunkSource) Company {
func (r RefOfCompany) TargetValue(cs chunks.ChunkStore) Company {
return types.ReadValue(r.target, cs).(Company)
}
@@ -956,7 +967,7 @@ func builderForRefOfKey(r ref.Ref) types.Value {
return NewRefOfKey(r)
}
func (r RefOfKey) TargetValue(cs chunks.ChunkSource) Key {
func (r RefOfKey) TargetValue(cs chunks.ChunkStore) Key {
return types.ReadValue(r.target, cs).(Key)
}
@@ -968,23 +979,24 @@ func (r RefOfKey) SetTargetValue(val Key, cs chunks.ChunkSink) RefOfKey {
type SetOfRoundRaise struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfRoundRaise() SetOfRoundRaise {
return SetOfRoundRaise{types.NewTypedSet(__typeForSetOfRoundRaise), &ref.Ref{}}
func NewSetOfRoundRaise(cs chunks.ChunkStore) SetOfRoundRaise {
return SetOfRoundRaise{types.NewTypedSet(cs, __typeForSetOfRoundRaise), cs, &ref.Ref{}}
}
type SetOfRoundRaiseDef map[RoundRaiseDef]bool
func (def SetOfRoundRaiseDef) New() SetOfRoundRaise {
func (def SetOfRoundRaiseDef) New(cs chunks.ChunkStore) SetOfRoundRaise {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = d.New()
l[i] = d.New(cs)
i++
}
return SetOfRoundRaise{types.NewTypedSet(__typeForSetOfRoundRaise, l...), &ref.Ref{}}
return SetOfRoundRaise{types.NewTypedSet(cs, __typeForSetOfRoundRaise, l...), cs, &ref.Ref{}}
}
func (s SetOfRoundRaise) Def() SetOfRoundRaiseDef {
@@ -1026,8 +1038,8 @@ func init() {
types.RegisterValue(__typeForSetOfRoundRaise, builderForSetOfRoundRaise, readerForSetOfRoundRaise)
}
func builderForSetOfRoundRaise(v types.Value) types.Value {
return SetOfRoundRaise{v.(types.Set), &ref.Ref{}}
func builderForSetOfRoundRaise(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfRoundRaise{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfRoundRaise(v types.Value) types.Value {
@@ -1074,23 +1086,23 @@ func (s SetOfRoundRaise) Filter(cb SetOfRoundRaiseFilterCallback) SetOfRoundRais
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(RoundRaise))
})
return SetOfRoundRaise{out, &ref.Ref{}}
return SetOfRoundRaise{out, s.cs, &ref.Ref{}}
}
func (s SetOfRoundRaise) Insert(p ...RoundRaise) SetOfRoundRaise {
return SetOfRoundRaise{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRoundRaise{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRoundRaise) Remove(p ...RoundRaise) SetOfRoundRaise {
return SetOfRoundRaise{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRoundRaise{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRoundRaise) Union(others ...SetOfRoundRaise) SetOfRoundRaise {
return SetOfRoundRaise{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRoundRaise{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRoundRaise) Subtract(others ...SetOfRoundRaise) SetOfRoundRaise {
return SetOfRoundRaise{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRoundRaise{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRoundRaise) Any() RoundRaise {

View File

@@ -71,15 +71,16 @@ type Company struct {
_LastFundingAt int64
_Rounds SetOfRefOfRound
cs chunks.ChunkStore
ref *ref.Ref
}
func NewCompany() Company {
func NewCompany(cs chunks.ChunkStore) Company {
return Company{
_Permalink: "",
_Name: "",
_HomepageUrl: "",
_CategoryList: NewSetOfString(),
_CategoryList: NewSetOfString(cs),
_Market: "",
_FundingTotalUsd: float64(0),
_Status: "",
@@ -91,8 +92,9 @@ func NewCompany() Company {
_FoundedAt: int64(0),
_FirstFundingAt: int64(0),
_LastFundingAt: int64(0),
_Rounds: NewSetOfRefOfRound(),
_Rounds: NewSetOfRefOfRound(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -116,12 +118,12 @@ type CompanyDef struct {
Rounds SetOfRefOfRoundDef
}
func (def CompanyDef) New() Company {
func (def CompanyDef) New(cs chunks.ChunkStore) Company {
return Company{
_Permalink: def.Permalink,
_Name: def.Name,
_HomepageUrl: def.HomepageUrl,
_CategoryList: def.CategoryList.New(),
_CategoryList: def.CategoryList.New(cs),
_Market: def.Market,
_FundingTotalUsd: def.FundingTotalUsd,
_Status: def.Status,
@@ -133,7 +135,8 @@ func (def CompanyDef) New() Company {
_FoundedAt: def.FoundedAt,
_FirstFundingAt: def.FirstFundingAt,
_LastFundingAt: def.LastFundingAt,
_Rounds: def.Rounds.New(),
_Rounds: def.Rounds.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -169,9 +172,9 @@ func init() {
types.RegisterStruct(__typeForCompany, builderForCompany, readerForCompany)
}
func builderForCompany(values []types.Value) types.Value {
func builderForCompany(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Company{ref: &ref.Ref{}}
s := Company{ref: &ref.Ref{}, cs: cs}
s._Permalink = values[i].(types.String).String()
i++
s._Name = values[i].(types.String).String()
@@ -434,10 +437,11 @@ type Round struct {
_FundedAt int64
_RaisedAmountUsd float64
cs chunks.ChunkStore
ref *ref.Ref
}
func NewRound() Round {
func NewRound(cs chunks.ChunkStore) Round {
return Round{
_CompanyPermalink: "",
_FundingRoundPermalink: "",
@@ -446,6 +450,7 @@ func NewRound() Round {
_FundedAt: int64(0),
_RaisedAmountUsd: float64(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -459,7 +464,7 @@ type RoundDef struct {
RaisedAmountUsd float64
}
func (def RoundDef) New() Round {
func (def RoundDef) New(cs chunks.ChunkStore) Round {
return Round{
_CompanyPermalink: def.CompanyPermalink,
_FundingRoundPermalink: def.FundingRoundPermalink,
@@ -467,6 +472,7 @@ func (def RoundDef) New() Round {
_FundingRoundCode: def.FundingRoundCode,
_FundedAt: def.FundedAt,
_RaisedAmountUsd: def.RaisedAmountUsd,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -492,9 +498,9 @@ func init() {
types.RegisterStruct(__typeForRound, builderForRound, readerForRound)
}
func builderForRound(values []types.Value) types.Value {
func builderForRound(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Round{ref: &ref.Ref{}}
s := Round{ref: &ref.Ref{}, cs: cs}
s._CompanyPermalink = values[i].(types.String).String()
i++
s._FundingRoundPermalink = values[i].(types.String).String()
@@ -609,23 +615,24 @@ func (s Round) SetRaisedAmountUsd(val float64) Round {
type SetOfString struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfString() SetOfString {
return SetOfString{types.NewTypedSet(__typeForSetOfString), &ref.Ref{}}
func NewSetOfString(cs chunks.ChunkStore) SetOfString {
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString), cs, &ref.Ref{}}
}
type SetOfStringDef map[string]bool
func (def SetOfStringDef) New() SetOfString {
func (def SetOfStringDef) New(cs chunks.ChunkStore) SetOfString {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = types.NewString(d)
i++
}
return SetOfString{types.NewTypedSet(__typeForSetOfString, l...), &ref.Ref{}}
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString, l...), cs, &ref.Ref{}}
}
func (s SetOfString) Def() SetOfStringDef {
@@ -667,8 +674,8 @@ func init() {
types.RegisterValue(__typeForSetOfString, builderForSetOfString, readerForSetOfString)
}
func builderForSetOfString(v types.Value) types.Value {
return SetOfString{v.(types.Set), &ref.Ref{}}
func builderForSetOfString(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfString{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfString(v types.Value) types.Value {
@@ -715,23 +722,23 @@ func (s SetOfString) Filter(cb SetOfStringFilterCallback) SetOfString {
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(types.String).String())
})
return SetOfString{out, &ref.Ref{}}
return SetOfString{out, s.cs, &ref.Ref{}}
}
func (s SetOfString) Insert(p ...string) SetOfString {
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Remove(p ...string) SetOfString {
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Union(others ...SetOfString) SetOfString {
return SetOfString{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Subtract(others ...SetOfString) SetOfString {
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Any() string {
@@ -758,23 +765,24 @@ func (s SetOfString) fromElemSlice(p []string) []types.Value {
type SetOfRefOfRound struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfRefOfRound() SetOfRefOfRound {
return SetOfRefOfRound{types.NewTypedSet(__typeForSetOfRefOfRound), &ref.Ref{}}
func NewSetOfRefOfRound(cs chunks.ChunkStore) SetOfRefOfRound {
return SetOfRefOfRound{types.NewTypedSet(cs, __typeForSetOfRefOfRound), cs, &ref.Ref{}}
}
type SetOfRefOfRoundDef map[ref.Ref]bool
func (def SetOfRefOfRoundDef) New() SetOfRefOfRound {
func (def SetOfRefOfRoundDef) New(cs chunks.ChunkStore) SetOfRefOfRound {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = NewRefOfRound(d)
i++
}
return SetOfRefOfRound{types.NewTypedSet(__typeForSetOfRefOfRound, l...), &ref.Ref{}}
return SetOfRefOfRound{types.NewTypedSet(cs, __typeForSetOfRefOfRound, l...), cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Def() SetOfRefOfRoundDef {
@@ -816,8 +824,8 @@ func init() {
types.RegisterValue(__typeForSetOfRefOfRound, builderForSetOfRefOfRound, readerForSetOfRefOfRound)
}
func builderForSetOfRefOfRound(v types.Value) types.Value {
return SetOfRefOfRound{v.(types.Set), &ref.Ref{}}
func builderForSetOfRefOfRound(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfRefOfRound{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfRefOfRound(v types.Value) types.Value {
@@ -864,23 +872,23 @@ func (s SetOfRefOfRound) Filter(cb SetOfRefOfRoundFilterCallback) SetOfRefOfRoun
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(RefOfRound))
})
return SetOfRefOfRound{out, &ref.Ref{}}
return SetOfRefOfRound{out, s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Insert(p ...RefOfRound) SetOfRefOfRound {
return SetOfRefOfRound{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfRound{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Remove(p ...RefOfRound) SetOfRefOfRound {
return SetOfRefOfRound{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfRound{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Union(others ...SetOfRefOfRound) SetOfRefOfRound {
return SetOfRefOfRound{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfRound{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Subtract(others ...SetOfRefOfRound) SetOfRefOfRound {
return SetOfRefOfRound{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfRound{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRound) Any() RefOfRound {
@@ -952,7 +960,7 @@ func builderForRefOfRound(r ref.Ref) types.Value {
return NewRefOfRound(r)
}
func (r RefOfRound) TargetValue(cs chunks.ChunkSource) Round {
func (r RefOfRound) TargetValue(cs chunks.ChunkStore) Round {
return types.ReadValue(r.target, cs).(Round)
}

View File

@@ -80,7 +80,7 @@ func getUser() {
return
}
} else {
user = NewUser()
user = NewUser(ds.Store())
}
authUser()
@@ -148,7 +148,7 @@ func getAlbum(id string) Album {
fmt.Printf("Photoset: %v\nRef: %s\n", response.Photoset.Title.Content, photos.TargetRef())
return NewAlbum().
return NewAlbum(ds.Store()).
SetId(id).
SetTitle(response.Photoset.Title.Content).
SetPhotos(photos)
@@ -178,7 +178,7 @@ func getAlbums() MapOfStringToAlbum {
}()
}
albums := NewMapOfStringToAlbum()
albums := NewMapOfStringToAlbum(ds.Store())
for {
if albums.Len() == uint64(len(response.Photosets.Photoset)) {
break
@@ -227,16 +227,16 @@ func getAlbumPhotos(id string) RefOfSetOfRefOfRemotePhoto {
})
d.Chk.NoError(err)
photos := NewSetOfRefOfRemotePhoto()
photos := NewSetOfRefOfRemotePhoto(ds.Store())
for _, p := range response.Photoset.Photo {
photo := RemotePhotoDef{
Id: p.Id,
Title: p.Title,
Tags: getTags(p.Tags),
}.New()
}.New(ds.Store())
sizes := NewMapOfSizeToString()
sizes := NewMapOfSizeToString(ds.Store())
sizes = addSize(sizes, p.ThumbURL, p.ThumbWidth, p.ThumbHeight)
sizes = addSize(sizes, p.SmallURL, p.SmallWidth, p.SmallHeight)
sizes = addSize(sizes, p.MediumURL, p.MediumWidth, p.MediumHeight)
@@ -247,7 +247,7 @@ func getAlbumPhotos(id string) RefOfSetOfRefOfRemotePhoto {
lat := deFlickr(p.Latitude)
lon := deFlickr(p.Longitude)
if lat != 0.0 && lon != 0.0 {
photo = photo.SetGeoposition(GeopositionDef{lat, lon}.New())
photo = photo.SetGeoposition(GeopositionDef{lat, lon}.New(ds.Store()))
}
photos = photos.Insert(NewRefOfRemotePhoto(types.WriteValue(photo, ds.Store())))
@@ -301,7 +301,7 @@ func addSize(sizes MapOfSizeToString, url string, width interface{}, height inte
return sizes
}
return sizes.Set(SizeDef{getDim(width), getDim(height)}.New(), url)
return sizes.Set(SizeDef{getDim(width), getDim(height)}.New(ds.Store()), url)
}
func awaitOAuthResponse(l net.Listener, tempCred *oauth.Credentials) error {

View File

@@ -3,6 +3,7 @@
package main
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -48,18 +49,20 @@ type RemotePhoto struct {
_Sizes MapOfSizeToString
_Tags SetOfString
cs chunks.ChunkStore
ref *ref.Ref
}
func NewRemotePhoto() RemotePhoto {
func NewRemotePhoto(cs chunks.ChunkStore) RemotePhoto {
return RemotePhoto{
_Id: "",
_Title: "",
_Url: "",
_Geoposition: NewGeoposition(),
_Sizes: NewMapOfSizeToString(),
_Tags: NewSetOfString(),
_Geoposition: NewGeoposition(cs),
_Sizes: NewMapOfSizeToString(cs),
_Tags: NewSetOfString(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -73,14 +76,15 @@ type RemotePhotoDef struct {
Tags SetOfStringDef
}
func (def RemotePhotoDef) New() RemotePhoto {
func (def RemotePhotoDef) New(cs chunks.ChunkStore) RemotePhoto {
return RemotePhoto{
_Id: def.Id,
_Title: def.Title,
_Url: def.Url,
_Geoposition: def.Geoposition.New(),
_Sizes: def.Sizes.New(),
_Tags: def.Tags.New(),
_Geoposition: def.Geoposition.New(cs),
_Sizes: def.Sizes.New(cs),
_Tags: def.Tags.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -106,9 +110,9 @@ func init() {
types.RegisterStruct(__typeForRemotePhoto, builderForRemotePhoto, readerForRemotePhoto)
}
func builderForRemotePhoto(values []types.Value) types.Value {
func builderForRemotePhoto(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := RemotePhoto{ref: &ref.Ref{}}
s := RemotePhoto{ref: &ref.Ref{}, cs: cs}
s._Id = values[i].(types.String).String()
i++
s._Title = values[i].(types.String).String()
@@ -228,14 +232,16 @@ type Size struct {
_Width uint32
_Height uint32
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSize() Size {
func NewSize(cs chunks.ChunkStore) Size {
return Size{
_Width: uint32(0),
_Height: uint32(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -245,10 +251,11 @@ type SizeDef struct {
Height uint32
}
func (def SizeDef) New() Size {
func (def SizeDef) New(cs chunks.ChunkStore) Size {
return Size{
_Width: def.Width,
_Height: def.Height,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -270,9 +277,9 @@ func init() {
types.RegisterStruct(__typeForSize, builderForSize, readerForSize)
}
func builderForSize(values []types.Value) types.Value {
func builderForSize(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Size{ref: &ref.Ref{}}
s := Size{ref: &ref.Ref{}, cs: cs}
s._Width = uint32(values[i].(types.UInt32))
i++
s._Height = uint32(values[i].(types.UInt32))
@@ -331,21 +338,22 @@ func (s Size) SetHeight(val uint32) Size {
type MapOfSizeToString struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfSizeToString() MapOfSizeToString {
return MapOfSizeToString{types.NewTypedMap(__typeForMapOfSizeToString), &ref.Ref{}}
func NewMapOfSizeToString(cs chunks.ChunkStore) MapOfSizeToString {
return MapOfSizeToString{types.NewTypedMap(cs, __typeForMapOfSizeToString), cs, &ref.Ref{}}
}
type MapOfSizeToStringDef map[SizeDef]string
func (def MapOfSizeToStringDef) New() MapOfSizeToString {
func (def MapOfSizeToStringDef) New(cs chunks.ChunkStore) MapOfSizeToString {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, k.New(), types.NewString(v))
kv = append(kv, k.New(cs), types.NewString(v))
}
return MapOfSizeToString{types.NewTypedMap(__typeForMapOfSizeToString, kv...), &ref.Ref{}}
return MapOfSizeToString{types.NewTypedMap(cs, __typeForMapOfSizeToString, kv...), cs, &ref.Ref{}}
}
func (m MapOfSizeToString) Def() MapOfSizeToStringDef {
@@ -387,8 +395,8 @@ func init() {
types.RegisterValue(__typeForMapOfSizeToString, builderForMapOfSizeToString, readerForMapOfSizeToString)
}
func builderForMapOfSizeToString(v types.Value) types.Value {
return MapOfSizeToString{v.(types.Map), &ref.Ref{}}
func builderForMapOfSizeToString(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfSizeToString{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfSizeToString(v types.Value) types.Value {
@@ -420,13 +428,13 @@ func (m MapOfSizeToString) MaybeGet(p Size) (string, bool) {
}
func (m MapOfSizeToString) Set(k Size, v string) MapOfSizeToString {
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), &ref.Ref{}}
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
return MapOfSizeToString{m.m.Remove(p), &ref.Ref{}}
return MapOfSizeToString{m.m.Remove(p), m.cs, &ref.Ref{}}
}
type MapOfSizeToStringIterCallback func(k Size, v string) (stop bool)
@@ -457,30 +465,31 @@ func (m MapOfSizeToString) Filter(cb MapOfSizeToStringFilterCallback) MapOfSizeT
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(Size), v.(types.String).String())
})
return MapOfSizeToString{out, &ref.Ref{}}
return MapOfSizeToString{out, m.cs, &ref.Ref{}}
}
// SetOfString
type SetOfString struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfString() SetOfString {
return SetOfString{types.NewTypedSet(__typeForSetOfString), &ref.Ref{}}
func NewSetOfString(cs chunks.ChunkStore) SetOfString {
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString), cs, &ref.Ref{}}
}
type SetOfStringDef map[string]bool
func (def SetOfStringDef) New() SetOfString {
func (def SetOfStringDef) New(cs chunks.ChunkStore) SetOfString {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = types.NewString(d)
i++
}
return SetOfString{types.NewTypedSet(__typeForSetOfString, l...), &ref.Ref{}}
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString, l...), cs, &ref.Ref{}}
}
func (s SetOfString) Def() SetOfStringDef {
@@ -522,8 +531,8 @@ func init() {
types.RegisterValue(__typeForSetOfString, builderForSetOfString, readerForSetOfString)
}
func builderForSetOfString(v types.Value) types.Value {
return SetOfString{v.(types.Set), &ref.Ref{}}
func builderForSetOfString(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfString{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfString(v types.Value) types.Value {
@@ -570,23 +579,23 @@ func (s SetOfString) Filter(cb SetOfStringFilterCallback) SetOfString {
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(types.String).String())
})
return SetOfString{out, &ref.Ref{}}
return SetOfString{out, s.cs, &ref.Ref{}}
}
func (s SetOfString) Insert(p ...string) SetOfString {
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Remove(p ...string) SetOfString {
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Union(others ...SetOfString) SetOfString {
return SetOfString{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Subtract(others ...SetOfString) SetOfString {
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Any() string {

View File

@@ -3,6 +3,7 @@
package main
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -38,14 +39,16 @@ type Geoposition struct {
_Latitude float32
_Longitude float32
cs chunks.ChunkStore
ref *ref.Ref
}
func NewGeoposition() Geoposition {
func NewGeoposition(cs chunks.ChunkStore) Geoposition {
return Geoposition{
_Latitude: float32(0),
_Longitude: float32(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -55,10 +58,11 @@ type GeopositionDef struct {
Longitude float32
}
func (def GeopositionDef) New() Geoposition {
func (def GeopositionDef) New(cs chunks.ChunkStore) Geoposition {
return Geoposition{
_Latitude: def.Latitude,
_Longitude: def.Longitude,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -80,9 +84,9 @@ func init() {
types.RegisterStruct(__typeForGeoposition, builderForGeoposition, readerForGeoposition)
}
func builderForGeoposition(values []types.Value) types.Value {
func builderForGeoposition(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Geoposition{ref: &ref.Ref{}}
s := Geoposition{ref: &ref.Ref{}, cs: cs}
s._Latitude = float32(values[i].(types.Float32))
i++
s._Longitude = float32(values[i].(types.Float32))
@@ -143,14 +147,16 @@ type Georectangle struct {
_TopLeft Geoposition
_BottomRight Geoposition
cs chunks.ChunkStore
ref *ref.Ref
}
func NewGeorectangle() Georectangle {
func NewGeorectangle(cs chunks.ChunkStore) Georectangle {
return Georectangle{
_TopLeft: NewGeoposition(),
_BottomRight: NewGeoposition(),
_TopLeft: NewGeoposition(cs),
_BottomRight: NewGeoposition(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -160,10 +166,11 @@ type GeorectangleDef struct {
BottomRight GeopositionDef
}
func (def GeorectangleDef) New() Georectangle {
func (def GeorectangleDef) New(cs chunks.ChunkStore) Georectangle {
return Georectangle{
_TopLeft: def.TopLeft.New(),
_BottomRight: def.BottomRight.New(),
_TopLeft: def.TopLeft.New(cs),
_BottomRight: def.BottomRight.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -185,9 +192,9 @@ func init() {
types.RegisterStruct(__typeForGeorectangle, builderForGeorectangle, readerForGeorectangle)
}
func builderForGeorectangle(values []types.Value) types.Value {
func builderForGeorectangle(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Georectangle{ref: &ref.Ref{}}
s := Georectangle{ref: &ref.Ref{}, cs: cs}
s._TopLeft = values[i].(Geoposition)
i++
s._BottomRight = values[i].(Geoposition)

View File

@@ -48,17 +48,19 @@ type User struct {
_OAuthSecret string
_Albums MapOfStringToAlbum
cs chunks.ChunkStore
ref *ref.Ref
}
func NewUser() User {
func NewUser(cs chunks.ChunkStore) User {
return User{
_Id: "",
_Name: "",
_OAuthToken: "",
_OAuthSecret: "",
_Albums: NewMapOfStringToAlbum(),
_Albums: NewMapOfStringToAlbum(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -71,13 +73,14 @@ type UserDef struct {
Albums MapOfStringToAlbumDef
}
func (def UserDef) New() User {
func (def UserDef) New(cs chunks.ChunkStore) User {
return User{
_Id: def.Id,
_Name: def.Name,
_OAuthToken: def.OAuthToken,
_OAuthSecret: def.OAuthSecret,
_Albums: def.Albums.New(),
_Albums: def.Albums.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -102,9 +105,9 @@ func init() {
types.RegisterStruct(__typeForUser, builderForUser, readerForUser)
}
func builderForUser(values []types.Value) types.Value {
func builderForUser(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := User{ref: &ref.Ref{}}
s := User{ref: &ref.Ref{}, cs: cs}
s._Id = values[i].(types.String).String()
i++
s._Name = values[i].(types.String).String()
@@ -209,15 +212,17 @@ type Album struct {
_Title string
_Photos RefOfSetOfRefOfRemotePhoto
cs chunks.ChunkStore
ref *ref.Ref
}
func NewAlbum() Album {
func NewAlbum(cs chunks.ChunkStore) Album {
return Album{
_Id: "",
_Title: "",
_Photos: NewRefOfSetOfRefOfRemotePhoto(ref.Ref{}),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -228,11 +233,12 @@ type AlbumDef struct {
Photos ref.Ref
}
func (def AlbumDef) New() Album {
func (def AlbumDef) New(cs chunks.ChunkStore) Album {
return Album{
_Id: def.Id,
_Title: def.Title,
_Photos: NewRefOfSetOfRefOfRemotePhoto(def.Photos),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -255,9 +261,9 @@ func init() {
types.RegisterStruct(__typeForAlbum, builderForAlbum, readerForAlbum)
}
func builderForAlbum(values []types.Value) types.Value {
func builderForAlbum(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Album{ref: &ref.Ref{}}
s := Album{ref: &ref.Ref{}, cs: cs}
s._Id = values[i].(types.String).String()
i++
s._Title = values[i].(types.String).String()
@@ -331,21 +337,22 @@ func (s Album) SetPhotos(val RefOfSetOfRefOfRemotePhoto) Album {
type MapOfStringToAlbum struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToAlbum() MapOfStringToAlbum {
return MapOfStringToAlbum{types.NewTypedMap(__typeForMapOfStringToAlbum), &ref.Ref{}}
func NewMapOfStringToAlbum(cs chunks.ChunkStore) MapOfStringToAlbum {
return MapOfStringToAlbum{types.NewTypedMap(cs, __typeForMapOfStringToAlbum), cs, &ref.Ref{}}
}
type MapOfStringToAlbumDef map[string]AlbumDef
func (def MapOfStringToAlbumDef) New() MapOfStringToAlbum {
func (def MapOfStringToAlbumDef) New(cs chunks.ChunkStore) MapOfStringToAlbum {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), v.New())
kv = append(kv, types.NewString(k), v.New(cs))
}
return MapOfStringToAlbum{types.NewTypedMap(__typeForMapOfStringToAlbum, kv...), &ref.Ref{}}
return MapOfStringToAlbum{types.NewTypedMap(cs, __typeForMapOfStringToAlbum, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToAlbum) Def() MapOfStringToAlbumDef {
@@ -387,8 +394,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToAlbum, builderForMapOfStringToAlbum, readerForMapOfStringToAlbum)
}
func builderForMapOfStringToAlbum(v types.Value) types.Value {
return MapOfStringToAlbum{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToAlbum(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToAlbum{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToAlbum(v types.Value) types.Value {
@@ -414,19 +421,19 @@ func (m MapOfStringToAlbum) Get(p string) Album {
func (m MapOfStringToAlbum) MaybeGet(p string) (Album, bool) {
v, ok := m.m.MaybeGet(types.NewString(p))
if !ok {
return NewAlbum(), false
return NewAlbum(m.cs), false
}
return v.(Album), ok
}
func (m MapOfStringToAlbum) Set(k string, v Album) MapOfStringToAlbum {
return MapOfStringToAlbum{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToAlbum{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToAlbum) Remove(p string) MapOfStringToAlbum {
return MapOfStringToAlbum{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToAlbum{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToAlbumIterCallback func(k string, v Album) (stop bool)
@@ -457,7 +464,7 @@ func (m MapOfStringToAlbum) Filter(cb MapOfStringToAlbumFilterCallback) MapOfStr
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(Album))
})
return MapOfStringToAlbum{out, &ref.Ref{}}
return MapOfStringToAlbum{out, m.cs, &ref.Ref{}}
}
// RefOfUser
@@ -509,7 +516,7 @@ func builderForRefOfUser(r ref.Ref) types.Value {
return NewRefOfUser(r)
}
func (r RefOfUser) TargetValue(cs chunks.ChunkSource) User {
func (r RefOfUser) TargetValue(cs chunks.ChunkStore) User {
return types.ReadValue(r.target, cs).(User)
}
@@ -566,7 +573,7 @@ func builderForRefOfSetOfRefOfRemotePhoto(r ref.Ref) types.Value {
return NewRefOfSetOfRefOfRemotePhoto(r)
}
func (r RefOfSetOfRefOfRemotePhoto) TargetValue(cs chunks.ChunkSource) SetOfRefOfRemotePhoto {
func (r RefOfSetOfRefOfRemotePhoto) TargetValue(cs chunks.ChunkStore) SetOfRefOfRemotePhoto {
return types.ReadValue(r.target, cs).(SetOfRefOfRemotePhoto)
}
@@ -578,23 +585,24 @@ func (r RefOfSetOfRefOfRemotePhoto) SetTargetValue(val SetOfRefOfRemotePhoto, cs
type SetOfRefOfRemotePhoto struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfRefOfRemotePhoto() SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{types.NewTypedSet(__typeForSetOfRefOfRemotePhoto), &ref.Ref{}}
func NewSetOfRefOfRemotePhoto(cs chunks.ChunkStore) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{types.NewTypedSet(cs, __typeForSetOfRefOfRemotePhoto), cs, &ref.Ref{}}
}
type SetOfRefOfRemotePhotoDef map[ref.Ref]bool
func (def SetOfRefOfRemotePhotoDef) New() SetOfRefOfRemotePhoto {
func (def SetOfRefOfRemotePhotoDef) New(cs chunks.ChunkStore) SetOfRefOfRemotePhoto {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = NewRefOfRemotePhoto(d)
i++
}
return SetOfRefOfRemotePhoto{types.NewTypedSet(__typeForSetOfRefOfRemotePhoto, l...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{types.NewTypedSet(cs, __typeForSetOfRefOfRemotePhoto, l...), cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Def() SetOfRefOfRemotePhotoDef {
@@ -636,8 +644,8 @@ func init() {
types.RegisterValue(__typeForSetOfRefOfRemotePhoto, builderForSetOfRefOfRemotePhoto, readerForSetOfRefOfRemotePhoto)
}
func builderForSetOfRefOfRemotePhoto(v types.Value) types.Value {
return SetOfRefOfRemotePhoto{v.(types.Set), &ref.Ref{}}
func builderForSetOfRefOfRemotePhoto(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfRefOfRemotePhoto{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfRefOfRemotePhoto(v types.Value) types.Value {
@@ -684,23 +692,23 @@ func (s SetOfRefOfRemotePhoto) Filter(cb SetOfRefOfRemotePhotoFilterCallback) Se
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(RefOfRemotePhoto))
})
return SetOfRefOfRemotePhoto{out, &ref.Ref{}}
return SetOfRefOfRemotePhoto{out, s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Insert(p ...RefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Remove(p ...RefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Union(others ...SetOfRefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Subtract(others ...SetOfRefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Any() RefOfRemotePhoto {
@@ -772,7 +780,7 @@ func builderForRefOfRemotePhoto(r ref.Ref) types.Value {
return NewRefOfRemotePhoto(r)
}
func (r RefOfRemotePhoto) TargetValue(cs chunks.ChunkSource) RemotePhoto {
func (r RefOfRemotePhoto) TargetValue(cs chunks.ChunkStore) RemotePhoto {
return types.ReadValue(r.target, cs).(RemotePhoto)
}

View File

@@ -41,6 +41,6 @@ func main() {
log.Fatalln("Error decoding JSON: ", err)
}
_, ok := ds.Commit(util.NomsValueFromDecodedJSON(jsonObject))
_, ok := ds.Commit(util.NomsValueFromDecodedJSON(ds.Store(), jsonObject))
d.Exp.True(ok, "Could not commit due to conflicting edit")
}

View File

@@ -37,7 +37,7 @@ func addMp3(ds *dataset.Dataset, filename string) {
Album: id3.Album(),
Year: id3.Year(),
Mp3: types.NewBlob(bufio.NewReader(mp3_file), ds.Store()),
}.New()
}.New(ds.Store())
songs := readSongsFromDataset(ds).Append(new_song)
if _, ok := ds.Commit(songs); ok {
fmt.Println("Successfully committed", filename)
@@ -64,7 +64,7 @@ func listSongs(ds *dataset.Dataset) {
}
func readSongsFromDataset(ds *dataset.Dataset) ListOfSong {
songs := NewListOfSong()
songs := NewListOfSong(ds.Store())
if commit, ok := ds.MaybeHead(); ok {
songs = commit.Value().(ListOfSong)
}

View File

@@ -3,6 +3,7 @@
package main
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -37,10 +38,11 @@ type Song struct {
_Year string
_Mp3 types.Blob
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSong() Song {
func NewSong(cs chunks.ChunkStore) Song {
return Song{
_Title: "",
_Artist: "",
@@ -48,6 +50,7 @@ func NewSong() Song {
_Year: "",
_Mp3: types.NewEmptyBlob(),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -60,13 +63,14 @@ type SongDef struct {
Mp3 types.Blob
}
func (def SongDef) New() Song {
func (def SongDef) New(cs chunks.ChunkStore) Song {
return Song{
_Title: def.Title,
_Artist: def.Artist,
_Album: def.Album,
_Year: def.Year,
_Mp3: def.Mp3,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -91,9 +95,9 @@ func init() {
types.RegisterStruct(__typeForSong, builderForSong, readerForSong)
}
func builderForSong(values []types.Value) types.Value {
func builderForSong(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Song{ref: &ref.Ref{}}
s := Song{ref: &ref.Ref{}, cs: cs}
s._Title = values[i].(types.String).String()
i++
s._Artist = values[i].(types.String).String()
@@ -195,21 +199,22 @@ func (s Song) SetMp3(val types.Blob) Song {
type ListOfSong struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfSong() ListOfSong {
return ListOfSong{types.NewTypedList(__typeForListOfSong), &ref.Ref{}}
func NewListOfSong(cs chunks.ChunkStore) ListOfSong {
return ListOfSong{types.NewTypedList(cs, __typeForListOfSong), cs, &ref.Ref{}}
}
type ListOfSongDef []SongDef
func (def ListOfSongDef) New() ListOfSong {
func (def ListOfSongDef) New(cs chunks.ChunkStore) ListOfSong {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = d.New()
l[i] = d.New(cs)
}
return ListOfSong{types.NewTypedList(__typeForListOfSong, l...), &ref.Ref{}}
return ListOfSong{types.NewTypedList(cs, __typeForListOfSong, l...), cs, &ref.Ref{}}
}
func (l ListOfSong) Def() ListOfSongDef {
@@ -250,8 +255,8 @@ func init() {
types.RegisterValue(__typeForListOfSong, builderForListOfSong, readerForListOfSong)
}
func builderForListOfSong(v types.Value) types.Value {
return ListOfSong{v.(types.List), &ref.Ref{}}
func builderForListOfSong(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfSong{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfSong(v types.Value) types.Value {
@@ -271,27 +276,27 @@ func (l ListOfSong) Get(i uint64) Song {
}
func (l ListOfSong) Slice(idx uint64, end uint64) ListOfSong {
return ListOfSong{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfSong{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfSong) Set(i uint64, val Song) ListOfSong {
return ListOfSong{l.l.Set(i, val), &ref.Ref{}}
return ListOfSong{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfSong) Append(v ...Song) ListOfSong {
return ListOfSong{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfSong{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfSong) Insert(idx uint64, v ...Song) ListOfSong {
return ListOfSong{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfSong{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfSong) Remove(idx uint64, end uint64) ListOfSong {
return ListOfSong{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfSong{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfSong) RemoveAt(idx uint64) ListOfSong {
return ListOfSong{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfSong{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfSong) fromElemSlice(p []Song) []types.Value {
@@ -330,5 +335,5 @@ func (l ListOfSong) Filter(cb ListOfSongFilterCallback) ListOfSong {
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(Song), i)
})
return ListOfSong{out, &ref.Ref{}}
return ListOfSong{out, l.cs, &ref.Ref{}}
}

View File

@@ -115,9 +115,9 @@ func getSingleAlbum(albumID string) *User {
aj := AlbumJSON{}
path := fmt.Sprintf("user/default/albumid/%s?alt=json&max-results=0", albumID)
callPicasaAPI(authHTTPClient, path, &aj)
u := UserDef{Id: aj.Feed.UserID.V, Name: aj.Feed.UserName.V}.New()
u := UserDef{Id: aj.Feed.UserID.V, Name: aj.Feed.UserName.V}.New(ds.Store())
albums := NewMapOfStringToAlbum()
albums := NewMapOfStringToAlbum(ds.Store())
albums = getAlbum(0, aj.Feed.ID.V, aj.Feed.Title.V, uint32(aj.Feed.NumPhotos.V), albums)
types.WriteValue(albums, ds.Store())
@@ -131,8 +131,8 @@ func getAlbums() *User {
if !*quietFlag {
fmt.Printf("Found %d albums\n", len(alj.Feed.Entry))
}
albums := NewMapOfStringToAlbum()
user := UserDef{Id: alj.Feed.UserID.V, Name: alj.Feed.UserName.V}.New()
albums := NewMapOfStringToAlbum(ds.Store())
user := UserDef{Id: alj.Feed.UserID.V, Name: alj.Feed.UserName.V}.New(ds.Store())
for i, entry := range alj.Feed.Entry {
albums = getAlbum(i, entry.ID.V, entry.Title.V, uint32(entry.NumPhotos.V), albums)
}
@@ -143,7 +143,7 @@ func getAlbums() *User {
}
func getAlbum(albumIndex int, albumId, albumTitle string, numPhotos uint32, albums MapOfStringToAlbum) MapOfStringToAlbum {
a := AlbumDef{Id: albumId, Title: albumTitle, NumPhotos: uint32(numPhotos)}.New()
a := AlbumDef{Id: albumId, Title: albumTitle, NumPhotos: uint32(numPhotos)}.New(ds.Store())
remotePhotoRefs := getRemotePhotoRefs(&a, albumIndex)
r := types.WriteValue(remotePhotoRefs, ds.Store())
a = a.SetPhotos(NewRefOfSetOfRefOfRemotePhoto(r))
@@ -154,7 +154,7 @@ func getRemotePhotoRefs(album *Album, albumIndex int) *SetOfRefOfRemotePhoto {
if album.NumPhotos() <= 0 {
return nil
}
remotePhotoRefs := NewSetOfRefOfRemotePhoto()
remotePhotoRefs := NewSetOfRefOfRemotePhoto(ds.Store())
if !*quietFlag {
fmt.Printf("Album #%d: %q contains %d photos... ", albumIndex, album.Title(), album.NumPhotos())
}
@@ -185,7 +185,7 @@ func getRemotePhotoRefs(album *Album, albumIndex int) *SetOfRefOfRemotePhoto {
Url: e.Content.Src,
Sizes: sizes,
Tags: tags,
}.New()
}.New(ds.Store())
r := types.WriteValue(p, ds.Store())
remotePhotoRefs = remotePhotoRefs.Insert(NewRefOfRemotePhoto(r))
}

View File

@@ -51,18 +51,20 @@ type User struct {
_OAuthToken string
_OAuthSecret string
cs chunks.ChunkStore
ref *ref.Ref
}
func NewUser() User {
func NewUser(cs chunks.ChunkStore) User {
return User{
_Id: "",
_Name: "",
_Albums: NewMapOfStringToAlbum(),
_Albums: NewMapOfStringToAlbum(cs),
_RefreshToken: "",
_OAuthToken: "",
_OAuthSecret: "",
cs: cs,
ref: &ref.Ref{},
}
}
@@ -76,14 +78,15 @@ type UserDef struct {
OAuthSecret string
}
func (def UserDef) New() User {
func (def UserDef) New(cs chunks.ChunkStore) User {
return User{
_Id: def.Id,
_Name: def.Name,
_Albums: def.Albums.New(),
_Albums: def.Albums.New(cs),
_RefreshToken: def.RefreshToken,
_OAuthToken: def.OAuthToken,
_OAuthSecret: def.OAuthSecret,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -109,9 +112,9 @@ func init() {
types.RegisterStruct(__typeForUser, builderForUser, readerForUser)
}
func builderForUser(values []types.Value) types.Value {
func builderForUser(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := User{ref: &ref.Ref{}}
s := User{ref: &ref.Ref{}, cs: cs}
s._Id = values[i].(types.String).String()
i++
s._Name = values[i].(types.String).String()
@@ -231,16 +234,18 @@ type Album struct {
_NumPhotos uint32
_Photos RefOfSetOfRefOfRemotePhoto
cs chunks.ChunkStore
ref *ref.Ref
}
func NewAlbum() Album {
func NewAlbum(cs chunks.ChunkStore) Album {
return Album{
_Id: "",
_Title: "",
_NumPhotos: uint32(0),
_Photos: NewRefOfSetOfRefOfRemotePhoto(ref.Ref{}),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -252,12 +257,13 @@ type AlbumDef struct {
Photos ref.Ref
}
func (def AlbumDef) New() Album {
func (def AlbumDef) New(cs chunks.ChunkStore) Album {
return Album{
_Id: def.Id,
_Title: def.Title,
_NumPhotos: def.NumPhotos,
_Photos: NewRefOfSetOfRefOfRemotePhoto(def.Photos),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -281,9 +287,9 @@ func init() {
types.RegisterStruct(__typeForAlbum, builderForAlbum, readerForAlbum)
}
func builderForAlbum(values []types.Value) types.Value {
func builderForAlbum(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Album{ref: &ref.Ref{}}
s := Album{ref: &ref.Ref{}, cs: cs}
s._Id = values[i].(types.String).String()
i++
s._Title = values[i].(types.String).String()
@@ -371,21 +377,22 @@ func (s Album) SetPhotos(val RefOfSetOfRefOfRemotePhoto) Album {
type MapOfStringToAlbum struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToAlbum() MapOfStringToAlbum {
return MapOfStringToAlbum{types.NewTypedMap(__typeForMapOfStringToAlbum), &ref.Ref{}}
func NewMapOfStringToAlbum(cs chunks.ChunkStore) MapOfStringToAlbum {
return MapOfStringToAlbum{types.NewTypedMap(cs, __typeForMapOfStringToAlbum), cs, &ref.Ref{}}
}
type MapOfStringToAlbumDef map[string]AlbumDef
func (def MapOfStringToAlbumDef) New() MapOfStringToAlbum {
func (def MapOfStringToAlbumDef) New(cs chunks.ChunkStore) MapOfStringToAlbum {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), v.New())
kv = append(kv, types.NewString(k), v.New(cs))
}
return MapOfStringToAlbum{types.NewTypedMap(__typeForMapOfStringToAlbum, kv...), &ref.Ref{}}
return MapOfStringToAlbum{types.NewTypedMap(cs, __typeForMapOfStringToAlbum, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToAlbum) Def() MapOfStringToAlbumDef {
@@ -427,8 +434,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToAlbum, builderForMapOfStringToAlbum, readerForMapOfStringToAlbum)
}
func builderForMapOfStringToAlbum(v types.Value) types.Value {
return MapOfStringToAlbum{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToAlbum(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToAlbum{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToAlbum(v types.Value) types.Value {
@@ -454,19 +461,19 @@ func (m MapOfStringToAlbum) Get(p string) Album {
func (m MapOfStringToAlbum) MaybeGet(p string) (Album, bool) {
v, ok := m.m.MaybeGet(types.NewString(p))
if !ok {
return NewAlbum(), false
return NewAlbum(m.cs), false
}
return v.(Album), ok
}
func (m MapOfStringToAlbum) Set(k string, v Album) MapOfStringToAlbum {
return MapOfStringToAlbum{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToAlbum{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToAlbum) Remove(p string) MapOfStringToAlbum {
return MapOfStringToAlbum{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToAlbum{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToAlbumIterCallback func(k string, v Album) (stop bool)
@@ -497,18 +504,19 @@ func (m MapOfStringToAlbum) Filter(cb MapOfStringToAlbumFilterCallback) MapOfStr
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(Album))
})
return MapOfStringToAlbum{out, &ref.Ref{}}
return MapOfStringToAlbum{out, m.cs, &ref.Ref{}}
}
// SetOfRemotePhoto
type SetOfRemotePhoto struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfRemotePhoto() SetOfRemotePhoto {
return SetOfRemotePhoto{types.NewTypedSet(__typeForSetOfRemotePhoto), &ref.Ref{}}
func NewSetOfRemotePhoto(cs chunks.ChunkStore) SetOfRemotePhoto {
return SetOfRemotePhoto{types.NewTypedSet(cs, __typeForSetOfRemotePhoto), cs, &ref.Ref{}}
}
func (s SetOfRemotePhoto) Equals(other types.Value) bool {
@@ -541,8 +549,8 @@ func init() {
types.RegisterValue(__typeForSetOfRemotePhoto, builderForSetOfRemotePhoto, readerForSetOfRemotePhoto)
}
func builderForSetOfRemotePhoto(v types.Value) types.Value {
return SetOfRemotePhoto{v.(types.Set), &ref.Ref{}}
func builderForSetOfRemotePhoto(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfRemotePhoto{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfRemotePhoto(v types.Value) types.Value {
@@ -589,23 +597,23 @@ func (s SetOfRemotePhoto) Filter(cb SetOfRemotePhotoFilterCallback) SetOfRemoteP
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(RemotePhoto))
})
return SetOfRemotePhoto{out, &ref.Ref{}}
return SetOfRemotePhoto{out, s.cs, &ref.Ref{}}
}
func (s SetOfRemotePhoto) Insert(p ...RemotePhoto) SetOfRemotePhoto {
return SetOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRemotePhoto) Remove(p ...RemotePhoto) SetOfRemotePhoto {
return SetOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRemotePhoto) Union(others ...SetOfRemotePhoto) SetOfRemotePhoto {
return SetOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRemotePhoto) Subtract(others ...SetOfRemotePhoto) SetOfRemotePhoto {
return SetOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRemotePhoto) Any() RemotePhoto {
@@ -677,7 +685,7 @@ func builderForRefOfUser(r ref.Ref) types.Value {
return NewRefOfUser(r)
}
func (r RefOfUser) TargetValue(cs chunks.ChunkSource) User {
func (r RefOfUser) TargetValue(cs chunks.ChunkStore) User {
return types.ReadValue(r.target, cs).(User)
}
@@ -734,7 +742,7 @@ func builderForRefOfSetOfRefOfRemotePhoto(r ref.Ref) types.Value {
return NewRefOfSetOfRefOfRemotePhoto(r)
}
func (r RefOfSetOfRefOfRemotePhoto) TargetValue(cs chunks.ChunkSource) SetOfRefOfRemotePhoto {
func (r RefOfSetOfRefOfRemotePhoto) TargetValue(cs chunks.ChunkStore) SetOfRefOfRemotePhoto {
return types.ReadValue(r.target, cs).(SetOfRefOfRemotePhoto)
}
@@ -746,23 +754,24 @@ func (r RefOfSetOfRefOfRemotePhoto) SetTargetValue(val SetOfRefOfRemotePhoto, cs
type SetOfRefOfRemotePhoto struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfRefOfRemotePhoto() SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{types.NewTypedSet(__typeForSetOfRefOfRemotePhoto), &ref.Ref{}}
func NewSetOfRefOfRemotePhoto(cs chunks.ChunkStore) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{types.NewTypedSet(cs, __typeForSetOfRefOfRemotePhoto), cs, &ref.Ref{}}
}
type SetOfRefOfRemotePhotoDef map[ref.Ref]bool
func (def SetOfRefOfRemotePhotoDef) New() SetOfRefOfRemotePhoto {
func (def SetOfRefOfRemotePhotoDef) New(cs chunks.ChunkStore) SetOfRefOfRemotePhoto {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = NewRefOfRemotePhoto(d)
i++
}
return SetOfRefOfRemotePhoto{types.NewTypedSet(__typeForSetOfRefOfRemotePhoto, l...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{types.NewTypedSet(cs, __typeForSetOfRefOfRemotePhoto, l...), cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Def() SetOfRefOfRemotePhotoDef {
@@ -804,8 +813,8 @@ func init() {
types.RegisterValue(__typeForSetOfRefOfRemotePhoto, builderForSetOfRefOfRemotePhoto, readerForSetOfRefOfRemotePhoto)
}
func builderForSetOfRefOfRemotePhoto(v types.Value) types.Value {
return SetOfRefOfRemotePhoto{v.(types.Set), &ref.Ref{}}
func builderForSetOfRefOfRemotePhoto(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfRefOfRemotePhoto{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfRefOfRemotePhoto(v types.Value) types.Value {
@@ -852,23 +861,23 @@ func (s SetOfRefOfRemotePhoto) Filter(cb SetOfRefOfRemotePhotoFilterCallback) Se
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(RefOfRemotePhoto))
})
return SetOfRefOfRemotePhoto{out, &ref.Ref{}}
return SetOfRefOfRemotePhoto{out, s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Insert(p ...RefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Remove(p ...RefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Union(others ...SetOfRefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Subtract(others ...SetOfRefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Any() RefOfRemotePhoto {
@@ -940,7 +949,7 @@ func builderForRefOfRemotePhoto(r ref.Ref) types.Value {
return NewRefOfRemotePhoto(r)
}
func (r RefOfRemotePhoto) TargetValue(cs chunks.ChunkSource) RemotePhoto {
func (r RefOfRemotePhoto) TargetValue(cs chunks.ChunkStore) RemotePhoto {
return types.ReadValue(r.target, cs).(RemotePhoto)
}

View File

@@ -3,6 +3,7 @@
package main
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -48,18 +49,20 @@ type RemotePhoto struct {
_Sizes MapOfSizeToString
_Tags SetOfString
cs chunks.ChunkStore
ref *ref.Ref
}
func NewRemotePhoto() RemotePhoto {
func NewRemotePhoto(cs chunks.ChunkStore) RemotePhoto {
return RemotePhoto{
_Id: "",
_Title: "",
_Url: "",
_Geoposition: NewGeoposition(),
_Sizes: NewMapOfSizeToString(),
_Tags: NewSetOfString(),
_Geoposition: NewGeoposition(cs),
_Sizes: NewMapOfSizeToString(cs),
_Tags: NewSetOfString(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -73,14 +76,15 @@ type RemotePhotoDef struct {
Tags SetOfStringDef
}
func (def RemotePhotoDef) New() RemotePhoto {
func (def RemotePhotoDef) New(cs chunks.ChunkStore) RemotePhoto {
return RemotePhoto{
_Id: def.Id,
_Title: def.Title,
_Url: def.Url,
_Geoposition: def.Geoposition.New(),
_Sizes: def.Sizes.New(),
_Tags: def.Tags.New(),
_Geoposition: def.Geoposition.New(cs),
_Sizes: def.Sizes.New(cs),
_Tags: def.Tags.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -106,9 +110,9 @@ func init() {
types.RegisterStruct(__typeForRemotePhoto, builderForRemotePhoto, readerForRemotePhoto)
}
func builderForRemotePhoto(values []types.Value) types.Value {
func builderForRemotePhoto(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := RemotePhoto{ref: &ref.Ref{}}
s := RemotePhoto{ref: &ref.Ref{}, cs: cs}
s._Id = values[i].(types.String).String()
i++
s._Title = values[i].(types.String).String()
@@ -228,14 +232,16 @@ type Size struct {
_Width uint32
_Height uint32
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSize() Size {
func NewSize(cs chunks.ChunkStore) Size {
return Size{
_Width: uint32(0),
_Height: uint32(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -245,10 +251,11 @@ type SizeDef struct {
Height uint32
}
func (def SizeDef) New() Size {
func (def SizeDef) New(cs chunks.ChunkStore) Size {
return Size{
_Width: def.Width,
_Height: def.Height,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -270,9 +277,9 @@ func init() {
types.RegisterStruct(__typeForSize, builderForSize, readerForSize)
}
func builderForSize(values []types.Value) types.Value {
func builderForSize(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Size{ref: &ref.Ref{}}
s := Size{ref: &ref.Ref{}, cs: cs}
s._Width = uint32(values[i].(types.UInt32))
i++
s._Height = uint32(values[i].(types.UInt32))
@@ -331,21 +338,22 @@ func (s Size) SetHeight(val uint32) Size {
type MapOfSizeToString struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfSizeToString() MapOfSizeToString {
return MapOfSizeToString{types.NewTypedMap(__typeForMapOfSizeToString), &ref.Ref{}}
func NewMapOfSizeToString(cs chunks.ChunkStore) MapOfSizeToString {
return MapOfSizeToString{types.NewTypedMap(cs, __typeForMapOfSizeToString), cs, &ref.Ref{}}
}
type MapOfSizeToStringDef map[SizeDef]string
func (def MapOfSizeToStringDef) New() MapOfSizeToString {
func (def MapOfSizeToStringDef) New(cs chunks.ChunkStore) MapOfSizeToString {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, k.New(), types.NewString(v))
kv = append(kv, k.New(cs), types.NewString(v))
}
return MapOfSizeToString{types.NewTypedMap(__typeForMapOfSizeToString, kv...), &ref.Ref{}}
return MapOfSizeToString{types.NewTypedMap(cs, __typeForMapOfSizeToString, kv...), cs, &ref.Ref{}}
}
func (m MapOfSizeToString) Def() MapOfSizeToStringDef {
@@ -387,8 +395,8 @@ func init() {
types.RegisterValue(__typeForMapOfSizeToString, builderForMapOfSizeToString, readerForMapOfSizeToString)
}
func builderForMapOfSizeToString(v types.Value) types.Value {
return MapOfSizeToString{v.(types.Map), &ref.Ref{}}
func builderForMapOfSizeToString(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfSizeToString{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfSizeToString(v types.Value) types.Value {
@@ -420,13 +428,13 @@ func (m MapOfSizeToString) MaybeGet(p Size) (string, bool) {
}
func (m MapOfSizeToString) Set(k Size, v string) MapOfSizeToString {
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), &ref.Ref{}}
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
return MapOfSizeToString{m.m.Remove(p), &ref.Ref{}}
return MapOfSizeToString{m.m.Remove(p), m.cs, &ref.Ref{}}
}
type MapOfSizeToStringIterCallback func(k Size, v string) (stop bool)
@@ -457,30 +465,31 @@ func (m MapOfSizeToString) Filter(cb MapOfSizeToStringFilterCallback) MapOfSizeT
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(Size), v.(types.String).String())
})
return MapOfSizeToString{out, &ref.Ref{}}
return MapOfSizeToString{out, m.cs, &ref.Ref{}}
}
// SetOfString
type SetOfString struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfString() SetOfString {
return SetOfString{types.NewTypedSet(__typeForSetOfString), &ref.Ref{}}
func NewSetOfString(cs chunks.ChunkStore) SetOfString {
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString), cs, &ref.Ref{}}
}
type SetOfStringDef map[string]bool
func (def SetOfStringDef) New() SetOfString {
func (def SetOfStringDef) New(cs chunks.ChunkStore) SetOfString {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = types.NewString(d)
i++
}
return SetOfString{types.NewTypedSet(__typeForSetOfString, l...), &ref.Ref{}}
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString, l...), cs, &ref.Ref{}}
}
func (s SetOfString) Def() SetOfStringDef {
@@ -522,8 +531,8 @@ func init() {
types.RegisterValue(__typeForSetOfString, builderForSetOfString, readerForSetOfString)
}
func builderForSetOfString(v types.Value) types.Value {
return SetOfString{v.(types.Set), &ref.Ref{}}
func builderForSetOfString(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfString{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfString(v types.Value) types.Value {
@@ -570,23 +579,23 @@ func (s SetOfString) Filter(cb SetOfStringFilterCallback) SetOfString {
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(types.String).String())
})
return SetOfString{out, &ref.Ref{}}
return SetOfString{out, s.cs, &ref.Ref{}}
}
func (s SetOfString) Insert(p ...string) SetOfString {
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Remove(p ...string) SetOfString {
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Union(others ...SetOfString) SetOfString {
return SetOfString{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Subtract(others ...SetOfString) SetOfString {
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Any() string {

View File

@@ -3,6 +3,7 @@
package main
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -38,14 +39,16 @@ type Geoposition struct {
_Latitude float32
_Longitude float32
cs chunks.ChunkStore
ref *ref.Ref
}
func NewGeoposition() Geoposition {
func NewGeoposition(cs chunks.ChunkStore) Geoposition {
return Geoposition{
_Latitude: float32(0),
_Longitude: float32(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -55,10 +58,11 @@ type GeopositionDef struct {
Longitude float32
}
func (def GeopositionDef) New() Geoposition {
func (def GeopositionDef) New(cs chunks.ChunkStore) Geoposition {
return Geoposition{
_Latitude: def.Latitude,
_Longitude: def.Longitude,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -80,9 +84,9 @@ func init() {
types.RegisterStruct(__typeForGeoposition, builderForGeoposition, readerForGeoposition)
}
func builderForGeoposition(values []types.Value) types.Value {
func builderForGeoposition(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Geoposition{ref: &ref.Ref{}}
s := Geoposition{ref: &ref.Ref{}, cs: cs}
s._Latitude = float32(values[i].(types.Float32))
i++
s._Longitude = float32(values[i].(types.Float32))
@@ -143,14 +147,16 @@ type Georectangle struct {
_TopLeft Geoposition
_BottomRight Geoposition
cs chunks.ChunkStore
ref *ref.Ref
}
func NewGeorectangle() Georectangle {
func NewGeorectangle(cs chunks.ChunkStore) Georectangle {
return Georectangle{
_TopLeft: NewGeoposition(),
_BottomRight: NewGeoposition(),
_TopLeft: NewGeoposition(cs),
_BottomRight: NewGeoposition(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -160,10 +166,11 @@ type GeorectangleDef struct {
BottomRight GeopositionDef
}
func (def GeorectangleDef) New() Georectangle {
func (def GeorectangleDef) New(cs chunks.ChunkStore) Georectangle {
return Georectangle{
_TopLeft: def.TopLeft.New(),
_BottomRight: def.BottomRight.New(),
_TopLeft: def.TopLeft.New(cs),
_BottomRight: def.BottomRight.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -185,9 +192,9 @@ func init() {
types.RegisterStruct(__typeForGeorectangle, builderForGeorectangle, readerForGeorectangle)
}
func builderForGeorectangle(values []types.Value) types.Value {
func builderForGeorectangle(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Georectangle{ref: &ref.Ref{}}
s := Georectangle{ref: &ref.Ref{}, cs: cs}
s._TopLeft = values[i].(Geoposition)
i++
s._BottomRight = values[i].(Geoposition)

View File

@@ -138,10 +138,10 @@ func getIndex(input ListOfRefOfMapOfStringToValue, cs chunks.ChunkStore) MapOfSt
namedPitchCounts := MapOfStringToRefOfListOfPitchDef{}
for id, p := range pitchCounts {
if name, ok := pitchers[id]; d.Chk.True(ok, "Unknown pitcher: %s", id) {
namedPitchCounts[name] = types.WriteValue(p.New(), cs)
namedPitchCounts[name] = types.WriteValue(p.New(cs), cs)
}
}
return namedPitchCounts.New()
return namedPitchCounts.New(cs)
}
func main() {

View File

@@ -32,14 +32,16 @@ type Pitch struct {
_X float64
_Z float64
cs chunks.ChunkStore
ref *ref.Ref
}
func NewPitch() Pitch {
func NewPitch(cs chunks.ChunkStore) Pitch {
return Pitch{
_X: float64(0),
_Z: float64(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -49,10 +51,11 @@ type PitchDef struct {
Z float64
}
func (def PitchDef) New() Pitch {
func (def PitchDef) New(cs chunks.ChunkStore) Pitch {
return Pitch{
_X: def.X,
_Z: def.Z,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -74,9 +77,9 @@ func init() {
types.RegisterStruct(__typeForPitch, builderForPitch, readerForPitch)
}
func builderForPitch(values []types.Value) types.Value {
func builderForPitch(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Pitch{ref: &ref.Ref{}}
s := Pitch{ref: &ref.Ref{}, cs: cs}
s._X = float64(values[i].(types.Float64))
i++
s._Z = float64(values[i].(types.Float64))
@@ -135,21 +138,22 @@ func (s Pitch) SetZ(val float64) Pitch {
type MapOfStringToRefOfListOfPitch struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToRefOfListOfPitch() MapOfStringToRefOfListOfPitch {
return MapOfStringToRefOfListOfPitch{types.NewTypedMap(__typeForMapOfStringToRefOfListOfPitch), &ref.Ref{}}
func NewMapOfStringToRefOfListOfPitch(cs chunks.ChunkStore) MapOfStringToRefOfListOfPitch {
return MapOfStringToRefOfListOfPitch{types.NewTypedMap(cs, __typeForMapOfStringToRefOfListOfPitch), cs, &ref.Ref{}}
}
type MapOfStringToRefOfListOfPitchDef map[string]ref.Ref
func (def MapOfStringToRefOfListOfPitchDef) New() MapOfStringToRefOfListOfPitch {
func (def MapOfStringToRefOfListOfPitchDef) New(cs chunks.ChunkStore) MapOfStringToRefOfListOfPitch {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), NewRefOfListOfPitch(v))
}
return MapOfStringToRefOfListOfPitch{types.NewTypedMap(__typeForMapOfStringToRefOfListOfPitch, kv...), &ref.Ref{}}
return MapOfStringToRefOfListOfPitch{types.NewTypedMap(cs, __typeForMapOfStringToRefOfListOfPitch, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToRefOfListOfPitch) Def() MapOfStringToRefOfListOfPitchDef {
@@ -191,8 +195,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToRefOfListOfPitch, builderForMapOfStringToRefOfListOfPitch, readerForMapOfStringToRefOfListOfPitch)
}
func builderForMapOfStringToRefOfListOfPitch(v types.Value) types.Value {
return MapOfStringToRefOfListOfPitch{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToRefOfListOfPitch(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToRefOfListOfPitch{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToRefOfListOfPitch(v types.Value) types.Value {
@@ -224,13 +228,13 @@ func (m MapOfStringToRefOfListOfPitch) MaybeGet(p string) (RefOfListOfPitch, boo
}
func (m MapOfStringToRefOfListOfPitch) Set(k string, v RefOfListOfPitch) MapOfStringToRefOfListOfPitch {
return MapOfStringToRefOfListOfPitch{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToRefOfListOfPitch{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToRefOfListOfPitch) Remove(p string) MapOfStringToRefOfListOfPitch {
return MapOfStringToRefOfListOfPitch{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToRefOfListOfPitch{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToRefOfListOfPitchIterCallback func(k string, v RefOfListOfPitch) (stop bool)
@@ -261,28 +265,29 @@ func (m MapOfStringToRefOfListOfPitch) Filter(cb MapOfStringToRefOfListOfPitchFi
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(RefOfListOfPitch))
})
return MapOfStringToRefOfListOfPitch{out, &ref.Ref{}}
return MapOfStringToRefOfListOfPitch{out, m.cs, &ref.Ref{}}
}
// ListOfRefOfMapOfStringToValue
type ListOfRefOfMapOfStringToValue struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfRefOfMapOfStringToValue() ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{types.NewTypedList(__typeForListOfRefOfMapOfStringToValue), &ref.Ref{}}
func NewListOfRefOfMapOfStringToValue(cs chunks.ChunkStore) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{types.NewTypedList(cs, __typeForListOfRefOfMapOfStringToValue), cs, &ref.Ref{}}
}
type ListOfRefOfMapOfStringToValueDef []ref.Ref
func (def ListOfRefOfMapOfStringToValueDef) New() ListOfRefOfMapOfStringToValue {
func (def ListOfRefOfMapOfStringToValueDef) New(cs chunks.ChunkStore) ListOfRefOfMapOfStringToValue {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = NewRefOfMapOfStringToValue(d)
}
return ListOfRefOfMapOfStringToValue{types.NewTypedList(__typeForListOfRefOfMapOfStringToValue, l...), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{types.NewTypedList(cs, __typeForListOfRefOfMapOfStringToValue, l...), cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) Def() ListOfRefOfMapOfStringToValueDef {
@@ -323,8 +328,8 @@ func init() {
types.RegisterValue(__typeForListOfRefOfMapOfStringToValue, builderForListOfRefOfMapOfStringToValue, readerForListOfRefOfMapOfStringToValue)
}
func builderForListOfRefOfMapOfStringToValue(v types.Value) types.Value {
return ListOfRefOfMapOfStringToValue{v.(types.List), &ref.Ref{}}
func builderForListOfRefOfMapOfStringToValue(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfRefOfMapOfStringToValue{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfRefOfMapOfStringToValue(v types.Value) types.Value {
@@ -344,27 +349,27 @@ func (l ListOfRefOfMapOfStringToValue) Get(i uint64) RefOfMapOfStringToValue {
}
func (l ListOfRefOfMapOfStringToValue) Slice(idx uint64, end uint64) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) Set(i uint64, val RefOfMapOfStringToValue) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{l.l.Set(i, val), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) Append(v ...RefOfMapOfStringToValue) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) Insert(idx uint64, v ...RefOfMapOfStringToValue) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) Remove(idx uint64, end uint64) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) RemoveAt(idx uint64) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) fromElemSlice(p []RefOfMapOfStringToValue) []types.Value {
@@ -403,7 +408,7 @@ func (l ListOfRefOfMapOfStringToValue) Filter(cb ListOfRefOfMapOfStringToValueFi
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(RefOfMapOfStringToValue), i)
})
return ListOfRefOfMapOfStringToValue{out, &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{out, l.cs, &ref.Ref{}}
}
// RefOfMapOfStringToValue
@@ -455,7 +460,7 @@ func builderForRefOfMapOfStringToValue(r ref.Ref) types.Value {
return NewRefOfMapOfStringToValue(r)
}
func (r RefOfMapOfStringToValue) TargetValue(cs chunks.ChunkSource) MapOfStringToValue {
func (r RefOfMapOfStringToValue) TargetValue(cs chunks.ChunkStore) MapOfStringToValue {
return types.ReadValue(r.target, cs).(MapOfStringToValue)
}
@@ -467,21 +472,22 @@ func (r RefOfMapOfStringToValue) SetTargetValue(val MapOfStringToValue, cs chunk
type MapOfStringToValue struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToValue() MapOfStringToValue {
return MapOfStringToValue{types.NewTypedMap(__typeForMapOfStringToValue), &ref.Ref{}}
func NewMapOfStringToValue(cs chunks.ChunkStore) MapOfStringToValue {
return MapOfStringToValue{types.NewTypedMap(cs, __typeForMapOfStringToValue), cs, &ref.Ref{}}
}
type MapOfStringToValueDef map[string]types.Value
func (def MapOfStringToValueDef) New() MapOfStringToValue {
func (def MapOfStringToValueDef) New(cs chunks.ChunkStore) MapOfStringToValue {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), v)
}
return MapOfStringToValue{types.NewTypedMap(__typeForMapOfStringToValue, kv...), &ref.Ref{}}
return MapOfStringToValue{types.NewTypedMap(cs, __typeForMapOfStringToValue, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToValue) Def() MapOfStringToValueDef {
@@ -523,8 +529,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToValue, builderForMapOfStringToValue, readerForMapOfStringToValue)
}
func builderForMapOfStringToValue(v types.Value) types.Value {
return MapOfStringToValue{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToValue(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToValue{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToValue(v types.Value) types.Value {
@@ -556,13 +562,13 @@ func (m MapOfStringToValue) MaybeGet(p string) (types.Value, bool) {
}
func (m MapOfStringToValue) Set(k string, v types.Value) MapOfStringToValue {
return MapOfStringToValue{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToValue{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToValue) Remove(p string) MapOfStringToValue {
return MapOfStringToValue{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToValue{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToValueIterCallback func(k string, v types.Value) (stop bool)
@@ -593,28 +599,29 @@ func (m MapOfStringToValue) Filter(cb MapOfStringToValueFilterCallback) MapOfStr
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v)
})
return MapOfStringToValue{out, &ref.Ref{}}
return MapOfStringToValue{out, m.cs, &ref.Ref{}}
}
// ListOfPitch
type ListOfPitch struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfPitch() ListOfPitch {
return ListOfPitch{types.NewTypedList(__typeForListOfPitch), &ref.Ref{}}
func NewListOfPitch(cs chunks.ChunkStore) ListOfPitch {
return ListOfPitch{types.NewTypedList(cs, __typeForListOfPitch), cs, &ref.Ref{}}
}
type ListOfPitchDef []PitchDef
func (def ListOfPitchDef) New() ListOfPitch {
func (def ListOfPitchDef) New(cs chunks.ChunkStore) ListOfPitch {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = d.New()
l[i] = d.New(cs)
}
return ListOfPitch{types.NewTypedList(__typeForListOfPitch, l...), &ref.Ref{}}
return ListOfPitch{types.NewTypedList(cs, __typeForListOfPitch, l...), cs, &ref.Ref{}}
}
func (l ListOfPitch) Def() ListOfPitchDef {
@@ -655,8 +662,8 @@ func init() {
types.RegisterValue(__typeForListOfPitch, builderForListOfPitch, readerForListOfPitch)
}
func builderForListOfPitch(v types.Value) types.Value {
return ListOfPitch{v.(types.List), &ref.Ref{}}
func builderForListOfPitch(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfPitch{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfPitch(v types.Value) types.Value {
@@ -676,27 +683,27 @@ func (l ListOfPitch) Get(i uint64) Pitch {
}
func (l ListOfPitch) Slice(idx uint64, end uint64) ListOfPitch {
return ListOfPitch{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfPitch{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfPitch) Set(i uint64, val Pitch) ListOfPitch {
return ListOfPitch{l.l.Set(i, val), &ref.Ref{}}
return ListOfPitch{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfPitch) Append(v ...Pitch) ListOfPitch {
return ListOfPitch{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfPitch{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfPitch) Insert(idx uint64, v ...Pitch) ListOfPitch {
return ListOfPitch{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfPitch{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfPitch) Remove(idx uint64, end uint64) ListOfPitch {
return ListOfPitch{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfPitch{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfPitch) RemoveAt(idx uint64) ListOfPitch {
return ListOfPitch{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfPitch{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfPitch) fromElemSlice(p []Pitch) []types.Value {
@@ -735,7 +742,7 @@ func (l ListOfPitch) Filter(cb ListOfPitchFilterCallback) ListOfPitch {
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(Pitch), i)
})
return ListOfPitch{out, &ref.Ref{}}
return ListOfPitch{out, l.cs, &ref.Ref{}}
}
// RefOfListOfPitch
@@ -787,7 +794,7 @@ func builderForRefOfListOfPitch(r ref.Ref) types.Value {
return NewRefOfListOfPitch(r)
}
func (r RefOfListOfPitch) TargetValue(cs chunks.ChunkSource) ListOfPitch {
func (r RefOfListOfPitch) TargetValue(cs chunks.ChunkStore) ListOfPitch {
return types.ReadValue(r.target, cs).(ListOfPitch)
}

View File

@@ -19,11 +19,10 @@ import (
)
var (
datasFlags = datas.NewFlags()
inputRefStr = flag.String("input-ref", "", "ref to list containing nodes")
outputDs = flag.String("output-ds", "", "dataset to store data in.")
quietFlag = flag.Bool("quiet", false, "suppress printing of progress statements")
geopositionType = common.NewGeoposition().Type()
datasFlags = datas.NewFlags()
inputRefStr = flag.String("input-ref", "", "ref to list containing nodes")
outputDs = flag.String("output-ds", "", "dataset to store data in.")
quietFlag = flag.Bool("quiet", false, "suppress printing of progress statements")
)
func main() {

View File

@@ -149,7 +149,7 @@ func main() {
close(iChan)
refWg.Wait()
incidentRefs := types.NewList(refs...)
incidentRefs := types.NewList(ds.Store(), refs...)
if !*quietFlag {
fmt.Printf("Converting refs list to noms list: %.2f secs\n", time.Now().Sub(start).Seconds())
}
@@ -166,7 +166,7 @@ func main() {
fmt.Printf("Ref of list containing Incidents: %s, , elaspsed time: %.2f secs\n", incidentRefs.Ref(), time.Now().Sub(start).Seconds())
}
func getNomsWriter(cs chunks.ChunkSink) (iChan chan incidentWithIndex, rChan chan refIndex) {
func getNomsWriter(cs chunks.ChunkStore) (iChan chan incidentWithIndex, rChan chan refIndex) {
iChan = make(chan incidentWithIndex, 3000)
rChan = make(chan refIndex, 3000)
var wg sync.WaitGroup
@@ -174,7 +174,7 @@ func getNomsWriter(cs chunks.ChunkSink) (iChan chan incidentWithIndex, rChan cha
wg.Add(1)
go func() {
for incidentRecord := range iChan {
v := incidentRecord.incident.New()
v := incidentRecord.incident.New(cs)
r := types.WriteValue(v, cs)
rChan <- refIndex{types.NewRef(r), incidentRecord.index}
}

View File

@@ -3,6 +3,7 @@
package main
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -48,18 +49,20 @@ type RemotePhoto struct {
_Sizes MapOfSizeToString
_Tags SetOfString
cs chunks.ChunkStore
ref *ref.Ref
}
func NewRemotePhoto() RemotePhoto {
func NewRemotePhoto(cs chunks.ChunkStore) RemotePhoto {
return RemotePhoto{
_Id: "",
_Title: "",
_Url: "",
_Geoposition: NewGeoposition(),
_Sizes: NewMapOfSizeToString(),
_Tags: NewSetOfString(),
_Geoposition: NewGeoposition(cs),
_Sizes: NewMapOfSizeToString(cs),
_Tags: NewSetOfString(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -73,14 +76,15 @@ type RemotePhotoDef struct {
Tags SetOfStringDef
}
func (def RemotePhotoDef) New() RemotePhoto {
func (def RemotePhotoDef) New(cs chunks.ChunkStore) RemotePhoto {
return RemotePhoto{
_Id: def.Id,
_Title: def.Title,
_Url: def.Url,
_Geoposition: def.Geoposition.New(),
_Sizes: def.Sizes.New(),
_Tags: def.Tags.New(),
_Geoposition: def.Geoposition.New(cs),
_Sizes: def.Sizes.New(cs),
_Tags: def.Tags.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -106,9 +110,9 @@ func init() {
types.RegisterStruct(__typeForRemotePhoto, builderForRemotePhoto, readerForRemotePhoto)
}
func builderForRemotePhoto(values []types.Value) types.Value {
func builderForRemotePhoto(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := RemotePhoto{ref: &ref.Ref{}}
s := RemotePhoto{ref: &ref.Ref{}, cs: cs}
s._Id = values[i].(types.String).String()
i++
s._Title = values[i].(types.String).String()
@@ -228,14 +232,16 @@ type Size struct {
_Width uint32
_Height uint32
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSize() Size {
func NewSize(cs chunks.ChunkStore) Size {
return Size{
_Width: uint32(0),
_Height: uint32(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -245,10 +251,11 @@ type SizeDef struct {
Height uint32
}
func (def SizeDef) New() Size {
func (def SizeDef) New(cs chunks.ChunkStore) Size {
return Size{
_Width: def.Width,
_Height: def.Height,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -270,9 +277,9 @@ func init() {
types.RegisterStruct(__typeForSize, builderForSize, readerForSize)
}
func builderForSize(values []types.Value) types.Value {
func builderForSize(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Size{ref: &ref.Ref{}}
s := Size{ref: &ref.Ref{}, cs: cs}
s._Width = uint32(values[i].(types.UInt32))
i++
s._Height = uint32(values[i].(types.UInt32))
@@ -331,21 +338,22 @@ func (s Size) SetHeight(val uint32) Size {
type MapOfSizeToString struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfSizeToString() MapOfSizeToString {
return MapOfSizeToString{types.NewTypedMap(__typeForMapOfSizeToString), &ref.Ref{}}
func NewMapOfSizeToString(cs chunks.ChunkStore) MapOfSizeToString {
return MapOfSizeToString{types.NewTypedMap(cs, __typeForMapOfSizeToString), cs, &ref.Ref{}}
}
type MapOfSizeToStringDef map[SizeDef]string
func (def MapOfSizeToStringDef) New() MapOfSizeToString {
func (def MapOfSizeToStringDef) New(cs chunks.ChunkStore) MapOfSizeToString {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, k.New(), types.NewString(v))
kv = append(kv, k.New(cs), types.NewString(v))
}
return MapOfSizeToString{types.NewTypedMap(__typeForMapOfSizeToString, kv...), &ref.Ref{}}
return MapOfSizeToString{types.NewTypedMap(cs, __typeForMapOfSizeToString, kv...), cs, &ref.Ref{}}
}
func (m MapOfSizeToString) Def() MapOfSizeToStringDef {
@@ -387,8 +395,8 @@ func init() {
types.RegisterValue(__typeForMapOfSizeToString, builderForMapOfSizeToString, readerForMapOfSizeToString)
}
func builderForMapOfSizeToString(v types.Value) types.Value {
return MapOfSizeToString{v.(types.Map), &ref.Ref{}}
func builderForMapOfSizeToString(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfSizeToString{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfSizeToString(v types.Value) types.Value {
@@ -420,13 +428,13 @@ func (m MapOfSizeToString) MaybeGet(p Size) (string, bool) {
}
func (m MapOfSizeToString) Set(k Size, v string) MapOfSizeToString {
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), &ref.Ref{}}
return MapOfSizeToString{m.m.Set(k, types.NewString(v)), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfSizeToString) Remove(p Size) MapOfSizeToString {
return MapOfSizeToString{m.m.Remove(p), &ref.Ref{}}
return MapOfSizeToString{m.m.Remove(p), m.cs, &ref.Ref{}}
}
type MapOfSizeToStringIterCallback func(k Size, v string) (stop bool)
@@ -457,30 +465,31 @@ func (m MapOfSizeToString) Filter(cb MapOfSizeToStringFilterCallback) MapOfSizeT
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(Size), v.(types.String).String())
})
return MapOfSizeToString{out, &ref.Ref{}}
return MapOfSizeToString{out, m.cs, &ref.Ref{}}
}
// SetOfString
type SetOfString struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfString() SetOfString {
return SetOfString{types.NewTypedSet(__typeForSetOfString), &ref.Ref{}}
func NewSetOfString(cs chunks.ChunkStore) SetOfString {
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString), cs, &ref.Ref{}}
}
type SetOfStringDef map[string]bool
func (def SetOfStringDef) New() SetOfString {
func (def SetOfStringDef) New(cs chunks.ChunkStore) SetOfString {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = types.NewString(d)
i++
}
return SetOfString{types.NewTypedSet(__typeForSetOfString, l...), &ref.Ref{}}
return SetOfString{types.NewTypedSet(cs, __typeForSetOfString, l...), cs, &ref.Ref{}}
}
func (s SetOfString) Def() SetOfStringDef {
@@ -522,8 +531,8 @@ func init() {
types.RegisterValue(__typeForSetOfString, builderForSetOfString, readerForSetOfString)
}
func builderForSetOfString(v types.Value) types.Value {
return SetOfString{v.(types.Set), &ref.Ref{}}
func builderForSetOfString(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfString{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfString(v types.Value) types.Value {
@@ -570,23 +579,23 @@ func (s SetOfString) Filter(cb SetOfStringFilterCallback) SetOfString {
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(types.String).String())
})
return SetOfString{out, &ref.Ref{}}
return SetOfString{out, s.cs, &ref.Ref{}}
}
func (s SetOfString) Insert(p ...string) SetOfString {
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Remove(p ...string) SetOfString {
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfString{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Union(others ...SetOfString) SetOfString {
return SetOfString{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Subtract(others ...SetOfString) SetOfString {
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfString{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfString) Any() string {

View File

@@ -3,6 +3,7 @@
package main
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -38,14 +39,16 @@ type Geoposition struct {
_Latitude float32
_Longitude float32
cs chunks.ChunkStore
ref *ref.Ref
}
func NewGeoposition() Geoposition {
func NewGeoposition(cs chunks.ChunkStore) Geoposition {
return Geoposition{
_Latitude: float32(0),
_Longitude: float32(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -55,10 +58,11 @@ type GeopositionDef struct {
Longitude float32
}
func (def GeopositionDef) New() Geoposition {
func (def GeopositionDef) New(cs chunks.ChunkStore) Geoposition {
return Geoposition{
_Latitude: def.Latitude,
_Longitude: def.Longitude,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -80,9 +84,9 @@ func init() {
types.RegisterStruct(__typeForGeoposition, builderForGeoposition, readerForGeoposition)
}
func builderForGeoposition(values []types.Value) types.Value {
func builderForGeoposition(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Geoposition{ref: &ref.Ref{}}
s := Geoposition{ref: &ref.Ref{}, cs: cs}
s._Latitude = float32(values[i].(types.Float32))
i++
s._Longitude = float32(values[i].(types.Float32))
@@ -143,14 +147,16 @@ type Georectangle struct {
_TopLeft Geoposition
_BottomRight Geoposition
cs chunks.ChunkStore
ref *ref.Ref
}
func NewGeorectangle() Georectangle {
func NewGeorectangle(cs chunks.ChunkStore) Georectangle {
return Georectangle{
_TopLeft: NewGeoposition(),
_BottomRight: NewGeoposition(),
_TopLeft: NewGeoposition(cs),
_BottomRight: NewGeoposition(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -160,10 +166,11 @@ type GeorectangleDef struct {
BottomRight GeopositionDef
}
func (def GeorectangleDef) New() Georectangle {
func (def GeorectangleDef) New(cs chunks.ChunkStore) Georectangle {
return Georectangle{
_TopLeft: def.TopLeft.New(),
_BottomRight: def.BottomRight.New(),
_TopLeft: def.TopLeft.New(cs),
_BottomRight: def.BottomRight.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -185,9 +192,9 @@ func init() {
types.RegisterStruct(__typeForGeorectangle, builderForGeorectangle, readerForGeorectangle)
}
func builderForGeorectangle(values []types.Value) types.Value {
func builderForGeorectangle(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Georectangle{ref: &ref.Ref{}}
s := Georectangle{ref: &ref.Ref{}, cs: cs}
s._TopLeft = values[i].(Geoposition)
i++
s._BottomRight = values[i].(Geoposition)

View File

@@ -49,7 +49,7 @@ func main() {
}
outputDS := dataset.NewDataset(store, *outputID)
out := NewMapOfStringToSetOfRefOfRemotePhoto()
out := NewMapOfStringToSetOfRefOfRemotePhoto(store)
t0 := time.Now()
numValues := 0

View File

@@ -20,7 +20,7 @@ type testSuite struct {
util.ClientTestSuite
}
func createRefOfRemotePhoto(id int, tag string, cs chunks.ChunkSink) RefOfRemotePhoto {
func createRefOfRemotePhoto(id int, tag string, cs chunks.ChunkStore) RefOfRemotePhoto {
p := RemotePhotoDef{
Id: fmt.Sprintf("%d", id),
Title: "title" + tag,
@@ -28,7 +28,7 @@ func createRefOfRemotePhoto(id int, tag string, cs chunks.ChunkSink) RefOfRemote
Geoposition: GeopositionDef{Latitude: 50, Longitude: 50},
Sizes: MapOfSizeToStringDef{SizeDef{1, 2}: "1x2"},
Tags: map[string]bool{tag: true},
}.New()
}.New(cs)
return NewRefOfRemotePhoto(types.WriteValue(p, cs))
}
@@ -37,7 +37,7 @@ func (s *testSuite) TestTagdex() {
inputDs := dataset.NewDataset(datas.NewDataStore(cs), "input-test")
// Build the set
set := NewSetOfRefOfRemotePhoto().Insert(
set := NewSetOfRefOfRemotePhoto(cs).Insert(
createRefOfRemotePhoto(0, "nyc", cs),
createRefOfRemotePhoto(1, "sf", cs),
createRefOfRemotePhoto(2, "cat", cs),

View File

@@ -12,21 +12,22 @@ import (
type MapOfStringToSetOfRefOfRemotePhoto struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToSetOfRefOfRemotePhoto() MapOfStringToSetOfRefOfRemotePhoto {
return MapOfStringToSetOfRefOfRemotePhoto{types.NewTypedMap(__typeForMapOfStringToSetOfRefOfRemotePhoto), &ref.Ref{}}
func NewMapOfStringToSetOfRefOfRemotePhoto(cs chunks.ChunkStore) MapOfStringToSetOfRefOfRemotePhoto {
return MapOfStringToSetOfRefOfRemotePhoto{types.NewTypedMap(cs, __typeForMapOfStringToSetOfRefOfRemotePhoto), cs, &ref.Ref{}}
}
type MapOfStringToSetOfRefOfRemotePhotoDef map[string]SetOfRefOfRemotePhotoDef
func (def MapOfStringToSetOfRefOfRemotePhotoDef) New() MapOfStringToSetOfRefOfRemotePhoto {
func (def MapOfStringToSetOfRefOfRemotePhotoDef) New(cs chunks.ChunkStore) MapOfStringToSetOfRefOfRemotePhoto {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), v.New())
kv = append(kv, types.NewString(k), v.New(cs))
}
return MapOfStringToSetOfRefOfRemotePhoto{types.NewTypedMap(__typeForMapOfStringToSetOfRefOfRemotePhoto, kv...), &ref.Ref{}}
return MapOfStringToSetOfRefOfRemotePhoto{types.NewTypedMap(cs, __typeForMapOfStringToSetOfRefOfRemotePhoto, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Def() MapOfStringToSetOfRefOfRemotePhotoDef {
@@ -68,8 +69,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToSetOfRefOfRemotePhoto, builderForMapOfStringToSetOfRefOfRemotePhoto, readerForMapOfStringToSetOfRefOfRemotePhoto)
}
func builderForMapOfStringToSetOfRefOfRemotePhoto(v types.Value) types.Value {
return MapOfStringToSetOfRefOfRemotePhoto{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToSetOfRefOfRemotePhoto(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToSetOfRefOfRemotePhoto{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToSetOfRefOfRemotePhoto(v types.Value) types.Value {
@@ -95,19 +96,19 @@ func (m MapOfStringToSetOfRefOfRemotePhoto) Get(p string) SetOfRefOfRemotePhoto
func (m MapOfStringToSetOfRefOfRemotePhoto) MaybeGet(p string) (SetOfRefOfRemotePhoto, bool) {
v, ok := m.m.MaybeGet(types.NewString(p))
if !ok {
return NewSetOfRefOfRemotePhoto(), false
return NewSetOfRefOfRemotePhoto(m.cs), false
}
return v.(SetOfRefOfRemotePhoto), ok
}
func (m MapOfStringToSetOfRefOfRemotePhoto) Set(k string, v SetOfRefOfRemotePhoto) MapOfStringToSetOfRefOfRemotePhoto {
return MapOfStringToSetOfRefOfRemotePhoto{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToSetOfRefOfRemotePhoto{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToSetOfRefOfRemotePhoto) Remove(p string) MapOfStringToSetOfRefOfRemotePhoto {
return MapOfStringToSetOfRefOfRemotePhoto{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToSetOfRefOfRemotePhoto{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToSetOfRefOfRemotePhotoIterCallback func(k string, v SetOfRefOfRemotePhoto) (stop bool)
@@ -138,30 +139,31 @@ func (m MapOfStringToSetOfRefOfRemotePhoto) Filter(cb MapOfStringToSetOfRefOfRem
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(SetOfRefOfRemotePhoto))
})
return MapOfStringToSetOfRefOfRemotePhoto{out, &ref.Ref{}}
return MapOfStringToSetOfRefOfRemotePhoto{out, m.cs, &ref.Ref{}}
}
// SetOfRefOfRemotePhoto
type SetOfRefOfRemotePhoto struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfRefOfRemotePhoto() SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{types.NewTypedSet(__typeForSetOfRefOfRemotePhoto), &ref.Ref{}}
func NewSetOfRefOfRemotePhoto(cs chunks.ChunkStore) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{types.NewTypedSet(cs, __typeForSetOfRefOfRemotePhoto), cs, &ref.Ref{}}
}
type SetOfRefOfRemotePhotoDef map[ref.Ref]bool
func (def SetOfRefOfRemotePhotoDef) New() SetOfRefOfRemotePhoto {
func (def SetOfRefOfRemotePhotoDef) New(cs chunks.ChunkStore) SetOfRefOfRemotePhoto {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = NewRefOfRemotePhoto(d)
i++
}
return SetOfRefOfRemotePhoto{types.NewTypedSet(__typeForSetOfRefOfRemotePhoto, l...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{types.NewTypedSet(cs, __typeForSetOfRefOfRemotePhoto, l...), cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Def() SetOfRefOfRemotePhotoDef {
@@ -203,8 +205,8 @@ func init() {
types.RegisterValue(__typeForSetOfRefOfRemotePhoto, builderForSetOfRefOfRemotePhoto, readerForSetOfRefOfRemotePhoto)
}
func builderForSetOfRefOfRemotePhoto(v types.Value) types.Value {
return SetOfRefOfRemotePhoto{v.(types.Set), &ref.Ref{}}
func builderForSetOfRefOfRemotePhoto(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfRefOfRemotePhoto{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfRefOfRemotePhoto(v types.Value) types.Value {
@@ -251,23 +253,23 @@ func (s SetOfRefOfRemotePhoto) Filter(cb SetOfRefOfRemotePhotoFilterCallback) Se
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(RefOfRemotePhoto))
})
return SetOfRefOfRemotePhoto{out, &ref.Ref{}}
return SetOfRefOfRemotePhoto{out, s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Insert(p ...RefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Remove(p ...RefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Union(others ...SetOfRefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Subtract(others ...SetOfRefOfRemotePhoto) SetOfRefOfRemotePhoto {
return SetOfRefOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfRemotePhoto{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfRemotePhoto) Any() RefOfRemotePhoto {
@@ -339,7 +341,7 @@ func builderForRefOfRemotePhoto(r ref.Ref) types.Value {
return NewRefOfRemotePhoto(r)
}
func (r RefOfRemotePhoto) TargetValue(cs chunks.ChunkSource) RemotePhoto {
func (r RefOfRemotePhoto) TargetValue(cs chunks.ChunkStore) RemotePhoto {
return types.ReadValue(r.target, cs).(RemotePhoto)
}

View File

@@ -12,21 +12,22 @@ import (
type ListOfRefOfMapOfStringToValue struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfRefOfMapOfStringToValue() ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{types.NewTypedList(__typeForListOfRefOfMapOfStringToValue), &ref.Ref{}}
func NewListOfRefOfMapOfStringToValue(cs chunks.ChunkStore) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{types.NewTypedList(cs, __typeForListOfRefOfMapOfStringToValue), cs, &ref.Ref{}}
}
type ListOfRefOfMapOfStringToValueDef []ref.Ref
func (def ListOfRefOfMapOfStringToValueDef) New() ListOfRefOfMapOfStringToValue {
func (def ListOfRefOfMapOfStringToValueDef) New(cs chunks.ChunkStore) ListOfRefOfMapOfStringToValue {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = NewRefOfMapOfStringToValue(d)
}
return ListOfRefOfMapOfStringToValue{types.NewTypedList(__typeForListOfRefOfMapOfStringToValue, l...), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{types.NewTypedList(cs, __typeForListOfRefOfMapOfStringToValue, l...), cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) Def() ListOfRefOfMapOfStringToValueDef {
@@ -67,8 +68,8 @@ func init() {
types.RegisterValue(__typeForListOfRefOfMapOfStringToValue, builderForListOfRefOfMapOfStringToValue, readerForListOfRefOfMapOfStringToValue)
}
func builderForListOfRefOfMapOfStringToValue(v types.Value) types.Value {
return ListOfRefOfMapOfStringToValue{v.(types.List), &ref.Ref{}}
func builderForListOfRefOfMapOfStringToValue(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfRefOfMapOfStringToValue{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfRefOfMapOfStringToValue(v types.Value) types.Value {
@@ -88,27 +89,27 @@ func (l ListOfRefOfMapOfStringToValue) Get(i uint64) RefOfMapOfStringToValue {
}
func (l ListOfRefOfMapOfStringToValue) Slice(idx uint64, end uint64) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) Set(i uint64, val RefOfMapOfStringToValue) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{l.l.Set(i, val), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) Append(v ...RefOfMapOfStringToValue) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) Insert(idx uint64, v ...RefOfMapOfStringToValue) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) Remove(idx uint64, end uint64) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) RemoveAt(idx uint64) ListOfRefOfMapOfStringToValue {
return ListOfRefOfMapOfStringToValue{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfMapOfStringToValue) fromElemSlice(p []RefOfMapOfStringToValue) []types.Value {
@@ -147,7 +148,7 @@ func (l ListOfRefOfMapOfStringToValue) Filter(cb ListOfRefOfMapOfStringToValueFi
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(RefOfMapOfStringToValue), i)
})
return ListOfRefOfMapOfStringToValue{out, &ref.Ref{}}
return ListOfRefOfMapOfStringToValue{out, l.cs, &ref.Ref{}}
}
// RefOfMapOfStringToValue
@@ -199,7 +200,7 @@ func builderForRefOfMapOfStringToValue(r ref.Ref) types.Value {
return NewRefOfMapOfStringToValue(r)
}
func (r RefOfMapOfStringToValue) TargetValue(cs chunks.ChunkSource) MapOfStringToValue {
func (r RefOfMapOfStringToValue) TargetValue(cs chunks.ChunkStore) MapOfStringToValue {
return types.ReadValue(r.target, cs).(MapOfStringToValue)
}
@@ -211,21 +212,22 @@ func (r RefOfMapOfStringToValue) SetTargetValue(val MapOfStringToValue, cs chunk
type MapOfStringToValue struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToValue() MapOfStringToValue {
return MapOfStringToValue{types.NewTypedMap(__typeForMapOfStringToValue), &ref.Ref{}}
func NewMapOfStringToValue(cs chunks.ChunkStore) MapOfStringToValue {
return MapOfStringToValue{types.NewTypedMap(cs, __typeForMapOfStringToValue), cs, &ref.Ref{}}
}
type MapOfStringToValueDef map[string]types.Value
func (def MapOfStringToValueDef) New() MapOfStringToValue {
func (def MapOfStringToValueDef) New(cs chunks.ChunkStore) MapOfStringToValue {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), v)
}
return MapOfStringToValue{types.NewTypedMap(__typeForMapOfStringToValue, kv...), &ref.Ref{}}
return MapOfStringToValue{types.NewTypedMap(cs, __typeForMapOfStringToValue, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToValue) Def() MapOfStringToValueDef {
@@ -267,8 +269,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToValue, builderForMapOfStringToValue, readerForMapOfStringToValue)
}
func builderForMapOfStringToValue(v types.Value) types.Value {
return MapOfStringToValue{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToValue(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToValue{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToValue(v types.Value) types.Value {
@@ -300,13 +302,13 @@ func (m MapOfStringToValue) MaybeGet(p string) (types.Value, bool) {
}
func (m MapOfStringToValue) Set(k string, v types.Value) MapOfStringToValue {
return MapOfStringToValue{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToValue{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToValue) Remove(p string) MapOfStringToValue {
return MapOfStringToValue{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToValue{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToValueIterCallback func(k string, v types.Value) (stop bool)
@@ -337,5 +339,5 @@ func (m MapOfStringToValue) Filter(cb MapOfStringToValueFilterCallback) MapOfStr
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v)
})
return MapOfStringToValue{out, &ref.Ref{}}
return MapOfStringToValue{out, m.cs, &ref.Ref{}}
}

View File

@@ -3,6 +3,7 @@ package util
import (
"reflect"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/d"
"github.com/attic-labs/noms/types"
)
@@ -21,7 +22,7 @@ import (
// Composites:
// - []interface{}
// - map[string]interface{}
func NomsValueFromDecodedJSON(o interface{}) types.Value {
func NomsValueFromDecodedJSON(cs chunks.ChunkStore, o interface{}) types.Value {
switch o := o.(type) {
case string:
return types.NewString(o)
@@ -32,18 +33,18 @@ func NomsValueFromDecodedJSON(o interface{}) types.Value {
case nil:
return nil
case []interface{}:
out := types.NewList()
out := types.NewList(cs)
for _, v := range o {
nv := NomsValueFromDecodedJSON(v)
nv := NomsValueFromDecodedJSON(cs, v)
if nv != nil {
out = out.Append(nv)
}
}
return out
case map[string]interface{}:
out := NewMapOfStringToValue()
out := NewMapOfStringToValue(cs)
for k, v := range o {
nv := NomsValueFromDecodedJSON(v)
nv := NomsValueFromDecodedJSON(cs, v)
if nv != nil {
out = out.Set(k, nv)
}

View File

@@ -4,6 +4,7 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/suite"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/types"
)
@@ -16,23 +17,25 @@ type LibTestSuite struct {
}
func (suite *LibTestSuite) TestPrimitiveTypes() {
suite.EqualValues(types.NewString("expected"), NomsValueFromDecodedJSON("expected"))
suite.EqualValues(types.Bool(false), NomsValueFromDecodedJSON(false))
suite.EqualValues(types.Float64(1.7), NomsValueFromDecodedJSON(1.7))
suite.False(NomsValueFromDecodedJSON(1.7).Equals(types.Bool(true)))
cs := chunks.NewMemoryStore()
suite.EqualValues(types.NewString("expected"), NomsValueFromDecodedJSON(cs, "expected"))
suite.EqualValues(types.Bool(false), NomsValueFromDecodedJSON(cs, false))
suite.EqualValues(types.Float64(1.7), NomsValueFromDecodedJSON(cs, 1.7))
suite.False(NomsValueFromDecodedJSON(cs, 1.7).Equals(types.Bool(true)))
}
func (suite *LibTestSuite) TestCompositeTypes() {
cs := chunks.NewMemoryStore()
// [false true]
suite.EqualValues(
types.NewList().Append(types.Bool(false)).Append(types.Bool(true)),
NomsValueFromDecodedJSON([]interface{}{false, true}))
types.NewList(cs).Append(types.Bool(false)).Append(types.Bool(true)),
NomsValueFromDecodedJSON(cs, []interface{}{false, true}))
// [[false true]]
suite.EqualValues(
types.NewList().Append(
types.NewList().Append(types.Bool(false)).Append(types.Bool(true))),
NomsValueFromDecodedJSON([]interface{}{[]interface{}{false, true}}))
types.NewList(cs).Append(
types.NewList(cs).Append(types.Bool(false)).Append(types.Bool(true))),
NomsValueFromDecodedJSON(cs, []interface{}{[]interface{}{false, true}}))
// {"string": "string",
// "list": [false true],
@@ -40,10 +43,10 @@ func (suite *LibTestSuite) TestCompositeTypes() {
// }
m := MapOfStringToValueDef{
"string": types.NewString("string"),
"list": types.NewList().Append(types.Bool(false)).Append(types.Bool(true)),
"map": MapOfStringToValueDef{"nested": types.NewString("string")}.New(),
}.New()
o := NomsValueFromDecodedJSON(map[string]interface{}{
"list": types.NewList(cs).Append(types.Bool(false)).Append(types.Bool(true)),
"map": MapOfStringToValueDef{"nested": types.NewString("string")}.New(cs),
}.New(cs)
o := NomsValueFromDecodedJSON(cs, map[string]interface{}{
"string": "string",
"list": []interface{}{false, true},
"map": map[string]interface{}{"nested": "string"},
@@ -53,5 +56,6 @@ func (suite *LibTestSuite) TestCompositeTypes() {
}
func (suite *LibTestSuite) TestPanicOnUnsupportedType() {
suite.Panics(func() { NomsValueFromDecodedJSON(map[int]string{1: "one"}) }, "Should panic on map[int]string!")
cs := chunks.NewMemoryStore()
suite.Panics(func() { NomsValueFromDecodedJSON(cs, map[int]string{1: "one"}) }, "Should panic on map[int]string!")
}

View File

@@ -84,7 +84,7 @@ func main() {
wg := sync.WaitGroup{}
importXml := func() {
expectedType := util.NewMapOfStringToValue()
expectedType := util.NewMapOfStringToValue(ds.Store())
for f := range filesChan {
file, err := os.Open(f.path)
d.Exp.NoError(err, "Error getting XML")
@@ -94,7 +94,7 @@ func main() {
object := xmlObject.Old()
file.Close()
nomsObj := util.NomsValueFromDecodedJSON(object)
nomsObj := util.NomsValueFromDecodedJSON(ds.Store(), object)
d.Chk.IsType(expectedType, nomsObj)
r := ref.Ref{}
@@ -130,7 +130,7 @@ func main() {
}
if !*noIO {
_, ok := ds.Commit(refs.New())
_, ok := ds.Commit(refs.New(ds.Store()))
d.Exp.True(ok, "Could not commit due to conflicting edit")
}

View File

@@ -12,7 +12,7 @@ type dataStoreCommon struct {
datasets *MapOfStringToRefOfCommit
}
func datasetsFromRef(datasetsRef ref.Ref, cs chunks.ChunkSource) *MapOfStringToRefOfCommit {
func datasetsFromRef(datasetsRef ref.Ref, cs chunks.ChunkStore) *MapOfStringToRefOfCommit {
c := types.ReadValue(datasetsRef, cs).(MapOfStringToRefOfCommit)
return &c
}
@@ -23,7 +23,7 @@ func (ds *dataStoreCommon) MaybeHead(datasetID string) (Commit, bool) {
return r.TargetValue(ds), true
}
}
return NewCommit(), false
return NewCommit(ds), false
}
func (ds *dataStoreCommon) Head(datasetID string) Commit {
@@ -34,7 +34,7 @@ func (ds *dataStoreCommon) Head(datasetID string) Commit {
func (ds *dataStoreCommon) Datasets() MapOfStringToRefOfCommit {
if ds.datasets == nil {
return NewMapOfStringToRefOfCommit()
return NewMapOfStringToRefOfCommit(ds)
} else {
return *ds.datasets
}
@@ -53,7 +53,7 @@ func (ds *dataStoreCommon) doCommit(datasetID string, commit Commit) bool {
} else if !currentRootRef.IsEmpty() {
currentDatasets = *datasetsFromRef(currentRootRef, ds)
} else {
currentDatasets = NewMapOfStringToRefOfCommit()
currentDatasets = NewMapOfStringToRefOfCommit(ds)
}
// TODO: This Commit will be orphaned if the UpdateRoot below fails
@@ -83,7 +83,7 @@ func (ds *dataStoreCommon) doCommit(datasetID string, commit Commit) bool {
return ds.UpdateRoot(newRootRef, currentRootRef)
}
func descendsFrom(commit Commit, currentHeadRef RefOfCommit, cs chunks.ChunkSource) bool {
func descendsFrom(commit Commit, currentHeadRef RefOfCommit, cs chunks.ChunkStore) bool {
// BFS because the common case is that the ancestor is only a step or two away
ancestors := commit.Parents()
for !ancestors.Has(currentHeadRef) {
@@ -95,8 +95,8 @@ func descendsFrom(commit Commit, currentHeadRef RefOfCommit, cs chunks.ChunkSour
return true
}
func getAncestors(commits SetOfRefOfCommit, cs chunks.ChunkSource) SetOfRefOfCommit {
ancestors := NewSetOfRefOfCommit()
func getAncestors(commits SetOfRefOfCommit, cs chunks.ChunkStore) SetOfRefOfCommit {
ancestors := NewSetOfRefOfCommit(cs)
commits.IterAll(func(r RefOfCommit) {
c := r.TargetValue(cs)
ancestors = ancestors.Union(c.Parents())

View File

@@ -10,8 +10,8 @@ import (
func TestDataStoreCommit(t *testing.T) {
assert := assert.New(t)
chunks := chunks.NewMemoryStore()
ds := NewDataStore(chunks)
cs := chunks.NewMemoryStore()
ds := NewDataStore(cs)
datasetID := "ds1"
datasets := ds.Datasets()
@@ -19,7 +19,7 @@ func TestDataStoreCommit(t *testing.T) {
// |a|
a := types.NewString("a")
aCommit := NewCommit().SetValue(a)
aCommit := NewCommit(cs).SetValue(a)
ds2, ok := ds.Commit(datasetID, aCommit)
assert.True(ok)
@@ -34,7 +34,7 @@ func TestDataStoreCommit(t *testing.T) {
// |a| <- |b|
b := types.NewString("b")
bCommit := NewCommit().SetValue(b).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(aCommit.Ref())))
bCommit := NewCommit(cs).SetValue(b).SetParents(NewSetOfRefOfCommit(cs).Insert(NewRefOfCommit(aCommit.Ref())))
ds, ok = ds.Commit(datasetID, bCommit)
assert.True(ok)
assert.True(ds.Head(datasetID).Value().Equals(b))
@@ -43,14 +43,14 @@ func TestDataStoreCommit(t *testing.T) {
// \----|c|
// Should be disallowed.
c := types.NewString("c")
cCommit := NewCommit().SetValue(c)
cCommit := NewCommit(cs).SetValue(c)
ds, ok = ds.Commit(datasetID, cCommit)
assert.False(ok)
assert.True(ds.Head(datasetID).Value().Equals(b))
// |a| <- |b| <- |d|
d := types.NewString("d")
dCommit := NewCommit().SetValue(d).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(bCommit.Ref())))
dCommit := NewCommit(cs).SetValue(d).SetParents(NewSetOfRefOfCommit(cs).Insert(NewRefOfCommit(bCommit.Ref())))
ds, ok = ds.Commit(datasetID, dCommit)
assert.True(ok)
assert.True(ds.Head(datasetID).Value().Equals(d))
@@ -66,7 +66,7 @@ func TestDataStoreCommit(t *testing.T) {
assert.True(ok)
// Get a fresh datastore, and verify that both datasets are present
newDs := NewDataStore(chunks)
newDs := NewDataStore(cs)
datasets2 := newDs.Datasets()
assert.Equal(uint64(2), datasets2.Len())
}
@@ -74,28 +74,28 @@ func TestDataStoreCommit(t *testing.T) {
func TestDataStoreConcurrency(t *testing.T) {
assert := assert.New(t)
chunks := chunks.NewMemoryStore()
ds := NewDataStore(chunks)
cs := chunks.NewMemoryStore()
ds := NewDataStore(cs)
datasetID := "ds1"
// Setup:
// |a| <- |b|
a := types.NewString("a")
aCommit := NewCommit().SetValue(a)
aCommit := NewCommit(cs).SetValue(a)
ds, ok := ds.Commit(datasetID, aCommit)
b := types.NewString("b")
bCommit := NewCommit().SetValue(b).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(aCommit.Ref())))
bCommit := NewCommit(cs).SetValue(b).SetParents(NewSetOfRefOfCommit(cs).Insert(NewRefOfCommit(aCommit.Ref())))
ds, ok = ds.Commit(datasetID, bCommit)
assert.True(ok)
assert.True(ds.Head(datasetID).Value().Equals(b))
// Important to create this here.
ds2 := NewDataStore(chunks)
ds2 := NewDataStore(cs)
// Change 1:
// |a| <- |b| <- |c|
c := types.NewString("c")
cCommit := NewCommit().SetValue(c).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(bCommit.Ref())))
cCommit := NewCommit(cs).SetValue(c).SetParents(NewSetOfRefOfCommit(cs).Insert(NewRefOfCommit(bCommit.Ref())))
ds, ok = ds.Commit(datasetID, cCommit)
assert.True(ok)
assert.True(ds.Head(datasetID).Value().Equals(c))
@@ -104,7 +104,7 @@ func TestDataStoreConcurrency(t *testing.T) {
// |a| <- |b| <- |e|
// Should be disallowed, DataStore returned by Commit() should have |c| as Head.
e := types.NewString("e")
eCommit := NewCommit().SetValue(e).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(bCommit.Ref())))
eCommit := NewCommit(cs).SetValue(e).SetParents(NewSetOfRefOfCommit(cs).Insert(NewRefOfCommit(bCommit.Ref())))
ds2, ok = ds2.Commit(datasetID, eCommit)
assert.False(ok)
assert.True(ds.Head(datasetID).Value().Equals(c))

View File

@@ -79,3 +79,19 @@ func (trs *teeChunkSource) Get(ref ref.Ref) chunks.Chunk {
func (trs *teeChunkSource) Has(ref ref.Ref) bool {
return trs.source.Has(ref)
}
func (trs *teeChunkSource) Root() ref.Ref {
panic("not reached")
}
func (trs *teeChunkSource) UpdateRoot(current, existing ref.Ref) bool {
panic("not reached")
}
func (trs *teeChunkSource) Put(c chunks.Chunk) {
panic("not reached")
}
func (trs *teeChunkSource) Close() error {
panic("not reached")
}

View File

@@ -32,14 +32,16 @@ type Commit struct {
_value types.Value
_parents SetOfRefOfCommit
cs chunks.ChunkStore
ref *ref.Ref
}
func NewCommit() Commit {
func NewCommit(cs chunks.ChunkStore) Commit {
return Commit{
_value: types.Bool(false),
_parents: NewSetOfRefOfCommit(),
_parents: NewSetOfRefOfCommit(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -49,10 +51,11 @@ type CommitDef struct {
Parents SetOfRefOfCommitDef
}
func (def CommitDef) New() Commit {
func (def CommitDef) New(cs chunks.ChunkStore) Commit {
return Commit{
_value: def.Value,
_parents: def.Parents.New(),
_parents: def.Parents.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -74,9 +77,9 @@ func init() {
types.RegisterStruct(__typeForCommit, builderForCommit, readerForCommit)
}
func builderForCommit(values []types.Value) types.Value {
func builderForCommit(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Commit{ref: &ref.Ref{}}
s := Commit{ref: &ref.Ref{}, cs: cs}
s._value = values[i]
i++
s._parents = values[i].(SetOfRefOfCommit)
@@ -137,21 +140,22 @@ func (s Commit) SetParents(val SetOfRefOfCommit) Commit {
type MapOfStringToRefOfCommit struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToRefOfCommit() MapOfStringToRefOfCommit {
return MapOfStringToRefOfCommit{types.NewTypedMap(__typeForMapOfStringToRefOfCommit), &ref.Ref{}}
func NewMapOfStringToRefOfCommit(cs chunks.ChunkStore) MapOfStringToRefOfCommit {
return MapOfStringToRefOfCommit{types.NewTypedMap(cs, __typeForMapOfStringToRefOfCommit), cs, &ref.Ref{}}
}
type MapOfStringToRefOfCommitDef map[string]ref.Ref
func (def MapOfStringToRefOfCommitDef) New() MapOfStringToRefOfCommit {
func (def MapOfStringToRefOfCommitDef) New(cs chunks.ChunkStore) MapOfStringToRefOfCommit {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), NewRefOfCommit(v))
}
return MapOfStringToRefOfCommit{types.NewTypedMap(__typeForMapOfStringToRefOfCommit, kv...), &ref.Ref{}}
return MapOfStringToRefOfCommit{types.NewTypedMap(cs, __typeForMapOfStringToRefOfCommit, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToRefOfCommit) Def() MapOfStringToRefOfCommitDef {
@@ -193,8 +197,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToRefOfCommit, builderForMapOfStringToRefOfCommit, readerForMapOfStringToRefOfCommit)
}
func builderForMapOfStringToRefOfCommit(v types.Value) types.Value {
return MapOfStringToRefOfCommit{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToRefOfCommit(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToRefOfCommit{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToRefOfCommit(v types.Value) types.Value {
@@ -226,13 +230,13 @@ func (m MapOfStringToRefOfCommit) MaybeGet(p string) (RefOfCommit, bool) {
}
func (m MapOfStringToRefOfCommit) Set(k string, v RefOfCommit) MapOfStringToRefOfCommit {
return MapOfStringToRefOfCommit{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToRefOfCommit{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToRefOfCommit) Remove(p string) MapOfStringToRefOfCommit {
return MapOfStringToRefOfCommit{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToRefOfCommit{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToRefOfCommitIterCallback func(k string, v RefOfCommit) (stop bool)
@@ -263,30 +267,31 @@ func (m MapOfStringToRefOfCommit) Filter(cb MapOfStringToRefOfCommitFilterCallba
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v.(RefOfCommit))
})
return MapOfStringToRefOfCommit{out, &ref.Ref{}}
return MapOfStringToRefOfCommit{out, m.cs, &ref.Ref{}}
}
// SetOfRefOfCommit
type SetOfRefOfCommit struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfRefOfCommit() SetOfRefOfCommit {
return SetOfRefOfCommit{types.NewTypedSet(__typeForSetOfRefOfCommit), &ref.Ref{}}
func NewSetOfRefOfCommit(cs chunks.ChunkStore) SetOfRefOfCommit {
return SetOfRefOfCommit{types.NewTypedSet(cs, __typeForSetOfRefOfCommit), cs, &ref.Ref{}}
}
type SetOfRefOfCommitDef map[ref.Ref]bool
func (def SetOfRefOfCommitDef) New() SetOfRefOfCommit {
func (def SetOfRefOfCommitDef) New(cs chunks.ChunkStore) SetOfRefOfCommit {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = NewRefOfCommit(d)
i++
}
return SetOfRefOfCommit{types.NewTypedSet(__typeForSetOfRefOfCommit, l...), &ref.Ref{}}
return SetOfRefOfCommit{types.NewTypedSet(cs, __typeForSetOfRefOfCommit, l...), cs, &ref.Ref{}}
}
func (s SetOfRefOfCommit) Def() SetOfRefOfCommitDef {
@@ -328,8 +333,8 @@ func init() {
types.RegisterValue(__typeForSetOfRefOfCommit, builderForSetOfRefOfCommit, readerForSetOfRefOfCommit)
}
func builderForSetOfRefOfCommit(v types.Value) types.Value {
return SetOfRefOfCommit{v.(types.Set), &ref.Ref{}}
func builderForSetOfRefOfCommit(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfRefOfCommit{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfRefOfCommit(v types.Value) types.Value {
@@ -376,23 +381,23 @@ func (s SetOfRefOfCommit) Filter(cb SetOfRefOfCommitFilterCallback) SetOfRefOfCo
out := s.s.Filter(func(v types.Value) bool {
return cb(v.(RefOfCommit))
})
return SetOfRefOfCommit{out, &ref.Ref{}}
return SetOfRefOfCommit{out, s.cs, &ref.Ref{}}
}
func (s SetOfRefOfCommit) Insert(p ...RefOfCommit) SetOfRefOfCommit {
return SetOfRefOfCommit{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfCommit{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfCommit) Remove(p ...RefOfCommit) SetOfRefOfCommit {
return SetOfRefOfCommit{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfCommit{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfCommit) Union(others ...SetOfRefOfCommit) SetOfRefOfCommit {
return SetOfRefOfCommit{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfCommit{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfCommit) Subtract(others ...SetOfRefOfCommit) SetOfRefOfCommit {
return SetOfRefOfCommit{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfCommit{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfRefOfCommit) Any() RefOfCommit {
@@ -464,7 +469,7 @@ func builderForRefOfCommit(r ref.Ref) types.Value {
return NewRefOfCommit(r)
}
func (r RefOfCommit) TargetValue(cs chunks.ChunkSource) Commit {
func (r RefOfCommit) TargetValue(cs chunks.ChunkStore) Commit {
return types.ReadValue(r.target, cs).(Commit)
}

View File

@@ -38,7 +38,7 @@ func (ds *Dataset) Head() datas.Commit {
// Commit updates the commit that a dataset points at. The new Commit is constructed using v and the current Head.
// If the update cannot be performed, e.g., because of a conflict, Commit returns 'false' and the current snapshot of the dataset so that the client can merge the changes and try again.
func (ds *Dataset) Commit(v types.Value) (Dataset, bool) {
p := datas.NewSetOfRefOfCommit()
p := datas.NewSetOfRefOfCommit(ds.store)
if head, ok := ds.MaybeHead(); ok {
p = p.Insert(datas.NewRefOfCommit(head.Ref()))
}
@@ -48,7 +48,7 @@ func (ds *Dataset) Commit(v types.Value) (Dataset, bool) {
// CommitWithParents updates the commit that a dataset points at. The new Commit is constructed using v and p.
// If the update cannot be performed, e.g., because of a conflict, CommitWithParents returns 'false' and the current snapshot of the dataset so that the client can merge the changes and try again.
func (ds *Dataset) CommitWithParents(v types.Value, p datas.SetOfRefOfCommit) (Dataset, bool) {
newCommit := datas.NewCommit().SetParents(p).SetValue(v)
newCommit := datas.NewCommit(ds.store).SetParents(p).SetValue(v)
store, ok := ds.Store().Commit(ds.id, newCommit)
return Dataset{store, ds.id}, ok
}

View File

@@ -13,14 +13,14 @@ func TestDatasetCommitTracker(t *testing.T) {
assert := assert.New(t)
id1 := "testdataset"
id2 := "othertestdataset"
ms := chunks.NewMemoryStore()
cs := chunks.NewMemoryStore()
ds1 := NewDataset(datas.NewDataStore(ms), id1)
ds1 := NewDataset(datas.NewDataStore(cs), id1)
ds1Commit := types.NewString("Commit value for " + id1)
ds1, ok := ds1.Commit(ds1Commit)
assert.True(ok)
ds2 := NewDataset(datas.NewDataStore(ms), id2)
ds2 := NewDataset(datas.NewDataStore(cs), id2)
ds2Commit := types.NewString("Commit value for " + id2)
ds2, ok = ds2.Commit(ds2Commit)
assert.True(ok)
@@ -30,11 +30,11 @@ func TestDatasetCommitTracker(t *testing.T) {
assert.False(ds2.Head().Value().Equals(ds1Commit))
assert.False(ds1.Head().Value().Equals(ds2Commit))
assert.Equal("sha1-580dcb5f3a138e4aafbf7cb831607d5475c06759", ms.Root().String())
assert.Equal("sha1-580dcb5f3a138e4aafbf7cb831607d5475c06759", cs.Root().String())
}
func newDS(id string, ms *chunks.MemoryStore) Dataset {
store := datas.NewDataStore(ms)
func newDS(id string, cs *chunks.MemoryStore) Dataset {
store := datas.NewDataStore(cs)
return NewDataset(store, id)
}
@@ -42,9 +42,9 @@ func TestExplicitBranchUsingDatasets(t *testing.T) {
assert := assert.New(t)
id1 := "testdataset"
id2 := "othertestdataset"
ms := chunks.NewMemoryStore()
cs := chunks.NewMemoryStore()
ds1 := newDS(id1, ms)
ds1 := newDS(id1, cs)
// ds1: |a|
a := types.NewString("a")
@@ -54,7 +54,7 @@ func TestExplicitBranchUsingDatasets(t *testing.T) {
// ds1: |a|
// \ds2
ds2 := newDS(id2, ms)
ds2 := newDS(id2, cs)
ds2, ok = ds2.Commit(ds1.Head().Value())
assert.True(ok)
assert.True(ds2.Head().Value().Equals(a))
@@ -74,7 +74,7 @@ func TestExplicitBranchUsingDatasets(t *testing.T) {
// ds1: |a| <- |b| <--|d|
// \ds2 <- |c| <--/
mergeParents := datas.NewSetOfRefOfCommit().Insert(datas.NewRefOfCommit(ds1.Head().Ref())).Insert(datas.NewRefOfCommit(ds2.Head().Ref()))
mergeParents := datas.NewSetOfRefOfCommit(cs).Insert(datas.NewRefOfCommit(ds1.Head().Ref())).Insert(datas.NewRefOfCommit(ds2.Head().Ref()))
d := types.NewString("d")
ds2, ok = ds2.CommitWithParents(d, mergeParents)
assert.True(ok)
@@ -88,10 +88,10 @@ func TestExplicitBranchUsingDatasets(t *testing.T) {
func TestTwoClientsWithEmptyDataset(t *testing.T) {
assert := assert.New(t)
id1 := "testdataset"
ms := chunks.NewMemoryStore()
cs := chunks.NewMemoryStore()
dsx := newDS(id1, ms)
dsy := newDS(id1, ms)
dsx := newDS(id1, cs)
dsy := newDS(id1, cs)
// dsx: || -> |a|
a := types.NewString("a")
@@ -115,19 +115,19 @@ func TestTwoClientsWithEmptyDataset(t *testing.T) {
func TestTwoClientsWithNonEmptyDataset(t *testing.T) {
assert := assert.New(t)
id1 := "testdataset"
ms := chunks.NewMemoryStore()
cs := chunks.NewMemoryStore()
a := types.NewString("a")
{
// ds1: || -> |a|
ds1 := newDS(id1, ms)
ds1 := newDS(id1, cs)
ds1, ok := ds1.Commit(a)
assert.True(ok)
assert.True(ds1.Head().Value().Equals(a))
}
dsx := newDS(id1, ms)
dsy := newDS(id1, ms)
dsx := newDS(id1, cs)
dsy := newDS(id1, cs)
// dsx: |a| -> |b|
assert.True(dsx.Head().Value().Equals(a))

View File

@@ -22,19 +22,19 @@ func TestValidateRef(t *testing.T) {
}
func NewList(ds Dataset, vs ...types.Value) types.Ref {
v := types.NewList(vs...)
v := types.NewList(ds.Store(), vs...)
r := types.WriteValue(v, ds.store)
return types.NewRef(r)
}
func NewMap(ds Dataset, vs ...types.Value) types.Ref {
v := types.NewMap(vs...)
v := types.NewMap(ds.Store(), vs...)
r := types.WriteValue(v, ds.store)
return types.NewRef(r)
}
func NewSet(ds Dataset, vs ...types.Value) types.Ref {
v := types.NewSet(vs...)
v := types.NewSet(ds.Store(), vs...)
r := types.WriteValue(v, ds.store)
return types.NewRef(r)
}
@@ -46,10 +46,10 @@ func TestPull(t *testing.T) {
source := createTestDataset("source")
// Give sink and source some initial shared context.
sourceInitialValue := types.NewMap(
sourceInitialValue := types.NewMap(source.Store(),
types.NewString("first"), NewList(source),
types.NewString("second"), NewList(source, types.Int32(2)))
sinkInitialValue := types.NewMap(
sinkInitialValue := types.NewMap(sink.Store(),
types.NewString("first"), NewList(sink),
types.NewString("second"), NewList(sink, types.Int32(2)))
@@ -82,7 +82,7 @@ func TestPullFirstCommit(t *testing.T) {
sink := createTestDataset("sink")
source := createTestDataset("source")
sourceInitialValue := types.NewMap(
sourceInitialValue := types.NewMap(source.Store(),
types.NewString("first"), NewList(source),
types.NewString("second"), NewList(source, types.Int32(2)))
@@ -102,10 +102,10 @@ func TestPullDeepRef(t *testing.T) {
sink := createTestDataset("sink")
source := createTestDataset("source")
sourceInitialValue := types.NewList(
types.NewList(NewList(source)),
types.NewSet(NewSet(source)),
types.NewMap(NewMap(source), NewMap(source)))
sourceInitialValue := types.NewList(source.Store(),
types.NewList(source.Store(), NewList(source)),
types.NewSet(source.Store(), NewSet(source)),
types.NewMap(source.Store(), NewMap(source), NewMap(source)))
source, ok := source.Commit(sourceInitialValue)
assert.True(ok)

View File

@@ -83,7 +83,7 @@ func (gen Generator) DefToValue(val string, t types.Type) string {
case types.BoolKind, types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.StringKind, types.UInt16Kind, types.UInt32Kind, types.UInt64Kind, types.UInt8Kind:
return gen.NativeToValue(val, rt)
case types.ListKind, types.MapKind, types.SetKind, types.StructKind:
return fmt.Sprintf("%s.New()", val)
return fmt.Sprintf("%s.New(cs)", val)
case types.RefKind:
return fmt.Sprintf("New%s(%s)", gen.UserName(rt), val)
}
@@ -209,7 +209,7 @@ func (gen Generator) ValueToUser(val string, t types.Type) string {
}
// UserZero returns a string containing Go code to create an uninitialized instance of the User type appropriate for t.
func (gen Generator) UserZero(t types.Type) string {
func (gen Generator) UserZero(val string, t types.Type) string {
rt := gen.R.Resolve(t)
k := rt.Kind()
switch k {
@@ -221,7 +221,9 @@ func (gen Generator) UserZero(t types.Type) string {
return fmt.Sprintf("New%s()", gen.UserName(rt))
case types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.UInt16Kind, types.UInt32Kind, types.UInt64Kind, types.UInt8Kind:
return fmt.Sprintf("%s(0)", strings.ToLower(kindToString(k)))
case types.ListKind, types.MapKind, types.PackageKind, types.SetKind, types.StructKind:
case types.ListKind, types.MapKind, types.SetKind, types.StructKind:
return fmt.Sprintf("New%s(%s)", gen.UserName(rt), val)
case types.PackageKind:
return fmt.Sprintf("New%s()", gen.UserName(rt))
case types.RefKind:
return fmt.Sprintf("New%s(ref.Ref{})", gen.UserName(rt))
@@ -246,11 +248,11 @@ func (gen Generator) ValueZero(t types.Type) string {
case types.BoolKind:
return fmt.Sprintf("%sBool(false)", gen.TypesPackage)
case types.EnumKind:
return gen.UserZero(t)
return gen.UserZero("", t)
case types.Float32Kind, types.Float64Kind, types.Int16Kind, types.Int32Kind, types.Int64Kind, types.Int8Kind, types.UInt16Kind, types.UInt32Kind, types.UInt64Kind, types.UInt8Kind:
return fmt.Sprintf("%s%s(0)", gen.TypesPackage, kindToString(k))
case types.ListKind, types.MapKind, types.RefKind, types.SetKind:
return gen.UserZero(t)
return gen.UserZero("", t)
case types.PackageKind:
return fmt.Sprintf("%sNewPackage()", gen.TypesPackage)
case types.StringKind:

View File

@@ -119,7 +119,7 @@ func generate(packageName, in, out, outDir string, written map[string]bool, pars
type depsMap map[ref.Ref]types.Package
func generateDepCode(packageName, outDir string, written map[string]bool, p types.Package, localPkgs refSet, cs chunks.ChunkSource) depsMap {
func generateDepCode(packageName, outDir string, written map[string]bool, p types.Package, localPkgs refSet, cs chunks.ChunkStore) depsMap {
deps := depsMap{}
for _, r := range p.Dependencies() {
p := types.ReadValue(r, cs).(types.Package)
@@ -159,7 +159,7 @@ func generateAndEmit(tag, out string, written map[string]bool, deps depsMap, p p
func buildSetOfRefOfPackage(pkg pkg.Parsed, deps depsMap, ds dataset.Dataset) types.SetOfRefOfPackage {
// Can do better once generated collections implement types.Value.
s := types.NewSetOfRefOfPackage()
s := types.NewSetOfRefOfPackage(ds.Store())
if h, ok := ds.MaybeHead(); ok {
s = h.Value().(types.SetOfRefOfPackage)
}

View File

@@ -4,22 +4,23 @@
type {{.Name}} struct {
l {{$typesPackage}}List
cs chunks.ChunkStore
ref *ref.Ref
}
func New{{.Name}}() {{.Name}} {
return {{.Name}}{ {{$typesPackage}}NewTypedList(__typeFor{{.Name}}), &ref.Ref{}}
func New{{.Name}}(cs chunks.ChunkStore) {{.Name}} {
return {{.Name}}{ {{$typesPackage}}NewTypedList(cs, __typeFor{{.Name}}), cs, &ref.Ref{}}
}
{{if .CanUseDef}}
type {{.Name}}Def []{{defType .ElemType}}
func (def {{.Name}}Def) New() {{.Name}} {
func (def {{.Name}}Def) New(cs chunks.ChunkStore) {{.Name}} {
l := make([]{{$typesPackage}}Value, len(def))
for i, d := range def {
l[i] = {{defToValue "d" .ElemType }}
}
return {{.Name}}{ {{$typesPackage}}NewTypedList(__typeFor{{.Name}}, l...), &ref.Ref{}}
return {{.Name}}{ {{$typesPackage}}NewTypedList(cs, __typeFor{{.Name}}, l...), cs, &ref.Ref{}}
}
func (l {{.Name}}) Def() {{.Name}}Def {
@@ -61,8 +62,8 @@ func init() {
{{$typesPackage}}RegisterValue(__typeFor{{.Name}}, builderFor{{.Name}}, readerFor{{.Name}})
}
func builderFor{{.Name}}(v {{$typesPackage}}Value) {{$typesPackage}}Value {
return {{.Name}}{v.({{$typesPackage}}List), &ref.Ref{}}
func builderFor{{.Name}}(cs chunks.ChunkStore, v {{$typesPackage}}Value) {{$typesPackage}}Value {
return {{.Name}}{v.({{$typesPackage}}List), cs, &ref.Ref{}}
}
func readerFor{{.Name}}(v {{$typesPackage}}Value) {{$typesPackage}}Value {
@@ -82,27 +83,27 @@ func (l {{.Name}}) Get(i uint64) {{userType .ElemType}} {
}
func (l {{.Name}}) Slice(idx uint64, end uint64) {{.Name}} {
return {{.Name}}{l.l.Slice(idx, end), &ref.Ref{}}
return {{.Name}}{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l {{.Name}}) Set(i uint64, val {{userType .ElemType}}) {{.Name}} {
return {{.Name}}{l.l.Set(i, {{userToValue "val" .ElemType}}), &ref.Ref{}}
return {{.Name}}{l.l.Set(i, {{userToValue "val" .ElemType}}), l.cs, &ref.Ref{}}
}
func (l {{.Name}}) Append(v ...{{userType .ElemType}}) {{.Name}} {
return {{.Name}}{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return {{.Name}}{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l {{.Name}}) Insert(idx uint64, v ...{{userType .ElemType}}) {{.Name}} {
return {{.Name}}{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return {{.Name}}{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l {{.Name}}) Remove(idx uint64, end uint64) {{.Name}} {
return {{.Name}}{l.l.Remove(idx, end), &ref.Ref{}}
return {{.Name}}{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l {{.Name}}) RemoveAt(idx uint64) {{.Name}} {
return {{.Name}}{(l.l.RemoveAt(idx)), &ref.Ref{}}
return {{.Name}}{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l {{.Name}}) fromElemSlice(p []{{userType .ElemType}}) []{{$typesPackage}}Value {
@@ -141,5 +142,5 @@ func (l {{.Name}}) Filter(cb {{.Name}}FilterCallback) {{.Name}} {
out := l.l.Filter(func(v {{$typesPackage}}Value, i uint64) bool {
return cb({{valueToUser "v" .ElemType}}, i)
})
return {{.Name}}{out, &ref.Ref{}}
return {{.Name}}{out, l.cs, &ref.Ref{}}
}

View File

@@ -4,22 +4,23 @@
type {{.Name}} struct {
m {{$typesPackage}}Map
cs chunks.ChunkStore
ref *ref.Ref
}
func New{{.Name}}() {{.Name}} {
return {{.Name}}{ {{$typesPackage}}NewTypedMap(__typeFor{{.Name}}), &ref.Ref{}}
func New{{.Name}}(cs chunks.ChunkStore) {{.Name}} {
return {{.Name}}{ {{$typesPackage}}NewTypedMap(cs, __typeFor{{.Name}}), cs, &ref.Ref{}}
}
{{if .CanUseDef}}
type {{.Name}}Def map[{{defType .KeyType}}]{{defType .ValueType}}
func (def {{.Name}}Def) New() {{.Name}} {
func (def {{.Name}}Def) New(cs chunks.ChunkStore) {{.Name}} {
kv := make([]{{$typesPackage}}Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, {{defToValue "k" .KeyType}}, {{defToValue "v" .ValueType}})
}
return {{.Name}}{ {{$typesPackage}}NewTypedMap(__typeFor{{.Name}}, kv...), &ref.Ref{}}
return {{.Name}}{ {{$typesPackage}}NewTypedMap(cs, __typeFor{{.Name}}, kv...), cs, &ref.Ref{}}
}
func (m {{.Name}}) Def() {{.Name}}Def {
@@ -62,8 +63,8 @@ func init() {
{{$typesPackage}}RegisterValue(__typeFor{{.Name}}, builderFor{{.Name}}, readerFor{{.Name}})
}
func builderFor{{.Name}}(v {{$typesPackage}}Value) {{$typesPackage}}Value {
return {{.Name}}{v.({{$typesPackage}}Map), &ref.Ref{}}
func builderFor{{.Name}}(cs chunks.ChunkStore, v {{$typesPackage}}Value) {{$typesPackage}}Value {
return {{.Name}}{v.({{$typesPackage}}Map), cs, &ref.Ref{}}
}
func readerFor{{.Name}}(v {{$typesPackage}}Value) {{$typesPackage}}Value {
@@ -89,19 +90,19 @@ func (m {{.Name}}) Get(p {{userType .KeyType}}) {{userType .ValueType}} {
func (m {{.Name}}) MaybeGet(p {{userType .KeyType}}) ({{userType .ValueType}}, bool) {
v, ok := m.m.MaybeGet({{userToValue "p" .KeyType}})
if !ok {
return {{userZero .ValueType}}, false
return {{userZero "m.cs" .ValueType}}, false
}
return {{valueToUser "v" .ValueType}}, ok
}
func (m {{.Name}}) Set(k {{userType .KeyType}}, v {{userType .ValueType}}) {{.Name}} {
return {{.Name}}{m.m.Set({{userToValue "k" .KeyType}}, {{userToValue "v" .ValueType}}), &ref.Ref{}}
return {{.Name}}{m.m.Set({{userToValue "k" .KeyType}}, {{userToValue "v" .ValueType}}), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m {{.Name}}) Remove(p {{userType .KeyType}}) {{.Name}} {
return {{.Name}}{m.m.Remove({{userToValue "p" .KeyType}}), &ref.Ref{}}
return {{.Name}}{m.m.Remove({{userToValue "p" .KeyType}}), m.cs, &ref.Ref{}}
}
type {{.Name}}IterCallback func(k {{userType .KeyType}}, v {{userType .ValueType}}) (stop bool)
@@ -132,5 +133,5 @@ func (m {{.Name}}) Filter(cb {{.Name}}FilterCallback) {{.Name}} {
out := m.m.Filter(func(k, v {{$typesPackage}}Value) bool {
return cb({{valueToUser "k" .KeyType}}, {{valueToUser "v" .ValueType}})
})
return {{.Name}}{out, &ref.Ref{}}
return {{.Name}}{out, m.cs, &ref.Ref{}}
}

View File

@@ -49,7 +49,7 @@ func builderFor{{.Name}}(r ref.Ref) {{$typesPackage}}Value {
return New{{.Name}}(r)
}
func (r {{.Name}}) TargetValue(cs chunks.ChunkSource) {{userType .ElemType}} {
func (r {{.Name}}) TargetValue(cs chunks.ChunkStore) {{userType .ElemType}} {
return {{valueToUser (printf "%sReadValue(r.target, cs)" $typesPackage) .ElemType}}
}

View File

@@ -4,24 +4,25 @@
type {{.Name}} struct {
s {{$typesPackage}}Set
cs chunks.ChunkStore
ref *ref.Ref
}
func New{{.Name}}() {{.Name}} {
return {{.Name}}{ {{$typesPackage}}NewTypedSet(__typeFor{{.Name}}), &ref.Ref{}}
func New{{.Name}}(cs chunks.ChunkStore) {{.Name}} {
return {{.Name}}{ {{$typesPackage}}NewTypedSet(cs, __typeFor{{.Name}}), cs, &ref.Ref{}}
}
{{if .CanUseDef}}
type {{.Name}}Def map[{{defType .ElemType}}]bool
func (def {{.Name}}Def) New() {{.Name}} {
func (def {{.Name}}Def) New(cs chunks.ChunkStore) {{.Name}} {
l := make([]{{$typesPackage}}Value, len(def))
i := 0
for d, _ := range def {
l[i] = {{defToValue "d" .ElemType}}
i++
}
return {{.Name}}{ {{$typesPackage}}NewTypedSet(__typeFor{{.Name}}, l...), &ref.Ref{}}
return {{.Name}}{ {{$typesPackage}}NewTypedSet(cs, __typeFor{{.Name}}, l...), cs, &ref.Ref{}}
}
func (s {{.Name}}) Def() {{.Name}}Def {
@@ -64,8 +65,8 @@ func init() {
{{$typesPackage}}RegisterValue(__typeFor{{.Name}}, builderFor{{.Name}}, readerFor{{.Name}})
}
func builderFor{{.Name}}(v {{$typesPackage}}Value) {{$typesPackage}}Value {
return {{.Name}}{v.({{$typesPackage}}Set), &ref.Ref{}}
func builderFor{{.Name}}(cs chunks.ChunkStore, v {{$typesPackage}}Value) {{$typesPackage}}Value {
return {{.Name}}{v.({{$typesPackage}}Set), cs, &ref.Ref{}}
}
func readerFor{{.Name}}(v {{$typesPackage}}Value) {{$typesPackage}}Value {
@@ -112,23 +113,23 @@ func (s {{.Name}}) Filter(cb {{.Name}}FilterCallback) {{.Name}} {
out := s.s.Filter(func(v {{$typesPackage}}Value) bool {
return cb({{valueToUser "v" .ElemType}})
})
return {{.Name}}{out, &ref.Ref{}}
return {{.Name}}{out, s.cs, &ref.Ref{}}
}
func (s {{.Name}}) Insert(p ...{{userType .ElemType}}) {{.Name}} {
return {{.Name}}{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return {{.Name}}{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s {{.Name}}) Remove(p ...{{userType .ElemType}}) {{.Name}} {
return {{.Name}}{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return {{.Name}}{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s {{.Name}}) Union(others ...{{.Name}}) {{.Name}} {
return {{.Name}}{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return {{.Name}}{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s {{.Name}}) Subtract(others ...{{.Name}}) {{.Name}} {
return {{.Name}}{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return {{.Name}}{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s {{.Name}}) Any() {{userType .ElemType}} {

View File

@@ -7,14 +7,16 @@ type {{.Name}} struct {
{{if .Optional}}__optional{{.Name}} bool
{{end}}{{end}}{{if .HasUnion}}__unionIndex uint32
__unionValue {{$typesPackage}}Value{{end}}
cs chunks.ChunkStore
ref *ref.Ref
}
func New{{.Name}}() {{.Name}} {
func New{{.Name}}(cs chunks.ChunkStore) {{.Name}} {
return {{.Name}}{
{{range .Fields}}{{if (not .Optional)}}_{{.Name}}: {{userZero .T}},
{{range .Fields}}{{if (not .Optional)}}_{{.Name}}: {{userZero "cs" .T}},
{{end}}{{end}}{{if .HasUnion}}__unionIndex: 0,
__unionValue: {{valueZero .UnionZeroType}},{{end}}
cs: cs,
ref: &ref.Ref{},
}
}
@@ -26,13 +28,14 @@ func New{{.Name}}() {{.Name}} {
__unionValue {{$typesPackage}}Value
{{end}}}
func (def {{.Name}}Def) New() {{.Name}} {
func (def {{.Name}}Def) New(cs chunks.ChunkStore) {{.Name}} {
return {{.Name}}{
{{range .Fields}}_{{.Name}}: {{defToUser (print "def." (title .Name)) .T}},
{{if .Optional}}__optional{{.Name}}: true,
{{end}}{{end}}{{if .HasUnion}}__unionIndex: def.__unionIndex,
__unionValue: def.__unionValue,
{{end}}ref: &ref.Ref{},
{{end}}cs: cs,
ref: &ref.Ref{},
}
}
@@ -56,9 +59,9 @@ func init() {
{{$typesPackage}}RegisterStruct(__typeFor{{.Name}}, builderFor{{.Name}}, readerFor{{.Name}})
}
func builderFor{{.Name}}(values []{{$typesPackage}}Value) {{$typesPackage}}Value {
func builderFor{{.Name}}(cs chunks.ChunkStore, values []{{$typesPackage}}Value) {{$typesPackage}}Value {
i := 0
s := {{.Name}}{ref: &ref.Ref{}}{{range .Fields}}{{if .Optional}}
s := {{.Name}}{ref: &ref.Ref{}, cs: cs}{{range .Fields}}{{if .Optional}}
s.__optional{{.Name}} = bool(values[i].({{$typesPackage}}Bool))
i++
if s.__optional{{.Name}} {
@@ -158,7 +161,7 @@ func (s {{$name}}) Set{{title .Name}}(val {{userType .T}}) {{$name}} {
return {{valueToDef "def.__unionValue" .T}}, true
}
func (def {{$name}}Def) Set{{title .Name}}(val {{defType .T}}) {{$name}}Def {
func (def {{$name}}Def) Set{{title .Name}}(cs chunks.ChunkStore, val {{defType .T}}) {{$name}}Def {
def.__unionIndex = {{$index}}
def.__unionValue = {{defToValue "val" .T}}
return def

View File

@@ -11,17 +11,18 @@ import (
func TestEnum(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.EnumStructDef{gen.Right}
st := def.New()
st := def.New(cs)
def2 := st.Def()
st2 := def.New()
st2 := def.New(cs)
assert.Equal(def, def2)
assert.True(st.Equals(st2))
st3 := gen.NewEnumStruct()
st3 := gen.NewEnumStruct(cs)
assert.Equal(gen.Right, st3.Hand())
st3 = st3.SetHand(gen.Left)
assert.Equal(gen.Left, st3.Hand())
@@ -29,17 +30,18 @@ func TestEnum(t *testing.T) {
func TestEnumValue(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.EnumStructDef{gen.Switch}
var st types.Value
st = def.New()
st = def.New(cs)
st2 := st.(gen.EnumStruct)
assert.True(st.Equals(st2))
}
func TestEnumIsValue(t *testing.T) {
cs := chunks.NewMemoryStore()
var v types.Value = gen.NewEnumStruct()
var v types.Value = gen.NewEnumStruct(cs)
ref := types.WriteValue(v, cs)
v2 := types.ReadValue(ref, cs)
assert.True(t, v.Equals(v2))

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -80,13 +81,15 @@ func (e Handedness) ChildValues() []types.Value {
type EnumStruct struct {
_hand Handedness
cs chunks.ChunkStore
ref *ref.Ref
}
func NewEnumStruct() EnumStruct {
func NewEnumStruct(cs chunks.ChunkStore) EnumStruct {
return EnumStruct{
_hand: NewHandedness(),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -95,9 +98,10 @@ type EnumStructDef struct {
Hand Handedness
}
func (def EnumStructDef) New() EnumStruct {
func (def EnumStructDef) New(cs chunks.ChunkStore) EnumStruct {
return EnumStruct{
_hand: def.Hand,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -118,9 +122,9 @@ func init() {
types.RegisterStruct(__typeForEnumStruct, builderForEnumStruct, readerForEnumStruct)
}
func builderForEnumStruct(values []types.Value) types.Value {
func builderForEnumStruct(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := EnumStruct{ref: &ref.Ref{}}
s := EnumStruct{ref: &ref.Ref{}, cs: cs}
s._hand = values[i].(Handedness)
i++
return s

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -11,21 +12,22 @@ import (
type ListOfInt64 struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfInt64() ListOfInt64 {
return ListOfInt64{types.NewTypedList(__typeForListOfInt64), &ref.Ref{}}
func NewListOfInt64(cs chunks.ChunkStore) ListOfInt64 {
return ListOfInt64{types.NewTypedList(cs, __typeForListOfInt64), cs, &ref.Ref{}}
}
type ListOfInt64Def []int64
func (def ListOfInt64Def) New() ListOfInt64 {
func (def ListOfInt64Def) New(cs chunks.ChunkStore) ListOfInt64 {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = types.Int64(d)
}
return ListOfInt64{types.NewTypedList(__typeForListOfInt64, l...), &ref.Ref{}}
return ListOfInt64{types.NewTypedList(cs, __typeForListOfInt64, l...), cs, &ref.Ref{}}
}
func (l ListOfInt64) Def() ListOfInt64Def {
@@ -66,8 +68,8 @@ func init() {
types.RegisterValue(__typeForListOfInt64, builderForListOfInt64, readerForListOfInt64)
}
func builderForListOfInt64(v types.Value) types.Value {
return ListOfInt64{v.(types.List), &ref.Ref{}}
func builderForListOfInt64(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfInt64{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfInt64(v types.Value) types.Value {
@@ -87,27 +89,27 @@ func (l ListOfInt64) Get(i uint64) int64 {
}
func (l ListOfInt64) Slice(idx uint64, end uint64) ListOfInt64 {
return ListOfInt64{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfInt64{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfInt64) Set(i uint64, val int64) ListOfInt64 {
return ListOfInt64{l.l.Set(i, types.Int64(val)), &ref.Ref{}}
return ListOfInt64{l.l.Set(i, types.Int64(val)), l.cs, &ref.Ref{}}
}
func (l ListOfInt64) Append(v ...int64) ListOfInt64 {
return ListOfInt64{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfInt64{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfInt64) Insert(idx uint64, v ...int64) ListOfInt64 {
return ListOfInt64{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfInt64{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfInt64) Remove(idx uint64, end uint64) ListOfInt64 {
return ListOfInt64{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfInt64{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfInt64) RemoveAt(idx uint64) ListOfInt64 {
return ListOfInt64{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfInt64{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfInt64) fromElemSlice(p []int64) []types.Value {
@@ -146,5 +148,5 @@ func (l ListOfInt64) Filter(cb ListOfInt64FilterCallback) ListOfInt64 {
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(int64(v.(types.Int64)), i)
})
return ListOfInt64{out, &ref.Ref{}}
return ListOfInt64{out, l.cs, &ref.Ref{}}
}

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -11,21 +12,22 @@ import (
type MapOfBoolToString struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfBoolToString() MapOfBoolToString {
return MapOfBoolToString{types.NewTypedMap(__typeForMapOfBoolToString), &ref.Ref{}}
func NewMapOfBoolToString(cs chunks.ChunkStore) MapOfBoolToString {
return MapOfBoolToString{types.NewTypedMap(cs, __typeForMapOfBoolToString), cs, &ref.Ref{}}
}
type MapOfBoolToStringDef map[bool]string
func (def MapOfBoolToStringDef) New() MapOfBoolToString {
func (def MapOfBoolToStringDef) New(cs chunks.ChunkStore) MapOfBoolToString {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.Bool(k), types.NewString(v))
}
return MapOfBoolToString{types.NewTypedMap(__typeForMapOfBoolToString, kv...), &ref.Ref{}}
return MapOfBoolToString{types.NewTypedMap(cs, __typeForMapOfBoolToString, kv...), cs, &ref.Ref{}}
}
func (m MapOfBoolToString) Def() MapOfBoolToStringDef {
@@ -67,8 +69,8 @@ func init() {
types.RegisterValue(__typeForMapOfBoolToString, builderForMapOfBoolToString, readerForMapOfBoolToString)
}
func builderForMapOfBoolToString(v types.Value) types.Value {
return MapOfBoolToString{v.(types.Map), &ref.Ref{}}
func builderForMapOfBoolToString(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfBoolToString{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfBoolToString(v types.Value) types.Value {
@@ -100,13 +102,13 @@ func (m MapOfBoolToString) MaybeGet(p bool) (string, bool) {
}
func (m MapOfBoolToString) Set(k bool, v string) MapOfBoolToString {
return MapOfBoolToString{m.m.Set(types.Bool(k), types.NewString(v)), &ref.Ref{}}
return MapOfBoolToString{m.m.Set(types.Bool(k), types.NewString(v)), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfBoolToString) Remove(p bool) MapOfBoolToString {
return MapOfBoolToString{m.m.Remove(types.Bool(p)), &ref.Ref{}}
return MapOfBoolToString{m.m.Remove(types.Bool(p)), m.cs, &ref.Ref{}}
}
type MapOfBoolToStringIterCallback func(k bool, v string) (stop bool)
@@ -137,28 +139,29 @@ func (m MapOfBoolToString) Filter(cb MapOfBoolToStringFilterCallback) MapOfBoolT
out := m.m.Filter(func(k, v types.Value) bool {
return cb(bool(k.(types.Bool)), v.(types.String).String())
})
return MapOfBoolToString{out, &ref.Ref{}}
return MapOfBoolToString{out, m.cs, &ref.Ref{}}
}
// MapOfStringToValue
type MapOfStringToValue struct {
m types.Map
cs chunks.ChunkStore
ref *ref.Ref
}
func NewMapOfStringToValue() MapOfStringToValue {
return MapOfStringToValue{types.NewTypedMap(__typeForMapOfStringToValue), &ref.Ref{}}
func NewMapOfStringToValue(cs chunks.ChunkStore) MapOfStringToValue {
return MapOfStringToValue{types.NewTypedMap(cs, __typeForMapOfStringToValue), cs, &ref.Ref{}}
}
type MapOfStringToValueDef map[string]types.Value
func (def MapOfStringToValueDef) New() MapOfStringToValue {
func (def MapOfStringToValueDef) New(cs chunks.ChunkStore) MapOfStringToValue {
kv := make([]types.Value, 0, len(def)*2)
for k, v := range def {
kv = append(kv, types.NewString(k), v)
}
return MapOfStringToValue{types.NewTypedMap(__typeForMapOfStringToValue, kv...), &ref.Ref{}}
return MapOfStringToValue{types.NewTypedMap(cs, __typeForMapOfStringToValue, kv...), cs, &ref.Ref{}}
}
func (m MapOfStringToValue) Def() MapOfStringToValueDef {
@@ -200,8 +203,8 @@ func init() {
types.RegisterValue(__typeForMapOfStringToValue, builderForMapOfStringToValue, readerForMapOfStringToValue)
}
func builderForMapOfStringToValue(v types.Value) types.Value {
return MapOfStringToValue{v.(types.Map), &ref.Ref{}}
func builderForMapOfStringToValue(cs chunks.ChunkStore, v types.Value) types.Value {
return MapOfStringToValue{v.(types.Map), cs, &ref.Ref{}}
}
func readerForMapOfStringToValue(v types.Value) types.Value {
@@ -233,13 +236,13 @@ func (m MapOfStringToValue) MaybeGet(p string) (types.Value, bool) {
}
func (m MapOfStringToValue) Set(k string, v types.Value) MapOfStringToValue {
return MapOfStringToValue{m.m.Set(types.NewString(k), v), &ref.Ref{}}
return MapOfStringToValue{m.m.Set(types.NewString(k), v), m.cs, &ref.Ref{}}
}
// TODO: Implement SetM?
func (m MapOfStringToValue) Remove(p string) MapOfStringToValue {
return MapOfStringToValue{m.m.Remove(types.NewString(p)), &ref.Ref{}}
return MapOfStringToValue{m.m.Remove(types.NewString(p)), m.cs, &ref.Ref{}}
}
type MapOfStringToValueIterCallback func(k string, v types.Value) (stop bool)
@@ -270,5 +273,5 @@ func (m MapOfStringToValue) Filter(cb MapOfStringToValueFilterCallback) MapOfStr
out := m.m.Filter(func(k, v types.Value) bool {
return cb(k.(types.String).String(), v)
})
return MapOfStringToValue{out, &ref.Ref{}}
return MapOfStringToValue{out, m.cs, &ref.Ref{}}
}

View File

@@ -30,13 +30,15 @@ func init() {
type StructWithRef struct {
_r RefOfSetOfFloat32
cs chunks.ChunkStore
ref *ref.Ref
}
func NewStructWithRef() StructWithRef {
func NewStructWithRef(cs chunks.ChunkStore) StructWithRef {
return StructWithRef{
_r: NewRefOfSetOfFloat32(ref.Ref{}),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -45,9 +47,10 @@ type StructWithRefDef struct {
R ref.Ref
}
func (def StructWithRefDef) New() StructWithRef {
func (def StructWithRefDef) New(cs chunks.ChunkStore) StructWithRef {
return StructWithRef{
_r: NewRefOfSetOfFloat32(def.R),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -68,9 +71,9 @@ func init() {
types.RegisterStruct(__typeForStructWithRef, builderForStructWithRef, readerForStructWithRef)
}
func builderForStructWithRef(values []types.Value) types.Value {
func builderForStructWithRef(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := StructWithRef{ref: &ref.Ref{}}
s := StructWithRef{ref: &ref.Ref{}, cs: cs}
s._r = values[i].(RefOfSetOfFloat32)
i++
return s
@@ -161,7 +164,7 @@ func builderForRefOfListOfString(r ref.Ref) types.Value {
return NewRefOfListOfString(r)
}
func (r RefOfListOfString) TargetValue(cs chunks.ChunkSource) ListOfString {
func (r RefOfListOfString) TargetValue(cs chunks.ChunkStore) ListOfString {
return types.ReadValue(r.target, cs).(ListOfString)
}
@@ -173,21 +176,22 @@ func (r RefOfListOfString) SetTargetValue(val ListOfString, cs chunks.ChunkSink)
type ListOfRefOfFloat32 struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfRefOfFloat32() ListOfRefOfFloat32 {
return ListOfRefOfFloat32{types.NewTypedList(__typeForListOfRefOfFloat32), &ref.Ref{}}
func NewListOfRefOfFloat32(cs chunks.ChunkStore) ListOfRefOfFloat32 {
return ListOfRefOfFloat32{types.NewTypedList(cs, __typeForListOfRefOfFloat32), cs, &ref.Ref{}}
}
type ListOfRefOfFloat32Def []ref.Ref
func (def ListOfRefOfFloat32Def) New() ListOfRefOfFloat32 {
func (def ListOfRefOfFloat32Def) New(cs chunks.ChunkStore) ListOfRefOfFloat32 {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = NewRefOfFloat32(d)
}
return ListOfRefOfFloat32{types.NewTypedList(__typeForListOfRefOfFloat32, l...), &ref.Ref{}}
return ListOfRefOfFloat32{types.NewTypedList(cs, __typeForListOfRefOfFloat32, l...), cs, &ref.Ref{}}
}
func (l ListOfRefOfFloat32) Def() ListOfRefOfFloat32Def {
@@ -228,8 +232,8 @@ func init() {
types.RegisterValue(__typeForListOfRefOfFloat32, builderForListOfRefOfFloat32, readerForListOfRefOfFloat32)
}
func builderForListOfRefOfFloat32(v types.Value) types.Value {
return ListOfRefOfFloat32{v.(types.List), &ref.Ref{}}
func builderForListOfRefOfFloat32(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfRefOfFloat32{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfRefOfFloat32(v types.Value) types.Value {
@@ -249,27 +253,27 @@ func (l ListOfRefOfFloat32) Get(i uint64) RefOfFloat32 {
}
func (l ListOfRefOfFloat32) Slice(idx uint64, end uint64) ListOfRefOfFloat32 {
return ListOfRefOfFloat32{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfRefOfFloat32{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfFloat32) Set(i uint64, val RefOfFloat32) ListOfRefOfFloat32 {
return ListOfRefOfFloat32{l.l.Set(i, val), &ref.Ref{}}
return ListOfRefOfFloat32{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfFloat32) Append(v ...RefOfFloat32) ListOfRefOfFloat32 {
return ListOfRefOfFloat32{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfRefOfFloat32{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfFloat32) Insert(idx uint64, v ...RefOfFloat32) ListOfRefOfFloat32 {
return ListOfRefOfFloat32{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfRefOfFloat32{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfFloat32) Remove(idx uint64, end uint64) ListOfRefOfFloat32 {
return ListOfRefOfFloat32{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfRefOfFloat32{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfFloat32) RemoveAt(idx uint64) ListOfRefOfFloat32 {
return ListOfRefOfFloat32{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfRefOfFloat32{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfRefOfFloat32) fromElemSlice(p []RefOfFloat32) []types.Value {
@@ -308,7 +312,7 @@ func (l ListOfRefOfFloat32) Filter(cb ListOfRefOfFloat32FilterCallback) ListOfRe
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(RefOfFloat32), i)
})
return ListOfRefOfFloat32{out, &ref.Ref{}}
return ListOfRefOfFloat32{out, l.cs, &ref.Ref{}}
}
// RefOfSetOfFloat32
@@ -360,7 +364,7 @@ func builderForRefOfSetOfFloat32(r ref.Ref) types.Value {
return NewRefOfSetOfFloat32(r)
}
func (r RefOfSetOfFloat32) TargetValue(cs chunks.ChunkSource) SetOfFloat32 {
func (r RefOfSetOfFloat32) TargetValue(cs chunks.ChunkStore) SetOfFloat32 {
return types.ReadValue(r.target, cs).(SetOfFloat32)
}
@@ -372,21 +376,22 @@ func (r RefOfSetOfFloat32) SetTargetValue(val SetOfFloat32, cs chunks.ChunkSink)
type ListOfString struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfString() ListOfString {
return ListOfString{types.NewTypedList(__typeForListOfString), &ref.Ref{}}
func NewListOfString(cs chunks.ChunkStore) ListOfString {
return ListOfString{types.NewTypedList(cs, __typeForListOfString), cs, &ref.Ref{}}
}
type ListOfStringDef []string
func (def ListOfStringDef) New() ListOfString {
func (def ListOfStringDef) New(cs chunks.ChunkStore) ListOfString {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = types.NewString(d)
}
return ListOfString{types.NewTypedList(__typeForListOfString, l...), &ref.Ref{}}
return ListOfString{types.NewTypedList(cs, __typeForListOfString, l...), cs, &ref.Ref{}}
}
func (l ListOfString) Def() ListOfStringDef {
@@ -427,8 +432,8 @@ func init() {
types.RegisterValue(__typeForListOfString, builderForListOfString, readerForListOfString)
}
func builderForListOfString(v types.Value) types.Value {
return ListOfString{v.(types.List), &ref.Ref{}}
func builderForListOfString(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfString{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfString(v types.Value) types.Value {
@@ -448,27 +453,27 @@ func (l ListOfString) Get(i uint64) string {
}
func (l ListOfString) Slice(idx uint64, end uint64) ListOfString {
return ListOfString{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfString{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfString) Set(i uint64, val string) ListOfString {
return ListOfString{l.l.Set(i, types.NewString(val)), &ref.Ref{}}
return ListOfString{l.l.Set(i, types.NewString(val)), l.cs, &ref.Ref{}}
}
func (l ListOfString) Append(v ...string) ListOfString {
return ListOfString{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfString{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfString) Insert(idx uint64, v ...string) ListOfString {
return ListOfString{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfString{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfString) Remove(idx uint64, end uint64) ListOfString {
return ListOfString{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfString{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfString) RemoveAt(idx uint64) ListOfString {
return ListOfString{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfString{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfString) fromElemSlice(p []string) []types.Value {
@@ -507,7 +512,7 @@ func (l ListOfString) Filter(cb ListOfStringFilterCallback) ListOfString {
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(types.String).String(), i)
})
return ListOfString{out, &ref.Ref{}}
return ListOfString{out, l.cs, &ref.Ref{}}
}
// RefOfFloat32
@@ -559,7 +564,7 @@ func builderForRefOfFloat32(r ref.Ref) types.Value {
return NewRefOfFloat32(r)
}
func (r RefOfFloat32) TargetValue(cs chunks.ChunkSource) float32 {
func (r RefOfFloat32) TargetValue(cs chunks.ChunkStore) float32 {
return float32(types.ReadValue(r.target, cs).(types.Float32))
}
@@ -571,23 +576,24 @@ func (r RefOfFloat32) SetTargetValue(val float32, cs chunks.ChunkSink) RefOfFloa
type SetOfFloat32 struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfFloat32() SetOfFloat32 {
return SetOfFloat32{types.NewTypedSet(__typeForSetOfFloat32), &ref.Ref{}}
func NewSetOfFloat32(cs chunks.ChunkStore) SetOfFloat32 {
return SetOfFloat32{types.NewTypedSet(cs, __typeForSetOfFloat32), cs, &ref.Ref{}}
}
type SetOfFloat32Def map[float32]bool
func (def SetOfFloat32Def) New() SetOfFloat32 {
func (def SetOfFloat32Def) New(cs chunks.ChunkStore) SetOfFloat32 {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = types.Float32(d)
i++
}
return SetOfFloat32{types.NewTypedSet(__typeForSetOfFloat32, l...), &ref.Ref{}}
return SetOfFloat32{types.NewTypedSet(cs, __typeForSetOfFloat32, l...), cs, &ref.Ref{}}
}
func (s SetOfFloat32) Def() SetOfFloat32Def {
@@ -629,8 +635,8 @@ func init() {
types.RegisterValue(__typeForSetOfFloat32, builderForSetOfFloat32, readerForSetOfFloat32)
}
func builderForSetOfFloat32(v types.Value) types.Value {
return SetOfFloat32{v.(types.Set), &ref.Ref{}}
func builderForSetOfFloat32(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfFloat32{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfFloat32(v types.Value) types.Value {
@@ -677,23 +683,23 @@ func (s SetOfFloat32) Filter(cb SetOfFloat32FilterCallback) SetOfFloat32 {
out := s.s.Filter(func(v types.Value) bool {
return cb(float32(v.(types.Float32)))
})
return SetOfFloat32{out, &ref.Ref{}}
return SetOfFloat32{out, s.cs, &ref.Ref{}}
}
func (s SetOfFloat32) Insert(p ...float32) SetOfFloat32 {
return SetOfFloat32{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfFloat32{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfFloat32) Remove(p ...float32) SetOfFloat32 {
return SetOfFloat32{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfFloat32{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfFloat32) Union(others ...SetOfFloat32) SetOfFloat32 {
return SetOfFloat32{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfFloat32{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfFloat32) Subtract(others ...SetOfFloat32) SetOfFloat32 {
return SetOfFloat32{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfFloat32{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfFloat32) Any() float32 {

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -11,23 +12,24 @@ import (
type SetOfBool struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfBool() SetOfBool {
return SetOfBool{types.NewTypedSet(__typeForSetOfBool), &ref.Ref{}}
func NewSetOfBool(cs chunks.ChunkStore) SetOfBool {
return SetOfBool{types.NewTypedSet(cs, __typeForSetOfBool), cs, &ref.Ref{}}
}
type SetOfBoolDef map[bool]bool
func (def SetOfBoolDef) New() SetOfBool {
func (def SetOfBoolDef) New(cs chunks.ChunkStore) SetOfBool {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = types.Bool(d)
i++
}
return SetOfBool{types.NewTypedSet(__typeForSetOfBool, l...), &ref.Ref{}}
return SetOfBool{types.NewTypedSet(cs, __typeForSetOfBool, l...), cs, &ref.Ref{}}
}
func (s SetOfBool) Def() SetOfBoolDef {
@@ -69,8 +71,8 @@ func init() {
types.RegisterValue(__typeForSetOfBool, builderForSetOfBool, readerForSetOfBool)
}
func builderForSetOfBool(v types.Value) types.Value {
return SetOfBool{v.(types.Set), &ref.Ref{}}
func builderForSetOfBool(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfBool{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfBool(v types.Value) types.Value {
@@ -117,23 +119,23 @@ func (s SetOfBool) Filter(cb SetOfBoolFilterCallback) SetOfBool {
out := s.s.Filter(func(v types.Value) bool {
return cb(bool(v.(types.Bool)))
})
return SetOfBool{out, &ref.Ref{}}
return SetOfBool{out, s.cs, &ref.Ref{}}
}
func (s SetOfBool) Insert(p ...bool) SetOfBool {
return SetOfBool{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfBool{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfBool) Remove(p ...bool) SetOfBool {
return SetOfBool{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfBool{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfBool) Union(others ...SetOfBool) SetOfBool {
return SetOfBool{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfBool{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfBool) Subtract(others ...SetOfBool) SetOfBool {
return SetOfBool{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfBool{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfBool) Any() bool {

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -39,14 +40,16 @@ type D struct {
_structField S
_enumField E
cs chunks.ChunkStore
ref *ref.Ref
}
func NewD() D {
func NewD(cs chunks.ChunkStore) D {
return D{
_structField: NewS(),
_structField: NewS(cs),
_enumField: NewE(),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -56,10 +59,11 @@ type DDef struct {
EnumField E
}
func (def DDef) New() D {
func (def DDef) New(cs chunks.ChunkStore) D {
return D{
_structField: def.StructField.New(),
_structField: def.StructField.New(cs),
_enumField: def.EnumField,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -81,9 +85,9 @@ func init() {
types.RegisterStruct(__typeForD, builderForD, readerForD)
}
func builderForD(values []types.Value) types.Value {
func builderForD(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := D{ref: &ref.Ref{}}
s := D{ref: &ref.Ref{}, cs: cs}
s._structField = values[i].(S)
i++
s._enumField = values[i].(E)
@@ -144,13 +148,15 @@ func (s D) SetEnumField(val E) D {
type DUser struct {
_Dfield D
cs chunks.ChunkStore
ref *ref.Ref
}
func NewDUser() DUser {
func NewDUser(cs chunks.ChunkStore) DUser {
return DUser{
_Dfield: NewD(),
_Dfield: NewD(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -159,9 +165,10 @@ type DUserDef struct {
Dfield DDef
}
func (def DUserDef) New() DUser {
func (def DUserDef) New(cs chunks.ChunkStore) DUser {
return DUser{
_Dfield: def.Dfield.New(),
_Dfield: def.Dfield.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -182,9 +189,9 @@ func init() {
types.RegisterStruct(__typeForDUser, builderForDUser, readerForDUser)
}
func builderForDUser(values []types.Value) types.Value {
func builderForDUser(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := DUser{ref: &ref.Ref{}}
s := DUser{ref: &ref.Ref{}, cs: cs}
s._Dfield = values[i].(D)
i++
return s

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -32,14 +33,16 @@ type S struct {
_s string
_b bool
cs chunks.ChunkStore
ref *ref.Ref
}
func NewS() S {
func NewS(cs chunks.ChunkStore) S {
return S{
_s: "",
_b: false,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -49,10 +52,11 @@ type SDef struct {
B bool
}
func (def SDef) New() S {
func (def SDef) New(cs chunks.ChunkStore) S {
return S{
_s: def.S,
_b: def.B,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -74,9 +78,9 @@ func init() {
types.RegisterStruct(__typeForS, builderForS, readerForS)
}
func builderForS(values []types.Value) types.Value {
func builderForS(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := S{ref: &ref.Ref{}}
s := S{ref: &ref.Ref{}, cs: cs}
s._s = values[i].(types.String).String()
i++
s._b = bool(values[i].(types.Bool))

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -31,14 +32,16 @@ type Struct struct {
_s string
_b bool
cs chunks.ChunkStore
ref *ref.Ref
}
func NewStruct() Struct {
func NewStruct(cs chunks.ChunkStore) Struct {
return Struct{
_s: "",
_b: false,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -48,10 +51,11 @@ type StructDef struct {
B bool
}
func (def StructDef) New() Struct {
func (def StructDef) New(cs chunks.ChunkStore) Struct {
return Struct{
_s: def.S,
_b: def.B,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -73,9 +77,9 @@ func init() {
types.RegisterStruct(__typeForStruct, builderForStruct, readerForStruct)
}
func builderForStruct(values []types.Value) types.Value {
func builderForStruct(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Struct{ref: &ref.Ref{}}
s := Struct{ref: &ref.Ref{}, cs: cs}
s._s = values[i].(types.String).String()
i++
s._b = bool(values[i].(types.Bool))
@@ -134,21 +138,22 @@ func (s Struct) SetB(val bool) Struct {
type ListOfStruct struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfStruct() ListOfStruct {
return ListOfStruct{types.NewTypedList(__typeForListOfStruct), &ref.Ref{}}
func NewListOfStruct(cs chunks.ChunkStore) ListOfStruct {
return ListOfStruct{types.NewTypedList(cs, __typeForListOfStruct), cs, &ref.Ref{}}
}
type ListOfStructDef []StructDef
func (def ListOfStructDef) New() ListOfStruct {
func (def ListOfStructDef) New(cs chunks.ChunkStore) ListOfStruct {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = d.New()
l[i] = d.New(cs)
}
return ListOfStruct{types.NewTypedList(__typeForListOfStruct, l...), &ref.Ref{}}
return ListOfStruct{types.NewTypedList(cs, __typeForListOfStruct, l...), cs, &ref.Ref{}}
}
func (l ListOfStruct) Def() ListOfStructDef {
@@ -189,8 +194,8 @@ func init() {
types.RegisterValue(__typeForListOfStruct, builderForListOfStruct, readerForListOfStruct)
}
func builderForListOfStruct(v types.Value) types.Value {
return ListOfStruct{v.(types.List), &ref.Ref{}}
func builderForListOfStruct(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfStruct{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfStruct(v types.Value) types.Value {
@@ -210,27 +215,27 @@ func (l ListOfStruct) Get(i uint64) Struct {
}
func (l ListOfStruct) Slice(idx uint64, end uint64) ListOfStruct {
return ListOfStruct{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfStruct{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfStruct) Set(i uint64, val Struct) ListOfStruct {
return ListOfStruct{l.l.Set(i, val), &ref.Ref{}}
return ListOfStruct{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfStruct) Append(v ...Struct) ListOfStruct {
return ListOfStruct{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfStruct{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfStruct) Insert(idx uint64, v ...Struct) ListOfStruct {
return ListOfStruct{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfStruct{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfStruct) Remove(idx uint64, end uint64) ListOfStruct {
return ListOfStruct{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfStruct{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfStruct) RemoveAt(idx uint64) ListOfStruct {
return ListOfStruct{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfStruct{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfStruct) fromElemSlice(p []Struct) []types.Value {
@@ -269,5 +274,5 @@ func (l ListOfStruct) Filter(cb ListOfStructFilterCallback) ListOfStruct {
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(Struct), i)
})
return ListOfStruct{out, &ref.Ref{}}
return ListOfStruct{out, l.cs, &ref.Ref{}}
}

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -33,12 +34,14 @@ type OptionalStruct struct {
_b bool
__optionalb bool
cs chunks.ChunkStore
ref *ref.Ref
}
func NewOptionalStruct() OptionalStruct {
func NewOptionalStruct(cs chunks.ChunkStore) OptionalStruct {
return OptionalStruct{
cs: cs,
ref: &ref.Ref{},
}
}
@@ -48,12 +51,13 @@ type OptionalStructDef struct {
B bool
}
func (def OptionalStructDef) New() OptionalStruct {
func (def OptionalStructDef) New(cs chunks.ChunkStore) OptionalStruct {
return OptionalStruct{
_s: def.S,
__optionals: true,
_b: def.B,
__optionalb: true,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -79,9 +83,9 @@ func init() {
types.RegisterStruct(__typeForOptionalStruct, builderForOptionalStruct, readerForOptionalStruct)
}
func builderForOptionalStruct(values []types.Value) types.Value {
func builderForOptionalStruct(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := OptionalStruct{ref: &ref.Ref{}}
s := OptionalStruct{ref: &ref.Ref{}, cs: cs}
s.__optionals = bool(values[i].(types.Bool))
i++
if s.__optionals {

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -55,10 +56,11 @@ type StructPrimitives struct {
_blob types.Blob
_value types.Value
cs chunks.ChunkStore
ref *ref.Ref
}
func NewStructPrimitives() StructPrimitives {
func NewStructPrimitives(cs chunks.ChunkStore) StructPrimitives {
return StructPrimitives{
_uint64: uint64(0),
_uint32: uint32(0),
@@ -75,6 +77,7 @@ func NewStructPrimitives() StructPrimitives {
_blob: types.NewEmptyBlob(),
_value: types.Bool(false),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -96,7 +99,7 @@ type StructPrimitivesDef struct {
Value types.Value
}
func (def StructPrimitivesDef) New() StructPrimitives {
func (def StructPrimitivesDef) New(cs chunks.ChunkStore) StructPrimitives {
return StructPrimitives{
_uint64: def.Uint64,
_uint32: def.Uint32,
@@ -112,6 +115,7 @@ func (def StructPrimitivesDef) New() StructPrimitives {
_string: def.String,
_blob: def.Blob,
_value: def.Value,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -145,9 +149,9 @@ func init() {
types.RegisterStruct(__typeForStructPrimitives, builderForStructPrimitives, readerForStructPrimitives)
}
func builderForStructPrimitives(values []types.Value) types.Value {
func builderForStructPrimitives(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := StructPrimitives{ref: &ref.Ref{}}
s := StructPrimitives{ref: &ref.Ref{}, cs: cs}
s._uint64 = uint64(values[i].(types.UInt64))
i++
s._uint32 = uint32(values[i].(types.UInt32))

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -29,13 +30,15 @@ func init() {
type Tree struct {
_children ListOfTree
cs chunks.ChunkStore
ref *ref.Ref
}
func NewTree() Tree {
func NewTree(cs chunks.ChunkStore) Tree {
return Tree{
_children: NewListOfTree(),
_children: NewListOfTree(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -44,9 +47,10 @@ type TreeDef struct {
Children ListOfTreeDef
}
func (def TreeDef) New() Tree {
func (def TreeDef) New(cs chunks.ChunkStore) Tree {
return Tree{
_children: def.Children.New(),
_children: def.Children.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -67,9 +71,9 @@ func init() {
types.RegisterStruct(__typeForTree, builderForTree, readerForTree)
}
func builderForTree(values []types.Value) types.Value {
func builderForTree(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := Tree{ref: &ref.Ref{}}
s := Tree{ref: &ref.Ref{}, cs: cs}
s._children = values[i].(ListOfTree)
i++
return s
@@ -115,21 +119,22 @@ func (s Tree) SetChildren(val ListOfTree) Tree {
type ListOfTree struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfTree() ListOfTree {
return ListOfTree{types.NewTypedList(__typeForListOfTree), &ref.Ref{}}
func NewListOfTree(cs chunks.ChunkStore) ListOfTree {
return ListOfTree{types.NewTypedList(cs, __typeForListOfTree), cs, &ref.Ref{}}
}
type ListOfTreeDef []TreeDef
func (def ListOfTreeDef) New() ListOfTree {
func (def ListOfTreeDef) New(cs chunks.ChunkStore) ListOfTree {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = d.New()
l[i] = d.New(cs)
}
return ListOfTree{types.NewTypedList(__typeForListOfTree, l...), &ref.Ref{}}
return ListOfTree{types.NewTypedList(cs, __typeForListOfTree, l...), cs, &ref.Ref{}}
}
func (l ListOfTree) Def() ListOfTreeDef {
@@ -170,8 +175,8 @@ func init() {
types.RegisterValue(__typeForListOfTree, builderForListOfTree, readerForListOfTree)
}
func builderForListOfTree(v types.Value) types.Value {
return ListOfTree{v.(types.List), &ref.Ref{}}
func builderForListOfTree(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfTree{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfTree(v types.Value) types.Value {
@@ -191,27 +196,27 @@ func (l ListOfTree) Get(i uint64) Tree {
}
func (l ListOfTree) Slice(idx uint64, end uint64) ListOfTree {
return ListOfTree{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfTree{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfTree) Set(i uint64, val Tree) ListOfTree {
return ListOfTree{l.l.Set(i, val), &ref.Ref{}}
return ListOfTree{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfTree) Append(v ...Tree) ListOfTree {
return ListOfTree{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfTree{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfTree) Insert(idx uint64, v ...Tree) ListOfTree {
return ListOfTree{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfTree{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfTree) Remove(idx uint64, end uint64) ListOfTree {
return ListOfTree{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfTree{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfTree) RemoveAt(idx uint64) ListOfTree {
return ListOfTree{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfTree{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfTree) fromElemSlice(p []Tree) []types.Value {
@@ -250,5 +255,5 @@ func (l ListOfTree) Filter(cb ListOfTreeFilterCallback) ListOfTree {
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(Tree), i)
})
return ListOfTree{out, &ref.Ref{}}
return ListOfTree{out, l.cs, &ref.Ref{}}
}

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -29,13 +30,15 @@ func init() {
type StructWithDupList struct {
_l ListOfUInt8
cs chunks.ChunkStore
ref *ref.Ref
}
func NewStructWithDupList() StructWithDupList {
func NewStructWithDupList(cs chunks.ChunkStore) StructWithDupList {
return StructWithDupList{
_l: NewListOfUInt8(),
_l: NewListOfUInt8(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -44,9 +47,10 @@ type StructWithDupListDef struct {
L ListOfUInt8Def
}
func (def StructWithDupListDef) New() StructWithDupList {
func (def StructWithDupListDef) New(cs chunks.ChunkStore) StructWithDupList {
return StructWithDupList{
_l: def.L.New(),
_l: def.L.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -67,9 +71,9 @@ func init() {
types.RegisterStruct(__typeForStructWithDupList, builderForStructWithDupList, readerForStructWithDupList)
}
func builderForStructWithDupList(values []types.Value) types.Value {
func builderForStructWithDupList(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := StructWithDupList{ref: &ref.Ref{}}
s := StructWithDupList{ref: &ref.Ref{}, cs: cs}
s._l = values[i].(ListOfUInt8)
i++
return s
@@ -110,3 +114,146 @@ func (s StructWithDupList) SetL(val ListOfUInt8) StructWithDupList {
s.ref = &ref.Ref{}
return s
}
// ListOfUInt8
type ListOfUInt8 struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfUInt8(cs chunks.ChunkStore) ListOfUInt8 {
return ListOfUInt8{types.NewTypedList(cs, __typeForListOfUInt8), cs, &ref.Ref{}}
}
type ListOfUInt8Def []uint8
func (def ListOfUInt8Def) New(cs chunks.ChunkStore) ListOfUInt8 {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = types.UInt8(d)
}
return ListOfUInt8{types.NewTypedList(cs, __typeForListOfUInt8, l...), cs, &ref.Ref{}}
}
func (l ListOfUInt8) Def() ListOfUInt8Def {
d := make([]uint8, l.Len())
for i := uint64(0); i < l.Len(); i++ {
d[i] = uint8(l.l.Get(i).(types.UInt8))
}
return d
}
func (l ListOfUInt8) Equals(other types.Value) bool {
return other != nil && __typeForListOfUInt8.Equals(other.Type()) && l.Ref() == other.Ref()
}
func (l ListOfUInt8) Ref() ref.Ref {
return types.EnsureRef(l.ref, l)
}
func (l ListOfUInt8) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, l.Type().Chunks()...)
chunks = append(chunks, l.l.Chunks()...)
return
}
func (l ListOfUInt8) ChildValues() []types.Value {
return append([]types.Value{}, l.l.ChildValues()...)
}
// A Noms Value that describes ListOfUInt8.
var __typeForListOfUInt8 types.Type
func (m ListOfUInt8) Type() types.Type {
return __typeForListOfUInt8
}
func init() {
__typeForListOfUInt8 = types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.UInt8Kind))
types.RegisterValue(__typeForListOfUInt8, builderForListOfUInt8, readerForListOfUInt8)
}
func builderForListOfUInt8(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfUInt8{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfUInt8(v types.Value) types.Value {
return v.(ListOfUInt8).l
}
func (l ListOfUInt8) Len() uint64 {
return l.l.Len()
}
func (l ListOfUInt8) Empty() bool {
return l.Len() == uint64(0)
}
func (l ListOfUInt8) Get(i uint64) uint8 {
return uint8(l.l.Get(i).(types.UInt8))
}
func (l ListOfUInt8) Slice(idx uint64, end uint64) ListOfUInt8 {
return ListOfUInt8{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfUInt8) Set(i uint64, val uint8) ListOfUInt8 {
return ListOfUInt8{l.l.Set(i, types.UInt8(val)), l.cs, &ref.Ref{}}
}
func (l ListOfUInt8) Append(v ...uint8) ListOfUInt8 {
return ListOfUInt8{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfUInt8) Insert(idx uint64, v ...uint8) ListOfUInt8 {
return ListOfUInt8{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfUInt8) Remove(idx uint64, end uint64) ListOfUInt8 {
return ListOfUInt8{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfUInt8) RemoveAt(idx uint64) ListOfUInt8 {
return ListOfUInt8{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfUInt8) fromElemSlice(p []uint8) []types.Value {
r := make([]types.Value, len(p))
for i, v := range p {
r[i] = types.UInt8(v)
}
return r
}
type ListOfUInt8IterCallback func(v uint8, i uint64) (stop bool)
func (l ListOfUInt8) Iter(cb ListOfUInt8IterCallback) {
l.l.Iter(func(v types.Value, i uint64) bool {
return cb(uint8(v.(types.UInt8)), i)
})
}
type ListOfUInt8IterAllCallback func(v uint8, i uint64)
func (l ListOfUInt8) IterAll(cb ListOfUInt8IterAllCallback) {
l.l.IterAll(func(v types.Value, i uint64) {
cb(uint8(v.(types.UInt8)), i)
})
}
func (l ListOfUInt8) IterAllP(concurrency int, cb ListOfUInt8IterAllCallback) {
l.l.IterAllP(concurrency, func(v types.Value, i uint64) {
cb(uint8(v.(types.UInt8)), i)
})
}
type ListOfUInt8FilterCallback func(v uint8, i uint64) (keep bool)
func (l ListOfUInt8) Filter(cb ListOfUInt8FilterCallback) ListOfUInt8 {
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(uint8(v.(types.UInt8)), i)
})
return ListOfUInt8{out, l.cs, &ref.Ref{}}
}

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -83,14 +84,16 @@ type ImportUser struct {
_importedStruct D
_enum LocalE
cs chunks.ChunkStore
ref *ref.Ref
}
func NewImportUser() ImportUser {
func NewImportUser(cs chunks.ChunkStore) ImportUser {
return ImportUser{
_importedStruct: NewD(),
_importedStruct: NewD(cs),
_enum: NewLocalE(),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -100,10 +103,11 @@ type ImportUserDef struct {
Enum LocalE
}
func (def ImportUserDef) New() ImportUser {
func (def ImportUserDef) New(cs chunks.ChunkStore) ImportUser {
return ImportUser{
_importedStruct: def.ImportedStruct.New(),
_importedStruct: def.ImportedStruct.New(cs),
_enum: def.Enum,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -125,9 +129,9 @@ func init() {
types.RegisterStruct(__typeForImportUser, builderForImportUser, readerForImportUser)
}
func builderForImportUser(values []types.Value) types.Value {
func builderForImportUser(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := ImportUser{ref: &ref.Ref{}}
s := ImportUser{ref: &ref.Ref{}, cs: cs}
s._importedStruct = values[i].(D)
i++
s._enum = values[i].(LocalE)
@@ -187,21 +191,22 @@ func (s ImportUser) SetEnum(val LocalE) ImportUser {
type ListOfD struct {
l types.List
cs chunks.ChunkStore
ref *ref.Ref
}
func NewListOfD() ListOfD {
return ListOfD{types.NewTypedList(__typeForListOfD), &ref.Ref{}}
func NewListOfD(cs chunks.ChunkStore) ListOfD {
return ListOfD{types.NewTypedList(cs, __typeForListOfD), cs, &ref.Ref{}}
}
type ListOfDDef []DDef
func (def ListOfDDef) New() ListOfD {
func (def ListOfDDef) New(cs chunks.ChunkStore) ListOfD {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = d.New()
l[i] = d.New(cs)
}
return ListOfD{types.NewTypedList(__typeForListOfD, l...), &ref.Ref{}}
return ListOfD{types.NewTypedList(cs, __typeForListOfD, l...), cs, &ref.Ref{}}
}
func (l ListOfD) Def() ListOfDDef {
@@ -242,8 +247,8 @@ func init() {
types.RegisterValue(__typeForListOfD, builderForListOfD, readerForListOfD)
}
func builderForListOfD(v types.Value) types.Value {
return ListOfD{v.(types.List), &ref.Ref{}}
func builderForListOfD(cs chunks.ChunkStore, v types.Value) types.Value {
return ListOfD{v.(types.List), cs, &ref.Ref{}}
}
func readerForListOfD(v types.Value) types.Value {
@@ -263,27 +268,27 @@ func (l ListOfD) Get(i uint64) D {
}
func (l ListOfD) Slice(idx uint64, end uint64) ListOfD {
return ListOfD{l.l.Slice(idx, end), &ref.Ref{}}
return ListOfD{l.l.Slice(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfD) Set(i uint64, val D) ListOfD {
return ListOfD{l.l.Set(i, val), &ref.Ref{}}
return ListOfD{l.l.Set(i, val), l.cs, &ref.Ref{}}
}
func (l ListOfD) Append(v ...D) ListOfD {
return ListOfD{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfD{l.l.Append(l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfD) Insert(idx uint64, v ...D) ListOfD {
return ListOfD{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
return ListOfD{l.l.Insert(idx, l.fromElemSlice(v)...), l.cs, &ref.Ref{}}
}
func (l ListOfD) Remove(idx uint64, end uint64) ListOfD {
return ListOfD{l.l.Remove(idx, end), &ref.Ref{}}
return ListOfD{l.l.Remove(idx, end), l.cs, &ref.Ref{}}
}
func (l ListOfD) RemoveAt(idx uint64) ListOfD {
return ListOfD{(l.l.RemoveAt(idx)), &ref.Ref{}}
return ListOfD{(l.l.RemoveAt(idx)), l.cs, &ref.Ref{}}
}
func (l ListOfD) fromElemSlice(p []D) []types.Value {
@@ -322,5 +327,5 @@ func (l ListOfD) Filter(cb ListOfDFilterCallback) ListOfD {
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(v.(D), i)
})
return ListOfD{out, &ref.Ref{}}
return ListOfD{out, l.cs, &ref.Ref{}}
}

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -35,16 +36,18 @@ type StructWithList struct {
_s string
_i int64
cs chunks.ChunkStore
ref *ref.Ref
}
func NewStructWithList() StructWithList {
func NewStructWithList(cs chunks.ChunkStore) StructWithList {
return StructWithList{
_l: NewListOfUInt8(),
_l: NewListOfUInt8(cs),
_b: false,
_s: "",
_i: int64(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -56,12 +59,13 @@ type StructWithListDef struct {
I int64
}
func (def StructWithListDef) New() StructWithList {
func (def StructWithListDef) New(cs chunks.ChunkStore) StructWithList {
return StructWithList{
_l: def.L.New(),
_l: def.L.New(cs),
_b: def.B,
_s: def.S,
_i: def.I,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -85,9 +89,9 @@ func init() {
types.RegisterStruct(__typeForStructWithList, builderForStructWithList, readerForStructWithList)
}
func builderForStructWithList(values []types.Value) types.Value {
func builderForStructWithList(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := StructWithList{ref: &ref.Ref{}}
s := StructWithList{ref: &ref.Ref{}, cs: cs}
s._l = values[i].(ListOfUInt8)
i++
s._b = bool(values[i].(types.Bool))
@@ -170,145 +174,3 @@ func (s StructWithList) SetI(val int64) StructWithList {
s.ref = &ref.Ref{}
return s
}
// ListOfUInt8
type ListOfUInt8 struct {
l types.List
ref *ref.Ref
}
func NewListOfUInt8() ListOfUInt8 {
return ListOfUInt8{types.NewTypedList(__typeForListOfUInt8), &ref.Ref{}}
}
type ListOfUInt8Def []uint8
func (def ListOfUInt8Def) New() ListOfUInt8 {
l := make([]types.Value, len(def))
for i, d := range def {
l[i] = types.UInt8(d)
}
return ListOfUInt8{types.NewTypedList(__typeForListOfUInt8, l...), &ref.Ref{}}
}
func (l ListOfUInt8) Def() ListOfUInt8Def {
d := make([]uint8, l.Len())
for i := uint64(0); i < l.Len(); i++ {
d[i] = uint8(l.l.Get(i).(types.UInt8))
}
return d
}
func (l ListOfUInt8) Equals(other types.Value) bool {
return other != nil && __typeForListOfUInt8.Equals(other.Type()) && l.Ref() == other.Ref()
}
func (l ListOfUInt8) Ref() ref.Ref {
return types.EnsureRef(l.ref, l)
}
func (l ListOfUInt8) Chunks() (chunks []ref.Ref) {
chunks = append(chunks, l.Type().Chunks()...)
chunks = append(chunks, l.l.Chunks()...)
return
}
func (l ListOfUInt8) ChildValues() []types.Value {
return append([]types.Value{}, l.l.ChildValues()...)
}
// A Noms Value that describes ListOfUInt8.
var __typeForListOfUInt8 types.Type
func (m ListOfUInt8) Type() types.Type {
return __typeForListOfUInt8
}
func init() {
__typeForListOfUInt8 = types.MakeCompoundType(types.ListKind, types.MakePrimitiveType(types.UInt8Kind))
types.RegisterValue(__typeForListOfUInt8, builderForListOfUInt8, readerForListOfUInt8)
}
func builderForListOfUInt8(v types.Value) types.Value {
return ListOfUInt8{v.(types.List), &ref.Ref{}}
}
func readerForListOfUInt8(v types.Value) types.Value {
return v.(ListOfUInt8).l
}
func (l ListOfUInt8) Len() uint64 {
return l.l.Len()
}
func (l ListOfUInt8) Empty() bool {
return l.Len() == uint64(0)
}
func (l ListOfUInt8) Get(i uint64) uint8 {
return uint8(l.l.Get(i).(types.UInt8))
}
func (l ListOfUInt8) Slice(idx uint64, end uint64) ListOfUInt8 {
return ListOfUInt8{l.l.Slice(idx, end), &ref.Ref{}}
}
func (l ListOfUInt8) Set(i uint64, val uint8) ListOfUInt8 {
return ListOfUInt8{l.l.Set(i, types.UInt8(val)), &ref.Ref{}}
}
func (l ListOfUInt8) Append(v ...uint8) ListOfUInt8 {
return ListOfUInt8{l.l.Append(l.fromElemSlice(v)...), &ref.Ref{}}
}
func (l ListOfUInt8) Insert(idx uint64, v ...uint8) ListOfUInt8 {
return ListOfUInt8{l.l.Insert(idx, l.fromElemSlice(v)...), &ref.Ref{}}
}
func (l ListOfUInt8) Remove(idx uint64, end uint64) ListOfUInt8 {
return ListOfUInt8{l.l.Remove(idx, end), &ref.Ref{}}
}
func (l ListOfUInt8) RemoveAt(idx uint64) ListOfUInt8 {
return ListOfUInt8{(l.l.RemoveAt(idx)), &ref.Ref{}}
}
func (l ListOfUInt8) fromElemSlice(p []uint8) []types.Value {
r := make([]types.Value, len(p))
for i, v := range p {
r[i] = types.UInt8(v)
}
return r
}
type ListOfUInt8IterCallback func(v uint8, i uint64) (stop bool)
func (l ListOfUInt8) Iter(cb ListOfUInt8IterCallback) {
l.l.Iter(func(v types.Value, i uint64) bool {
return cb(uint8(v.(types.UInt8)), i)
})
}
type ListOfUInt8IterAllCallback func(v uint8, i uint64)
func (l ListOfUInt8) IterAll(cb ListOfUInt8IterAllCallback) {
l.l.IterAll(func(v types.Value, i uint64) {
cb(uint8(v.(types.UInt8)), i)
})
}
func (l ListOfUInt8) IterAllP(concurrency int, cb ListOfUInt8IterAllCallback) {
l.l.IterAllP(concurrency, func(v types.Value, i uint64) {
cb(uint8(v.(types.UInt8)), i)
})
}
type ListOfUInt8FilterCallback func(v uint8, i uint64) (keep bool)
func (l ListOfUInt8) Filter(cb ListOfUInt8FilterCallback) ListOfUInt8 {
out := l.l.Filter(func(v types.Value, i uint64) bool {
return cb(uint8(v.(types.UInt8)), i)
})
return ListOfUInt8{out, &ref.Ref{}}
}

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -36,14 +37,16 @@ type StructWithUnionField struct {
_a float32
__unionIndex uint32
__unionValue types.Value
cs chunks.ChunkStore
ref *ref.Ref
}
func NewStructWithUnionField() StructWithUnionField {
func NewStructWithUnionField(cs chunks.ChunkStore) StructWithUnionField {
return StructWithUnionField{
_a: float32(0),
__unionIndex: 0,
__unionValue: types.Float64(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -54,11 +57,12 @@ type StructWithUnionFieldDef struct {
__unionValue types.Value
}
func (def StructWithUnionFieldDef) New() StructWithUnionField {
func (def StructWithUnionFieldDef) New(cs chunks.ChunkStore) StructWithUnionField {
return StructWithUnionField{
_a: def.A,
__unionIndex: def.__unionIndex,
__unionValue: def.__unionValue,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -81,9 +85,9 @@ func init() {
types.RegisterStruct(__typeForStructWithUnionField, builderForStructWithUnionField, readerForStructWithUnionField)
}
func builderForStructWithUnionField(values []types.Value) types.Value {
func builderForStructWithUnionField(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := StructWithUnionField{ref: &ref.Ref{}}
s := StructWithUnionField{ref: &ref.Ref{}, cs: cs}
s._a = float32(values[i].(types.Float32))
i++
s.__unionIndex = uint32(values[i].(types.UInt32))
@@ -153,7 +157,7 @@ func (def StructWithUnionFieldDef) B() (val float64, ok bool) {
return float64(def.__unionValue.(types.Float64)), true
}
func (def StructWithUnionFieldDef) SetB(val float64) StructWithUnionFieldDef {
func (def StructWithUnionFieldDef) SetB(cs chunks.ChunkStore, val float64) StructWithUnionFieldDef {
def.__unionIndex = 0
def.__unionValue = types.Float64(val)
return def
@@ -180,7 +184,7 @@ func (def StructWithUnionFieldDef) C() (val string, ok bool) {
return def.__unionValue.(types.String).String(), true
}
func (def StructWithUnionFieldDef) SetC(val string) StructWithUnionFieldDef {
func (def StructWithUnionFieldDef) SetC(cs chunks.ChunkStore, val string) StructWithUnionFieldDef {
def.__unionIndex = 1
def.__unionValue = types.NewString(val)
return def
@@ -207,7 +211,7 @@ func (def StructWithUnionFieldDef) D() (val types.Blob, ok bool) {
return def.__unionValue.(types.Blob), true
}
func (def StructWithUnionFieldDef) SetD(val types.Blob) StructWithUnionFieldDef {
func (def StructWithUnionFieldDef) SetD(cs chunks.ChunkStore, val types.Blob) StructWithUnionFieldDef {
def.__unionIndex = 2
def.__unionValue = val
return def
@@ -234,7 +238,7 @@ func (def StructWithUnionFieldDef) E() (val types.Value, ok bool) {
return def.__unionValue, true
}
func (def StructWithUnionFieldDef) SetE(val types.Value) StructWithUnionFieldDef {
func (def StructWithUnionFieldDef) SetE(cs chunks.ChunkStore, val types.Value) StructWithUnionFieldDef {
def.__unionIndex = 3
def.__unionValue = val
return def
@@ -261,9 +265,9 @@ func (def StructWithUnionFieldDef) F() (val SetOfUInt8Def, ok bool) {
return def.__unionValue.(SetOfUInt8).Def(), true
}
func (def StructWithUnionFieldDef) SetF(val SetOfUInt8Def) StructWithUnionFieldDef {
func (def StructWithUnionFieldDef) SetF(cs chunks.ChunkStore, val SetOfUInt8Def) StructWithUnionFieldDef {
def.__unionIndex = 4
def.__unionValue = val.New()
def.__unionValue = val.New(cs)
return def
}
@@ -271,23 +275,24 @@ func (def StructWithUnionFieldDef) SetF(val SetOfUInt8Def) StructWithUnionFieldD
type SetOfUInt8 struct {
s types.Set
cs chunks.ChunkStore
ref *ref.Ref
}
func NewSetOfUInt8() SetOfUInt8 {
return SetOfUInt8{types.NewTypedSet(__typeForSetOfUInt8), &ref.Ref{}}
func NewSetOfUInt8(cs chunks.ChunkStore) SetOfUInt8 {
return SetOfUInt8{types.NewTypedSet(cs, __typeForSetOfUInt8), cs, &ref.Ref{}}
}
type SetOfUInt8Def map[uint8]bool
func (def SetOfUInt8Def) New() SetOfUInt8 {
func (def SetOfUInt8Def) New(cs chunks.ChunkStore) SetOfUInt8 {
l := make([]types.Value, len(def))
i := 0
for d, _ := range def {
l[i] = types.UInt8(d)
i++
}
return SetOfUInt8{types.NewTypedSet(__typeForSetOfUInt8, l...), &ref.Ref{}}
return SetOfUInt8{types.NewTypedSet(cs, __typeForSetOfUInt8, l...), cs, &ref.Ref{}}
}
func (s SetOfUInt8) Def() SetOfUInt8Def {
@@ -329,8 +334,8 @@ func init() {
types.RegisterValue(__typeForSetOfUInt8, builderForSetOfUInt8, readerForSetOfUInt8)
}
func builderForSetOfUInt8(v types.Value) types.Value {
return SetOfUInt8{v.(types.Set), &ref.Ref{}}
func builderForSetOfUInt8(cs chunks.ChunkStore, v types.Value) types.Value {
return SetOfUInt8{v.(types.Set), cs, &ref.Ref{}}
}
func readerForSetOfUInt8(v types.Value) types.Value {
@@ -377,23 +382,23 @@ func (s SetOfUInt8) Filter(cb SetOfUInt8FilterCallback) SetOfUInt8 {
out := s.s.Filter(func(v types.Value) bool {
return cb(uint8(v.(types.UInt8)))
})
return SetOfUInt8{out, &ref.Ref{}}
return SetOfUInt8{out, s.cs, &ref.Ref{}}
}
func (s SetOfUInt8) Insert(p ...uint8) SetOfUInt8 {
return SetOfUInt8{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfUInt8{s.s.Insert(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfUInt8) Remove(p ...uint8) SetOfUInt8 {
return SetOfUInt8{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfUInt8{s.s.Remove(s.fromElemSlice(p)...), s.cs, &ref.Ref{}}
}
func (s SetOfUInt8) Union(others ...SetOfUInt8) SetOfUInt8 {
return SetOfUInt8{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfUInt8{s.s.Union(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfUInt8) Subtract(others ...SetOfUInt8) SetOfUInt8 {
return SetOfUInt8{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfUInt8{s.s.Subtract(s.fromStructSlice(others)...), s.cs, &ref.Ref{}}
}
func (s SetOfUInt8) Any() uint8 {

View File

@@ -3,6 +3,7 @@
package gen
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -45,14 +46,16 @@ type StructWithUnions struct {
_a __unionOfBOfFloat64AndCOfString
_d __unionOfEOfFloat64AndFOfString
cs chunks.ChunkStore
ref *ref.Ref
}
func NewStructWithUnions() StructWithUnions {
func NewStructWithUnions(cs chunks.ChunkStore) StructWithUnions {
return StructWithUnions{
_a: New__unionOfBOfFloat64AndCOfString(),
_d: New__unionOfEOfFloat64AndFOfString(),
_a: New__unionOfBOfFloat64AndCOfString(cs),
_d: New__unionOfEOfFloat64AndFOfString(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -62,10 +65,11 @@ type StructWithUnionsDef struct {
D __unionOfEOfFloat64AndFOfStringDef
}
func (def StructWithUnionsDef) New() StructWithUnions {
func (def StructWithUnionsDef) New(cs chunks.ChunkStore) StructWithUnions {
return StructWithUnions{
_a: def.A.New(),
_d: def.D.New(),
_a: def.A.New(cs),
_d: def.D.New(cs),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -87,9 +91,9 @@ func init() {
types.RegisterStruct(__typeForStructWithUnions, builderForStructWithUnions, readerForStructWithUnions)
}
func builderForStructWithUnions(values []types.Value) types.Value {
func builderForStructWithUnions(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := StructWithUnions{ref: &ref.Ref{}}
s := StructWithUnions{ref: &ref.Ref{}, cs: cs}
s._a = values[i].(__unionOfBOfFloat64AndCOfString)
i++
s._d = values[i].(__unionOfEOfFloat64AndFOfString)
@@ -151,13 +155,15 @@ func (s StructWithUnions) SetD(val __unionOfEOfFloat64AndFOfString) StructWithUn
type __unionOfBOfFloat64AndCOfString struct {
__unionIndex uint32
__unionValue types.Value
cs chunks.ChunkStore
ref *ref.Ref
}
func New__unionOfBOfFloat64AndCOfString() __unionOfBOfFloat64AndCOfString {
func New__unionOfBOfFloat64AndCOfString(cs chunks.ChunkStore) __unionOfBOfFloat64AndCOfString {
return __unionOfBOfFloat64AndCOfString{
__unionIndex: 0,
__unionValue: types.Float64(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -167,10 +173,11 @@ type __unionOfBOfFloat64AndCOfStringDef struct {
__unionValue types.Value
}
func (def __unionOfBOfFloat64AndCOfStringDef) New() __unionOfBOfFloat64AndCOfString {
func (def __unionOfBOfFloat64AndCOfStringDef) New(cs chunks.ChunkStore) __unionOfBOfFloat64AndCOfString {
return __unionOfBOfFloat64AndCOfString{
__unionIndex: def.__unionIndex,
__unionValue: def.__unionValue,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -192,9 +199,9 @@ func init() {
types.RegisterStruct(__typeFor__unionOfBOfFloat64AndCOfString, builderFor__unionOfBOfFloat64AndCOfString, readerFor__unionOfBOfFloat64AndCOfString)
}
func builderFor__unionOfBOfFloat64AndCOfString(values []types.Value) types.Value {
func builderFor__unionOfBOfFloat64AndCOfString(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := __unionOfBOfFloat64AndCOfString{ref: &ref.Ref{}}
s := __unionOfBOfFloat64AndCOfString{ref: &ref.Ref{}, cs: cs}
s.__unionIndex = uint32(values[i].(types.UInt32))
i++
s.__unionValue = values[i]
@@ -250,7 +257,7 @@ func (def __unionOfBOfFloat64AndCOfStringDef) B() (val float64, ok bool) {
return float64(def.__unionValue.(types.Float64)), true
}
func (def __unionOfBOfFloat64AndCOfStringDef) SetB(val float64) __unionOfBOfFloat64AndCOfStringDef {
func (def __unionOfBOfFloat64AndCOfStringDef) SetB(cs chunks.ChunkStore, val float64) __unionOfBOfFloat64AndCOfStringDef {
def.__unionIndex = 0
def.__unionValue = types.Float64(val)
return def
@@ -277,7 +284,7 @@ func (def __unionOfBOfFloat64AndCOfStringDef) C() (val string, ok bool) {
return def.__unionValue.(types.String).String(), true
}
func (def __unionOfBOfFloat64AndCOfStringDef) SetC(val string) __unionOfBOfFloat64AndCOfStringDef {
func (def __unionOfBOfFloat64AndCOfStringDef) SetC(cs chunks.ChunkStore, val string) __unionOfBOfFloat64AndCOfStringDef {
def.__unionIndex = 1
def.__unionValue = types.NewString(val)
return def
@@ -288,13 +295,15 @@ func (def __unionOfBOfFloat64AndCOfStringDef) SetC(val string) __unionOfBOfFloat
type __unionOfEOfFloat64AndFOfString struct {
__unionIndex uint32
__unionValue types.Value
cs chunks.ChunkStore
ref *ref.Ref
}
func New__unionOfEOfFloat64AndFOfString() __unionOfEOfFloat64AndFOfString {
func New__unionOfEOfFloat64AndFOfString(cs chunks.ChunkStore) __unionOfEOfFloat64AndFOfString {
return __unionOfEOfFloat64AndFOfString{
__unionIndex: 0,
__unionValue: types.Float64(0),
cs: cs,
ref: &ref.Ref{},
}
}
@@ -304,10 +313,11 @@ type __unionOfEOfFloat64AndFOfStringDef struct {
__unionValue types.Value
}
func (def __unionOfEOfFloat64AndFOfStringDef) New() __unionOfEOfFloat64AndFOfString {
func (def __unionOfEOfFloat64AndFOfStringDef) New(cs chunks.ChunkStore) __unionOfEOfFloat64AndFOfString {
return __unionOfEOfFloat64AndFOfString{
__unionIndex: def.__unionIndex,
__unionValue: def.__unionValue,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -329,9 +339,9 @@ func init() {
types.RegisterStruct(__typeFor__unionOfEOfFloat64AndFOfString, builderFor__unionOfEOfFloat64AndFOfString, readerFor__unionOfEOfFloat64AndFOfString)
}
func builderFor__unionOfEOfFloat64AndFOfString(values []types.Value) types.Value {
func builderFor__unionOfEOfFloat64AndFOfString(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := __unionOfEOfFloat64AndFOfString{ref: &ref.Ref{}}
s := __unionOfEOfFloat64AndFOfString{ref: &ref.Ref{}, cs: cs}
s.__unionIndex = uint32(values[i].(types.UInt32))
i++
s.__unionValue = values[i]
@@ -387,7 +397,7 @@ func (def __unionOfEOfFloat64AndFOfStringDef) E() (val float64, ok bool) {
return float64(def.__unionValue.(types.Float64)), true
}
func (def __unionOfEOfFloat64AndFOfStringDef) SetE(val float64) __unionOfEOfFloat64AndFOfStringDef {
func (def __unionOfEOfFloat64AndFOfStringDef) SetE(cs chunks.ChunkStore, val float64) __unionOfEOfFloat64AndFOfStringDef {
def.__unionIndex = 0
def.__unionValue = types.Float64(val)
return def
@@ -414,7 +424,7 @@ func (def __unionOfEOfFloat64AndFOfStringDef) F() (val string, ok bool) {
return def.__unionValue.(types.String).String(), true
}
func (def __unionOfEOfFloat64AndFOfStringDef) SetF(val string) __unionOfEOfFloat64AndFOfStringDef {
func (def __unionOfEOfFloat64AndFOfStringDef) SetF(cs chunks.ChunkStore, val string) __unionOfEOfFloat64AndFOfStringDef {
def.__unionIndex = 1
def.__unionValue = types.NewString(val)
return def

View File

@@ -5,26 +5,28 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
)
func TestListInt64Def(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.ListOfInt64Def{}
l := def.New()
l := def.New(cs)
def2 := l.Def()
l2 := def.New()
l2 := def.New(cs)
assert.Equal(def, def2)
assert.True(l.Equals(l2))
l3 := gen.NewListOfInt64()
l3 := gen.NewListOfInt64(cs)
assert.True(l.Equals(l3))
def3 := gen.ListOfInt64Def{0, 1, 2, 3, 4}
l4 := def3.New()
l4 := def3.New(cs)
assert.Equal(uint64(5), l4.Len())
assert.Equal(int64(0), l4.Get(0))
assert.Equal(int64(2), l4.Get(2))
@@ -36,7 +38,9 @@ func TestListInt64Def(t *testing.T) {
func TestListIter(t *testing.T) {
assert := assert.New(t)
l := gen.ListOfInt64Def{0, 1, 2, 3, 4}.New()
cs := chunks.NewMemoryStore()
l := gen.ListOfInt64Def{0, 1, 2, 3, 4}.New(cs)
acc := gen.ListOfInt64Def{}
i := uint64(0)
l.Iter(func(v int64, index uint64) (stop bool) {
@@ -51,10 +55,12 @@ func TestListIter(t *testing.T) {
func TestListIterAllP(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l := gen.ListOfInt64Def{0, 1, 2, 3, 4}
mu := sync.Mutex{}
visited := map[int64]bool{}
l.New().IterAllP(2, func(v int64, index uint64) {
l.New(cs).IterAllP(2, func(v int64, index uint64) {
assert.EqualValues(v, index)
mu.Lock()
defer mu.Unlock()
@@ -70,7 +76,9 @@ func TestListIterAllP(t *testing.T) {
func TestListFilter(t *testing.T) {
assert := assert.New(t)
l := gen.ListOfInt64Def{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.New()
cs := chunks.NewMemoryStore()
l := gen.ListOfInt64Def{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.New(cs)
i := uint64(0)
l2 := l.Filter(func(v int64, index uint64) bool {
assert.Equal(i, index)
@@ -82,8 +90,9 @@ func TestListFilter(t *testing.T) {
func TestListChunks(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l := gen.ListOfInt64Def{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.New()
cs := l.Chunks()
assert.Len(cs, 0)
l := gen.ListOfInt64Def{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.New(cs)
chunks := l.Chunks()
assert.Len(chunks, 0)
}

View File

@@ -4,15 +4,17 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
"github.com/attic-labs/noms/types"
)
func TestMapDef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.MapOfBoolToStringDef{true: "hi", false: "bye"}
m := def.New()
m := def.New(cs)
assert.Equal(uint64(2), m.Len())
assert.Equal("hi", m.Get(true))
@@ -21,15 +23,16 @@ func TestMapDef(t *testing.T) {
def2 := m.Def()
assert.Equal(def, def2)
m2 := gen.NewMapOfBoolToString().Set(true, "hi").Set(false, "bye")
m2 := gen.NewMapOfBoolToString(cs).Set(true, "hi").Set(false, "bye")
assert.True(m.Equals(m2))
}
func TestValueMapDef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.MapOfStringToValueDef{"s": types.NewString("s"), "i": types.Int32(42)}
m := def.New()
m := def.New(cs)
assert.Equal(uint64(2), m.Len())
assert.True(types.NewString("s").Equals(m.Get("s")))
@@ -38,31 +41,34 @@ func TestValueMapDef(t *testing.T) {
def2 := m.Def()
assert.Equal(def, def2)
m2 := gen.NewMapOfStringToValue().Set("s", types.NewString("s")).Set("i", types.Int32(42))
m2 := gen.NewMapOfStringToValue(cs).Set("s", types.NewString("s")).Set("i", types.Int32(42))
assert.True(m.Equals(m2))
}
func TestValueMapValue(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.MapOfStringToValueDef{"s": types.NewString("s"), "i": types.Int32(42)}
var m types.Value
m = def.New()
m = def.New(cs)
m2 := m.(gen.MapOfStringToValue)
assert.True(m.Equals(m2))
}
func TestMapIter(t *testing.T) {
assert := assert.New(t)
m := gen.MapOfBoolToStringDef{true: "hi", false: "bye"}.New()
acc := gen.NewMapOfBoolToString()
cs := chunks.NewMemoryStore()
m := gen.MapOfBoolToStringDef{true: "hi", false: "bye"}.New(cs)
acc := gen.NewMapOfBoolToString(cs)
m.Iter(func(k bool, v string) bool {
acc = acc.Set(k, v)
return false
})
assert.True(m.Equals(acc))
acc = gen.NewMapOfBoolToString()
acc = gen.NewMapOfBoolToString(cs)
m.Iter(func(k bool, v string) bool {
return true
})
@@ -71,8 +77,10 @@ func TestMapIter(t *testing.T) {
func TestMapIterAll(t *testing.T) {
assert := assert.New(t)
m := gen.MapOfBoolToStringDef{true: "hi", false: "bye"}.New()
acc := gen.NewMapOfBoolToString()
cs := chunks.NewMemoryStore()
m := gen.MapOfBoolToStringDef{true: "hi", false: "bye"}.New(cs)
acc := gen.NewMapOfBoolToString(cs)
m.IterAll(func(k bool, v string) {
acc = acc.Set(k, v)
})
@@ -81,21 +89,25 @@ func TestMapIterAll(t *testing.T) {
func TestMapFilter(t *testing.T) {
assert := assert.New(t)
m := gen.MapOfBoolToStringDef{true: "hi", false: "bye"}.New()
cs := chunks.NewMemoryStore()
m := gen.MapOfBoolToStringDef{true: "hi", false: "bye"}.New(cs)
m2 := m.Filter(func(k bool, v string) bool {
return k
})
assert.True(gen.NewMapOfBoolToString().Set(true, "hi").Equals(m2))
assert.True(gen.NewMapOfBoolToString(cs).Set(true, "hi").Equals(m2))
m3 := m.Filter(func(k bool, v string) bool {
return v == "bye"
})
assert.True(gen.NewMapOfBoolToString().Set(false, "bye").Equals(m3))
assert.True(gen.NewMapOfBoolToString(cs).Set(false, "bye").Equals(m3))
}
func TestMapMaybeGet(t *testing.T) {
assert := assert.New(t)
m := gen.NewMapOfStringToValue()
cs := chunks.NewMemoryStore()
m := gen.NewMapOfStringToValue(cs)
k1 := "key1"
k2 := "key2"
v1 := types.NewString("SomeValue")

View File

@@ -13,8 +13,8 @@ func TestRef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l := gen.ListOfStringDef{"a", "b", "c"}.New()
l2 := gen.ListOfStringDef{"d", "e", "f"}.New()
l := gen.ListOfStringDef{"a", "b", "c"}.New(cs)
l2 := gen.ListOfStringDef{"d", "e", "f"}.New(cs)
lRef := l.Ref()
r := gen.NewRefOfListOfString(lRef)
@@ -40,7 +40,7 @@ func TestListOfRef(t *testing.T) {
a := types.Float32(0)
ra := a.Ref()
l := gen.NewListOfRefOfFloat32()
l := gen.NewListOfRefOfFloat32(cs)
r := gen.NewRefOfFloat32(ra)
l = l.Append(r)
r2 := l.Get(0)
@@ -59,10 +59,10 @@ func TestStructWithRef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
set := gen.SetOfFloat32Def{0: true, 1: true, 2: true}.New()
set := gen.SetOfFloat32Def{0: true, 1: true, 2: true}.New(cs)
str := gen.StructWithRefDef{
R: set.Ref(),
}.New()
}.New(cs)
r := str.R()
r2 := gen.NewRefOfSetOfFloat32(set.Ref())
@@ -83,11 +83,12 @@ func TestStructWithRef(t *testing.T) {
func TestListOfRefChunks(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
a := types.Float32(0)
ra := a.Ref()
l := gen.NewListOfRefOfFloat32()
l := gen.NewListOfRefOfFloat32(cs)
r := gen.NewRefOfFloat32(ra)
assert.Len(l.Chunks(), 0)
@@ -98,11 +99,12 @@ func TestListOfRefChunks(t *testing.T) {
func TestStructWithRefChunks(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
set := gen.SetOfFloat32Def{0: true}.New()
set := gen.SetOfFloat32Def{0: true}.New(cs)
str := gen.StructWithRefDef{
R: set.Ref(),
}.New()
}.New(cs)
// 1 for the Type and 1 for the ref in the R field.
assert.Len(str.Chunks(), 2)

View File

@@ -4,14 +4,16 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
)
func TestSetDef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.SetOfBoolDef{true: true}
s := def.New()
s := def.New(cs)
assert.Equal(uint64(1), s.Len())
assert.True(s.Has(true))
@@ -20,22 +22,23 @@ func TestSetDef(t *testing.T) {
def2 := s.Def()
assert.Equal(def, def2)
s2 := gen.NewSetOfBool().Insert(true)
s2 := gen.NewSetOfBool(cs).Insert(true)
assert.True(s.Equals(s2))
}
func TestSetOfBoolIter(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
s := gen.NewSetOfBool().Insert(true, false)
acc := gen.NewSetOfBool()
s := gen.NewSetOfBool(cs).Insert(true, false)
acc := gen.NewSetOfBool(cs)
s.Iter(func(v bool) bool {
acc = acc.Insert(v)
return false
})
assert.True(s.Equals(acc))
acc = gen.NewSetOfBool()
acc = gen.NewSetOfBool(cs)
s.Iter(func(v bool) bool {
return true
})
@@ -44,9 +47,10 @@ func TestSetOfBoolIter(t *testing.T) {
func TestSetOfBoolIterAll(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
s := gen.NewSetOfBool().Insert(true, false)
acc := gen.NewSetOfBool()
s := gen.NewSetOfBool(cs).Insert(true, false)
acc := gen.NewSetOfBool(cs)
s.IterAll(func(v bool) {
acc = acc.Insert(v)
})
@@ -55,10 +59,11 @@ func TestSetOfBoolIterAll(t *testing.T) {
func TestSetOfBoolFilter(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
s := gen.NewSetOfBool().Insert(true, false)
s := gen.NewSetOfBool(cs).Insert(true, false)
s2 := s.Filter(func(v bool) bool {
return v
})
assert.True(gen.NewSetOfBool().Insert(true).Equals(s2))
assert.True(gen.NewSetOfBool(cs).Insert(true).Equals(s2))
}

View File

@@ -4,13 +4,15 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
)
func TestOptionalStruct(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
str := gen.NewOptionalStruct()
str := gen.NewOptionalStruct(cs)
_, ok := str.S()
assert.False(ok)
@@ -31,9 +33,10 @@ func TestOptionalStruct(t *testing.T) {
func TestOptionalStructDef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.OptionalStructDef{}
str := def.New()
str := def.New(cs)
s, ok := str.S()
assert.True(ok)
assert.Equal("", s)
@@ -48,8 +51,9 @@ func TestOptionalStructDef(t *testing.T) {
func TestOptionalStructDefFromNew(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
str := gen.NewOptionalStruct().SetB(true)
str := gen.NewOptionalStruct(cs).SetB(true)
def := str.Def()
def2 := gen.OptionalStructDef{B: true}
assert.Equal(def, def2)

View File

@@ -5,12 +5,14 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
"github.com/attic-labs/noms/types"
)
func TestAccessors(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.StructPrimitivesDef{
Uint64: uint64(1),
@@ -29,7 +31,7 @@ func TestAccessors(t *testing.T) {
Value: types.Bool(false),
}
st := def.New()
st := def.New(cs)
assert.Equal(uint64(1), st.Uint64())
st.SetUint64(uint64(11))

View File

@@ -4,11 +4,13 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
)
func TestStructRecursiveChildren(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
root := gen.TreeDef{
Children: []gen.TreeDef{
@@ -19,7 +21,7 @@ func TestStructRecursiveChildren(t *testing.T) {
},
},
},
}.New()
}.New(cs)
assert.Equal(uint64(2), root.Children().Len())
assert.Equal(uint64(0), root.Children().Get(0).Children().Len())

View File

@@ -4,23 +4,25 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
"github.com/attic-labs/noms/types"
)
func TestDef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.StructDef{"hi", true}
st := def.New()
st := def.New(cs)
def2 := st.Def()
st2 := def.New()
st2 := def.New(cs)
assert.Equal(def, def2)
assert.True(st.Equals(st2))
st3 := gen.NewStruct()
st3 := gen.NewStruct(cs)
st3 = st3.SetS("hi").SetB(true)
assert.Equal("hi", st3.S())
assert.Equal(true, st3.B())
@@ -28,19 +30,21 @@ func TestDef(t *testing.T) {
func TestValue(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.StructDef{"hi", true}
var st types.Value
st = def.New()
st = def.New(cs)
st2 := st.(gen.Struct)
assert.True(st.Equals(st2))
}
func TestType(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.StructDef{"hi", true}
st := def.New()
st := def.New(cs)
typ := st.Type()
assert.EqualValues(0, typ.Ordinal())
assert.Equal(types.UnresolvedKind, typ.Kind())
@@ -48,10 +52,11 @@ func TestType(t *testing.T) {
func TestStructChunks(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
st := gen.StructDef{"hi", true}.New()
cs := st.Chunks()
st := gen.StructDef{"hi", true}.New(cs)
chunks := st.Chunks()
// One chunk for the Type
assert.Len(cs, 1)
assert.Len(chunks, 1)
}

View File

@@ -4,11 +4,13 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
)
func TestStructWithDupList(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.StructWithListDef{
L: gen.ListOfUInt8Def{0, 1, 2},
@@ -17,11 +19,11 @@ func TestStructWithDupList(t *testing.T) {
I: 42,
}
st := def.New()
st := def.New(cs)
l := st.L()
assert.Equal(uint64(3), l.Len())
dupList := gen.NewStructWithDupList().SetL(st.L())
dupList := gen.NewStructWithDupList(cs).SetL(st.L())
assert.EqualValues(st.L(), dupList.L())
}

View File

@@ -4,12 +4,14 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
"github.com/attic-labs/noms/types"
)
func TestWithImportsDef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.ImportUserDef{
ImportedStruct: gen.DDef{
@@ -18,16 +20,16 @@ func TestWithImportsDef(t *testing.T) {
},
Enum: gen.LocalE1,
}
st := def.New()
st := def.New(cs)
def2 := st.Def()
st2 := def.New()
st2 := def.New(cs)
assert.Equal(def, def2)
assert.True(st.Equals(st2))
ds := gen.NewD().SetStructField(gen.NewS().SetS("hi").SetB(true)).SetEnumField(gen.E2)
st3 := gen.NewImportUser()
ds := gen.NewD(cs).SetStructField(gen.NewS(cs).SetS("hi").SetB(true)).SetEnumField(gen.E2)
st3 := gen.NewImportUser(cs)
st3 = st3.SetImportedStruct(ds).SetEnum(gen.LocalE1)
assert.True(st.Equals(st3))
ddef := st3.ImportedStruct().Def()
@@ -38,13 +40,15 @@ func TestWithImportsDef(t *testing.T) {
func TestListOfImportsDef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
lDef := gen.ListOfDDef{
gen.DDef{EnumField: gen.E3},
gen.DDef{EnumField: gen.E2},
gen.DDef{EnumField: gen.E1},
}
l := lDef.New()
l := lDef.New(cs)
assert.EqualValues(3, l.Len())
assert.EqualValues(gen.E3, l.Get(0).EnumField())
assert.EqualValues(gen.E2, l.Get(1).EnumField())
@@ -53,7 +57,9 @@ func TestListOfImportsDef(t *testing.T) {
func TestDepsAndPackageRefs(t *testing.T) {
assert := assert.New(t)
tr := gen.NewImportUser().ImportedStruct().Type()
cs := chunks.NewMemoryStore()
tr := gen.NewImportUser(cs).ImportedStruct().Type()
assert.Equal(types.UnresolvedKind, tr.Kind())
assert.True(tr.HasPackageRef())
p := types.LookupPackage(tr.PackageRef())

View File

@@ -11,6 +11,7 @@ import (
func TestStructWithList(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.StructWithListDef{
L: gen.ListOfUInt8Def{0, 1, 2},
@@ -19,7 +20,7 @@ func TestStructWithList(t *testing.T) {
I: 42,
}
st := def.New()
st := def.New(cs)
l := st.L()
assert.Equal(uint64(3), l.Len())
@@ -27,7 +28,7 @@ func TestStructWithList(t *testing.T) {
assert.Equal(def, def2)
def2.L[2] = 22
st2 := def2.New()
st2 := def2.New(cs)
assert.Equal(uint8(22), st2.L().Get(2))
}
@@ -39,14 +40,14 @@ func TestStructIsValue(t *testing.T) {
B: true,
S: "world",
I: 42,
}.New()
}.New(cs)
ref := types.WriteValue(v, cs)
v2 := types.ReadValue(ref, cs)
assert.True(v.Equals(v2))
s2 := v2.(gen.StructWithList)
assert.True(s2.L().Equals(gen.NewListOfUInt8().Append(0, 1, 2)))
assert.True(s2.L().Equals(gen.NewListOfUInt8(cs).Append(0, 1, 2)))
assert.True(s2.B())
assert.Equal("world", s2.S())
assert.Equal(int64(42), s2.I())

View File

@@ -4,34 +4,36 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
"github.com/attic-labs/noms/types"
)
func TestStructWithUnionField(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.StructWithUnionFieldDef{
A: float32(1),
}
def = def.SetC("s")
def = def.SetC(cs, "s")
_, ok := def.B()
assert.False(ok)
c, ok := def.C()
assert.True(ok)
assert.Equal("s", c)
st := def.New()
st := def.New(cs)
_, ok = st.F()
assert.False(ok)
c, ok = st.C()
assert.True(ok)
assert.Equal("s", c)
st2 := gen.NewStructWithUnionField().SetA(1).SetC("s")
st2 := gen.NewStructWithUnionField(cs).SetA(1).SetC("s")
assert.True(st.Equals(st2))
st3 := gen.NewStructWithUnionField().SetC("s").SetA(1)
st3 := gen.NewStructWithUnionField(cs).SetC("s").SetA(1)
assert.True(st.Equals(st3))
def2 := st3.Def()
@@ -40,8 +42,9 @@ func TestStructWithUnionField(t *testing.T) {
func TestStructWithUnionFieldListPart(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
st := gen.NewStructWithUnionField().SetF(gen.SetOfUInt8Def{2: true, 4: true}.New())
st := gen.NewStructWithUnionField(cs).SetF(gen.SetOfUInt8Def{2: true, 4: true}.New(cs))
f, ok := st.F()
assert.True(ok)
assert.True(f.Has(2))

View File

@@ -4,23 +4,25 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/nomdl/codegen/test/gen"
)
func TestStructWithUnions(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
def := gen.StructWithUnionsDef{}
def.A = def.A.SetB(42)
def.A = def.A.SetB(cs, 42)
b, ok := def.A.B()
assert.True(ok)
assert.Equal(float64(42), b)
def.D = def.D.SetF("hi")
def.D = def.D.SetF(cs, "hi")
f, ok := def.D.F()
assert.True(ok)
assert.Equal("hi", f)
st := def.New()
st := def.New(cs)
b, ok = st.A().B()
assert.True(ok)
assert.Equal(float64(42), b)
@@ -31,7 +33,7 @@ func TestStructWithUnions(t *testing.T) {
def2 := st.Def()
assert.Equal(def, def2)
st2 := gen.NewStructWithUnions()
st2 := gen.NewStructWithUnions(cs)
st2 = st2.SetA(st2.A().SetB(42)).SetD(st2.D().SetF("hi"))
assert.True(st.Equals(st2))

View File

@@ -3,6 +3,7 @@
package leafDep
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/types"
)
@@ -32,14 +33,16 @@ type S struct {
_s string
_b bool
cs chunks.ChunkStore
ref *ref.Ref
}
func NewS() S {
func NewS(cs chunks.ChunkStore) S {
return S{
_s: "",
_b: false,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -49,10 +52,11 @@ type SDef struct {
B bool
}
func (def SDef) New() S {
func (def SDef) New(cs chunks.ChunkStore) S {
return S{
_s: def.S,
_b: def.B,
cs: cs,
ref: &ref.Ref{},
}
}
@@ -74,9 +78,9 @@ func init() {
types.RegisterStruct(__typeForS, builderForS, readerForS)
}
func builderForS(values []types.Value) types.Value {
func builderForS(cs chunks.ChunkStore, values []types.Value) types.Value {
i := 0
s := S{ref: &ref.Ref{}}
s := S{ref: &ref.Ref{}, cs: cs}
s._s = values[i].(types.String).String()
i++
s._b = bool(values[i].(types.Bool))

View File

@@ -56,7 +56,7 @@ func builderForRefOfBlob(r ref.Ref) Value {
return NewRefOfBlob(r)
}
func (r RefOfBlob) TargetValue(cs chunks.ChunkSource) Blob {
func (r RefOfBlob) TargetValue(cs chunks.ChunkStore) Blob {
return ReadValue(r.target, cs).(Blob)
}

View File

@@ -14,16 +14,16 @@ import (
type compoundBlob struct {
metaSequenceObject
ref *ref.Ref
cs chunks.ChunkSource
cs chunks.ChunkStore
}
var typeForCompoundBlob = MakeCompoundType(MetaSequenceKind, MakePrimitiveType(BlobKind))
func newCompoundBlob(tuples metaSequenceData, cs chunks.ChunkSource) compoundBlob {
func newCompoundBlob(tuples metaSequenceData, cs chunks.ChunkStore) compoundBlob {
return buildCompoundBlob(tuples, typeForCompoundBlob, cs).(compoundBlob)
}
func buildCompoundBlob(tuples metaSequenceData, t Type, cs chunks.ChunkSource) Value {
func buildCompoundBlob(tuples metaSequenceData, t Type, cs chunks.ChunkStore) Value {
d.Chk.True(t.Equals(typeForCompoundBlob))
return compoundBlob{metaSequenceObject{tuples, typeForCompoundBlob}, &ref.Ref{}, cs}
}

View File

@@ -19,8 +19,8 @@ type compoundList struct {
cs chunks.ChunkStore
}
func buildCompoundList(tuples metaSequenceData, t Type, cs chunks.ChunkSource) Value {
return compoundList{metaSequenceObject{tuples, t}, &ref.Ref{}, cs.(chunks.ChunkStore)}
func buildCompoundList(tuples metaSequenceData, t Type, cs chunks.ChunkStore) Value {
return compoundList{metaSequenceObject{tuples, t}, &ref.Ref{}, cs}
}
func getListSequenceData(v Value) metaSequenceData {
@@ -145,7 +145,7 @@ func makeListLeafChunkFn(t Type, cs chunks.ChunkStore) makeChunkFn {
}
concreteType := t.Desc.(CompoundDesc).ElemTypes[0]
list := List{values, concreteType, &ref.Ref{}}
list := List{values, concreteType, &ref.Ref{}, cs}
ref := WriteValue(list, cs)
return metaTuple{ref, UInt64(len(values))}, list
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/attic-labs/noms/ref"
)
func fromTypedEncodeable(i []interface{}, cs chunks.ChunkSource) Value {
func fromTypedEncodeable(i []interface{}, cs chunks.ChunkStore) Value {
r := newJsonArrayReader(i, cs)
return r.readTopLevelValue()
}
@@ -18,10 +18,10 @@ func fromTypedEncodeable(i []interface{}, cs chunks.ChunkSource) Value {
type jsonArrayReader struct {
a []interface{}
i int
cs chunks.ChunkSource
cs chunks.ChunkStore
}
func newJsonArrayReader(a []interface{}, cs chunks.ChunkSource) *jsonArrayReader {
func newJsonArrayReader(a []interface{}, cs chunks.ChunkStore) *jsonArrayReader {
return &jsonArrayReader{a: a, i: 0, cs: cs}
}
@@ -101,7 +101,7 @@ func (r *jsonArrayReader) readList(t Type, pkg *Package) Value {
t = fixupType(t, pkg)
// TODO: Skip the List wrapper.
return valueFromType(newListNoCopy(data, t), t)
return valueFromType(r.cs, newListNoCopy(r.cs, data, t), t)
}
func (r *jsonArrayReader) readSet(t Type, pkg *Package) Value {
@@ -115,7 +115,7 @@ func (r *jsonArrayReader) readSet(t Type, pkg *Package) Value {
t = fixupType(t, pkg)
// TODO: Skip the Set wrapper.
return valueFromType(newSetFromData(data, t), t)
return valueFromType(r.cs, newSetFromData(r.cs, data, t), t)
}
func (r *jsonArrayReader) readMap(t Type, pkg *Package) Value {
@@ -132,7 +132,7 @@ func (r *jsonArrayReader) readMap(t Type, pkg *Package) Value {
t = fixupType(t, pkg)
// TODO: Skip the Map wrapper.
return valueFromType(newMapFromData(data, t), t)
return valueFromType(r.cs, newMapFromData(r.cs, data, t), t)
}
func indexTypeForMetaSequence(t Type) Type {
@@ -382,5 +382,5 @@ func (r *jsonArrayReader) readStruct(typeDef, typ Type, pkg *Package) Value {
}
typ = fixupType(typ, pkg)
return structBuilderForType(values, typ, typeDef)
return structBuilderForType(r.cs, values, typ, typeDef)
}

View File

@@ -97,7 +97,7 @@ func TestReadListOfInt32(t *testing.T) {
tr := MakeCompoundType(ListKind, MakePrimitiveType(Int32Kind))
l := r.readTopLevelValue()
l2 := NewTypedList(tr, Int32(0), Int32(1), Int32(2), Int32(3))
l2 := NewTypedList(cs, tr, Int32(0), Int32(1), Int32(2), Int32(3))
assert.True(l2.Equals(l))
}
@@ -108,7 +108,7 @@ func TestReadListOfValue(t *testing.T) {
a := parseJson(`[%d, %d, [%d, 1, %d, "hi", %d, true]]`, ListKind, ValueKind, Int32Kind, StringKind, BoolKind)
r := newJsonArrayReader(a, cs)
l := r.readTopLevelValue()
assert.True(NewList(Int32(1), NewString("hi"), Bool(true)).Equals(l))
assert.True(NewList(cs, Int32(1), NewString("hi"), Bool(true)).Equals(l))
}
func TestReadValueListOfInt8(t *testing.T) {
@@ -121,7 +121,7 @@ func TestReadValueListOfInt8(t *testing.T) {
tr := MakeCompoundType(ListKind, MakePrimitiveType(Int8Kind))
l := r.readTopLevelValue()
l2 := NewTypedList(tr, Int8(0), Int8(1), Int8(2))
l2 := NewTypedList(cs, tr, Int8(0), Int8(1), Int8(2))
assert.True(l2.Equals(l))
}
@@ -135,7 +135,7 @@ func TestReadMapOfInt64ToFloat64(t *testing.T) {
tr := MakeCompoundType(MapKind, MakePrimitiveType(Int64Kind), MakePrimitiveType(Float64Kind))
m := r.readTopLevelValue()
m2 := NewTypedMap(tr, Int64(0), Float64(1), Int64(2), Float64(3))
m2 := NewTypedMap(cs, tr, Int64(0), Float64(1), Int64(2), Float64(3))
assert.True(m2.Equals(m))
}
@@ -149,7 +149,7 @@ func TestReadValueMapOfUInt64ToUInt32(t *testing.T) {
mapTr := MakeCompoundType(MapKind, MakePrimitiveType(UInt64Kind), MakePrimitiveType(UInt32Kind))
m := r.readTopLevelValue()
m2 := NewTypedMap(mapTr, UInt64(0), UInt32(1), UInt64(2), UInt32(3))
m2 := NewTypedMap(cs, mapTr, UInt64(0), UInt32(1), UInt64(2), UInt32(3))
assert.True(m2.Equals(m))
}
@@ -163,7 +163,7 @@ func TestReadSetOfUInt8(t *testing.T) {
tr := MakeCompoundType(SetKind, MakePrimitiveType(UInt8Kind))
s := r.readTopLevelValue()
s2 := NewTypedSet(tr, UInt8(0), UInt8(1), UInt8(2), UInt8(3))
s2 := NewTypedSet(cs, tr, UInt8(0), UInt8(1), UInt8(2), UInt8(3))
assert.True(s2.Equals(s))
}
@@ -177,7 +177,7 @@ func TestReadValueSetOfUInt16(t *testing.T) {
setTr := MakeCompoundType(SetKind, MakePrimitiveType(UInt16Kind))
s := r.readTopLevelValue()
s2 := NewTypedSet(setTr, UInt16(0), UInt16(1), UInt16(2), UInt16(3))
s2 := NewTypedSet(cs, setTr, UInt16(0), UInt16(1), UInt16(2), UInt16(3))
assert.True(s2.Equals(s))
}
@@ -301,7 +301,7 @@ func TestReadStructWithList(t *testing.T) {
v := r.readTopLevelValue().(Struct)
assert.True(v.Get("b").Equals(Bool(true)))
l := NewTypedList(l32Tr, Int32(0), Int32(1), Int32(2))
l := NewTypedList(cs, l32Tr, Int32(0), Int32(1), Int32(2))
assert.True(v.Get("l").Equals(l))
assert.True(v.Get("s").Equals(NewString("hi")))
}

View File

@@ -44,7 +44,7 @@ func TestWriteList(t *testing.T) {
cs := chunks.NewMemoryStore()
typ := MakeCompoundType(ListKind, MakePrimitiveType(Int32Kind))
v := NewTypedList(typ, Int32(0), Int32(1), Int32(2), Int32(3))
v := NewTypedList(cs, typ, Int32(0), Int32(1), Int32(2), Int32(3))
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
@@ -57,9 +57,9 @@ func TestWriteListOfList(t *testing.T) {
it := MakeCompoundType(ListKind, MakePrimitiveType(Int16Kind))
typ := MakeCompoundType(ListKind, it)
l1 := NewTypedList(it, Int16(0))
l2 := NewTypedList(it, Int16(1), Int16(2), Int16(3))
v := NewTypedList(typ, l1, l2)
l1 := NewTypedList(cs, it, Int16(0))
l2 := NewTypedList(cs, it, Int16(1), Int16(2), Int16(3))
v := NewTypedList(cs, typ, l1, l2)
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
@@ -72,7 +72,7 @@ func TestWriteSet(t *testing.T) {
cs := chunks.NewMemoryStore()
typ := MakeCompoundType(SetKind, MakePrimitiveType(UInt32Kind))
v := NewTypedSet(typ, UInt32(3), UInt32(1), UInt32(2), UInt32(0))
v := NewTypedSet(cs, typ, UInt32(3), UInt32(1), UInt32(2), UInt32(0))
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
@@ -86,7 +86,7 @@ func TestWriteSetOfSet(t *testing.T) {
st := MakeCompoundType(SetKind, MakePrimitiveType(Int32Kind))
typ := MakeCompoundType(SetKind, st)
v := NewTypedSet(typ, NewTypedSet(st, Int32(0)), NewTypedSet(st, Int32(1), Int32(2), Int32(3)))
v := NewTypedSet(cs, typ, NewTypedSet(cs, st, Int32(0)), NewTypedSet(cs, st, Int32(1), Int32(2), Int32(3)))
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
@@ -99,7 +99,7 @@ func TestWriteMap(t *testing.T) {
cs := chunks.NewMemoryStore()
typ := MakeCompoundType(MapKind, MakePrimitiveType(StringKind), MakePrimitiveType(BoolKind))
v := NewTypedMap(typ, NewString("a"), Bool(false), NewString("b"), Bool(true))
v := NewTypedMap(cs, typ, NewString("a"), Bool(false), NewString("b"), Bool(true))
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
@@ -114,7 +114,7 @@ func TestWriteMapOfMap(t *testing.T) {
kt := MakeCompoundType(MapKind, MakePrimitiveType(StringKind), MakePrimitiveType(Int64Kind))
vt := MakeCompoundType(SetKind, MakePrimitiveType(BoolKind))
typ := MakeCompoundType(MapKind, kt, vt)
v := NewTypedMap(typ, NewTypedMap(kt, NewString("a"), Int64(0)), NewTypedSet(vt, Bool(true)))
v := NewTypedMap(cs, typ, NewTypedMap(cs, kt, NewString("a"), Int64(0)), NewTypedSet(cs, vt, Bool(true)))
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
@@ -232,12 +232,12 @@ func TestWriteStructWithList(t *testing.T) {
pkgRef := RegisterPackage(&pkg)
typ := MakeType(pkgRef, 0)
v := NewStruct(typ, typeDef, structData{"l": NewList(NewString("a"), NewString("b"))})
v := NewStruct(typ, typeDef, structData{"l": NewList(cs, NewString("a"), NewString("b"))})
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), []interface{}{"a", "b"}}, w.toArray())
v = NewStruct(typ, typeDef, structData{"l": NewList()})
v = NewStruct(typ, typeDef, structData{"l": NewList(cs)})
w = newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
assert.EqualValues([]interface{}{UnresolvedKind, pkgRef.String(), int16(0), []interface{}{}}, w.toArray())
@@ -305,7 +305,7 @@ func TestWriteListOfEnum(t *testing.T) {
pkgRef := RegisterPackage(&pkg)
et := MakeType(pkgRef, 0)
typ := MakeCompoundType(ListKind, et)
v := NewTypedList(typ, Enum{0, et}, Enum{1, et}, Enum{2, et})
v := NewTypedList(cs, typ, Enum{0, et}, Enum{1, et}, Enum{2, et})
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
@@ -318,7 +318,7 @@ func TestWriteListOfValue(t *testing.T) {
typ := MakeCompoundType(ListKind, MakePrimitiveType(ValueKind))
blob := NewMemoryBlob(bytes.NewBuffer([]byte{0x01}))
v := NewTypedList(typ,
v := NewTypedList(cs, typ,
Bool(true),
UInt8(1),
UInt16(1),
@@ -365,7 +365,7 @@ func TestWriteListOfValueWithStruct(t *testing.T) {
pkgRef := RegisterPackage(&pkg)
listType := MakeCompoundType(ListKind, MakePrimitiveType(ValueKind))
structType := MakeType(pkgRef, 0)
v := NewTypedList(listType, NewStruct(structType, typeDef, structData{"x": Int32(42)}))
v := NewTypedList(cs, listType, NewStruct(structType, typeDef, structData{"x": Int32(42)}))
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)
@@ -383,7 +383,7 @@ func TestWriteListOfValueWithType(t *testing.T) {
pkgRef := RegisterPackage(&pkg)
typ := MakeCompoundType(ListKind, MakePrimitiveType(ValueKind))
v := NewTypedList(typ,
v := NewTypedList(cs, typ,
Bool(true),
MakePrimitiveType(Int32Kind),
MakePrimitiveType(TypeKind),
@@ -475,7 +475,7 @@ func TestWriteListOfTypes(t *testing.T) {
cs := chunks.NewMemoryStore()
typ := MakeCompoundType(ListKind, MakePrimitiveType(TypeKind))
v := NewTypedList(typ, MakePrimitiveType(BoolKind), MakeEnumType("E", "a", "b", "c"), MakePrimitiveType(StringKind))
v := NewTypedList(cs, typ, MakePrimitiveType(BoolKind), MakeEnumType("E", "a", "b", "c"), MakePrimitiveType(StringKind))
w := newJsonArrayWriter(cs)
w.writeTopLevelValue(v)

View File

@@ -10,6 +10,7 @@ import (
func TestValueEquals(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
r1 := UInt16(1).Ref()
r2 := UInt16(2).Ref()
@@ -62,13 +63,13 @@ func TestValueEquals(t *testing.T) {
b2 := NewBlob(bytes.NewBufferString("bye"), ms)
return newCompoundBlob([]metaTuple{{WriteValue(b1, ms), UInt64(uint64(2))}, {WriteValue(b2, ms), UInt64(uint64(5))}}, ms)
},
func() Value { return NewList() },
func() Value { return NewList(NewString("foo")) },
func() Value { return NewList(NewString("bar")) },
func() Value { return NewMap() },
func() Value { return NewMap(NewString("a"), NewString("a")) },
func() Value { return NewSet() },
func() Value { return NewSet(NewString("hi")) },
func() Value { return NewList(cs) },
func() Value { return NewList(cs, NewString("foo")) },
func() Value { return NewList(cs, NewString("bar")) },
func() Value { return NewMap(cs) },
func() Value { return NewMap(cs, NewString("a"), NewString("a")) },
func() Value { return NewSet(cs) },
func() Value { return NewSet(cs, NewString("hi")) },
func() Value { return MakePrimitiveType(BoolKind) },
func() Value { return MakePrimitiveType(StringKind) },

View File

@@ -50,10 +50,10 @@ func TestEnsureRef(t *testing.T) {
values := []Value{
newBlobLeaf([]byte{}),
cb,
NewList(),
NewList(cs),
NewString(""),
NewMap(),
NewSet(),
NewMap(cs),
NewSet(cs),
}
for i := 0; i < 2; i++ {
for j, v := range values {

View File

@@ -23,9 +23,9 @@ var (
NewString("hi"),
newBlobLeaf([]byte("hi")),
// compoundBlob
NewSet(NewString("hi")),
NewList(NewString("hi")),
NewMap(NewString("hi"), NewString("hi")),
NewSet(chunks.NewMemoryStore(), NewString("hi")),
NewList(chunks.NewMemoryStore(), NewString("hi")),
NewMap(chunks.NewMemoryStore(), NewString("hi"), NewString("hi")),
}
)
@@ -41,7 +41,7 @@ func TestIncrementalLoadList(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
expected := NewList(testVals...)
expected := NewList(cs, testVals...)
ref := WriteValue(expected, cs)
actualVar := ReadValue(ref, cs)
@@ -68,7 +68,7 @@ func SkipTestIncrementalLoadSet(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
expected := NewSet(testVals...)
expected := NewSet(cs, testVals...)
ref := WriteValue(expected, cs)
actualVar := ReadValue(ref, cs)
@@ -87,7 +87,7 @@ func SkipTestIncrementalLoadMap(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
expected := NewMap(testVals...)
expected := NewMap(cs, testVals...)
ref := WriteValue(expected, cs)
actualVar := ReadValue(ref, cs)
@@ -110,7 +110,7 @@ func SkipTestIncrementalAddRef(t *testing.T) {
expectedItem := UInt32(42)
ref := WriteValue(expectedItem, cs)
expected := NewList(NewRef(ref))
expected := NewList(cs, NewRef(ref))
ref = WriteValue(expected, cs)
actualVar := ReadValue(ref, cs)

View File

@@ -6,30 +6,32 @@ import (
"github.com/attic-labs/noms/d"
"github.com/attic-labs/noms/ref"
"github.com/attic-labs/noms/chunks"
)
type List struct {
values []Value
t Type
ref *ref.Ref
cs chunks.ChunkStore
}
var listType = MakeCompoundType(ListKind, MakePrimitiveType(ValueKind))
func NewList(v ...Value) List {
return NewTypedList(listType, v...)
func NewList(cs chunks.ChunkStore, v ...Value) List {
return NewTypedList(cs, listType, v...)
}
func NewTypedList(t Type, v ...Value) List {
func NewTypedList(cs chunks.ChunkStore, t Type, v ...Value) List {
// Copy because Noms values are supposed to be immutable and Go allows v to be reused (thus mutable).
values := make([]Value, len(v))
copy(values, v)
return newListNoCopy(values, t)
return newListNoCopy(cs, values, t)
}
func newListNoCopy(values []Value, t Type) List {
func newListNoCopy(cs chunks.ChunkStore, values []Value, t Type) List {
d.Chk.Equal(ListKind, t.Kind())
return List{values, t, &ref.Ref{}}
return List{values, t, &ref.Ref{}, cs}
}
func (l List) Len() uint64 {
@@ -99,7 +101,7 @@ func (l List) Filter(cb listFilterCallback) List {
data = append(data, v)
}
}
return newListNoCopy(data, l.t)
return newListNoCopy(l.cs, data, l.t)
}
type MapFunc func(v Value, index uint64) interface{}
@@ -144,7 +146,7 @@ func (l List) mapInternal(sem chan int, mf MapFunc, offset uint64) []interface{}
}
func (l List) Slice(start uint64, end uint64) List {
return newListNoCopy(l.values[start:end], l.t)
return newListNoCopy(l.cs, l.values[start:end], l.t)
}
func (l List) Set(idx uint64, v Value) List {
@@ -152,13 +154,13 @@ func (l List) Set(idx uint64, v Value) List {
values := make([]Value, len(l.values))
copy(values, l.values)
values[idx] = v
return newListNoCopy(values, l.t)
return newListNoCopy(l.cs, values, l.t)
}
func (l List) Append(v ...Value) List {
assertType(l.elemType(), v...)
values := append(l.values, v...)
return newListNoCopy(values, l.t)
return newListNoCopy(l.cs, values, l.t)
}
func (l List) Insert(idx uint64, v ...Value) List {
@@ -167,14 +169,14 @@ func (l List) Insert(idx uint64, v ...Value) List {
copy(values, l.values[:idx])
copy(values[idx:], v)
copy(values[idx+uint64(len(v)):], l.values[idx:])
return newListNoCopy(values, l.t)
return newListNoCopy(l.cs, values, l.t)
}
func (l List) Remove(start uint64, end uint64) List {
values := make([]Value, uint64(len(l.values))-(end-start))
copy(values, l.values[:start])
copy(values[start:], l.values[end:])
return newListNoCopy(values, l.t)
return newListNoCopy(l.cs, values, l.t)
}
func (l List) RemoveAt(idx uint64) List {

View File

@@ -4,13 +4,15 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
)
func TestListLeafIterator(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l := NewList(Int32(0), Int32(1), Int32(2), Int32(3), Int32(4))
l2 := NewList()
l := NewList(cs, Int32(0), Int32(1), Int32(2), Int32(3), Int32(4))
l2 := NewList(cs)
it := newListIterator(l)
i := 0
for v, done := it.next(); !done; v, done = it.next() {
@@ -24,9 +26,10 @@ func TestListLeafIterator(t *testing.T) {
func TestListLeafIteratorAt(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l := NewList(Int32(0), Int32(1), Int32(2), Int32(3), Int32(4))
l2 := NewList()
l := NewList(cs, Int32(0), Int32(1), Int32(2), Int32(3), Int32(4))
l2 := NewList(cs)
it := newListIteratorAt(l, 2)
i := 2
for v, done := it.next(); !done; v, done = it.next() {
@@ -40,14 +43,15 @@ func TestListLeafIteratorAt(t *testing.T) {
func TestCompoundListIterator(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
uint8List := make([]Value, 256)
for i, _ := range uint8List {
uint8List[i] = UInt8(i)
}
l := NewList(uint8List...)
l2 := NewList()
l := NewList(cs, uint8List...)
l2 := NewList(cs)
it := newListIterator(l)
i := 0
for v, done := it.next(); !done; v, done = it.next() {
@@ -61,14 +65,15 @@ func TestCompoundListIterator(t *testing.T) {
func TestCompoundListIteratorAt(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
uint8List := make([]Value, 256)
for i, _ := range uint8List {
uint8List[i] = UInt8(i)
}
l := NewList(uint8List...)
l2 := NewList()
l := NewList(cs, uint8List...)
l2 := NewList(cs)
it := newListIteratorAt(l, 100)
i := 100
for v, done := it.next(); !done; v, done = it.next() {

View File

@@ -6,12 +6,14 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
)
func TestListLen(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l := NewList()
l := NewList(cs)
assert.Equal(uint64(0), l.Len())
l = l.Append(Bool(true))
assert.Equal(uint64(1), l.Len())
@@ -21,8 +23,9 @@ func TestListLen(t *testing.T) {
func TestListEmpty(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l := NewList()
l := NewList(cs)
assert.True(l.Empty())
l = l.Append(Bool(true))
assert.False(l.Empty())
@@ -32,8 +35,9 @@ func TestListEmpty(t *testing.T) {
func TestListGet(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l := NewList()
l := NewList(cs)
l = l.Append(Int32(0), Int32(1), Int32(2))
assert.Equal(Int32(0), l.Get(0))
assert.Equal(Int32(1), l.Get(1))
@@ -46,7 +50,9 @@ func TestListGet(t *testing.T) {
func TestListSlice(t *testing.T) {
assert := assert.New(t)
l1 := NewList()
cs := chunks.NewMemoryStore()
l1 := NewList(cs)
l1 = l1.Append(Int32(0), Int32(1), Int32(2), Int32(3))
l2 := l1.Slice(1, 3)
assert.Equal(uint64(4), l1.Len())
@@ -74,7 +80,9 @@ func TestListSlice(t *testing.T) {
func TestListSet(t *testing.T) {
assert := assert.New(t)
l0 := NewList()
cs := chunks.NewMemoryStore()
l0 := NewList(cs)
l0 = l0.Append(Float32(0.0))
l1 := l0.Set(uint64(0), Float32(1.0))
assert.Equal(Float32(1.0), l1.Get(0))
@@ -86,8 +94,9 @@ func TestListSet(t *testing.T) {
func TestListAppend(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l0 := NewList()
l0 := NewList(cs)
l1 := l0.Append(Bool(false))
assert.Equal(uint64(0), l0.Len())
assert.Equal(uint64(1), l1.Len())
@@ -97,15 +106,16 @@ func TestListAppend(t *testing.T) {
l2 := l1.Append(Bool(true), Bool(true))
assert.Equal(uint64(3), l2.Len())
assert.Equal(Bool(false), l2.Get(0))
assert.True(NewList(Bool(true), Bool(true)).Equals(l2.Slice(1, l2.Len())))
assert.True(NewList(cs, Bool(true), Bool(true)).Equals(l2.Slice(1, l2.Len())))
assert.Equal(uint64(1), l1.Len())
}
func TestListInsert(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
// Insert(0, v1)
l0 := NewList()
l0 := NewList(cs)
l1 := l0.Insert(uint64(0), Int32(-1))
assert.Equal(uint64(0), l0.Len())
assert.Equal(uint64(1), l1.Len())
@@ -115,7 +125,7 @@ func TestListInsert(t *testing.T) {
l2 := l1.Insert(0, Int32(-3), Int32(-2))
assert.Equal(uint64(3), l2.Len())
assert.Equal(Int32(-1), l2.Get(2))
assert.True(NewList(Int32(-3), Int32(-2)).Equals(l2.Slice(0, 2)))
assert.True(NewList(cs, Int32(-3), Int32(-2)).Equals(l2.Slice(0, 2)))
assert.Equal(uint64(1), l1.Len())
// Insert(2, v3)
@@ -129,7 +139,9 @@ func TestListInsert(t *testing.T) {
func TestListRemove(t *testing.T) {
assert := assert.New(t)
l0 := NewList()
cs := chunks.NewMemoryStore()
l0 := NewList(cs)
l0 = l0.Remove(0, 0)
assert.Equal(uint64(0), l0.Len())
@@ -137,13 +149,13 @@ func TestListRemove(t *testing.T) {
l1 := l0.Remove(1, 3)
assert.Equal(uint64(4), l0.Len())
assert.Equal(uint64(2), l1.Len())
assert.True(NewList(Bool(false), Bool(false)).Equals(l1))
assert.True(NewList(cs, Bool(false), Bool(false)).Equals(l1))
l1 = l1.Remove(1, 2)
assert.True(NewList(Bool(false)).Equals(l1))
assert.True(NewList(cs, Bool(false)).Equals(l1))
l1 = l1.Remove(0, 1)
assert.True(NewList().Equals(l1))
assert.True(NewList(cs).Equals(l1))
assert.Panics(func() {
l1.Remove(0, 1)
@@ -152,12 +164,14 @@ func TestListRemove(t *testing.T) {
func TestListRemoveAt(t *testing.T) {
assert := assert.New(t)
l0 := NewList()
cs := chunks.NewMemoryStore()
l0 := NewList(cs)
l0 = l0.Append(Bool(false), Bool(true))
l1 := l0.RemoveAt(1)
assert.True(NewList(Bool(false)).Equals(l1))
assert.True(NewList(cs, Bool(false)).Equals(l1))
l1 = l1.RemoveAt(0)
assert.True(NewList().Equals(l1))
assert.True(NewList(cs).Equals(l1))
assert.Panics(func() {
l1.RemoveAt(0)
@@ -166,6 +180,7 @@ func TestListRemoveAt(t *testing.T) {
func TestListMap(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
testMap := func(concurrency, listLen int) {
values := make([]Value, listLen)
@@ -173,7 +188,7 @@ func TestListMap(t *testing.T) {
values[i] = Int64(i)
}
l := NewList(values...)
l := NewList(cs, values...)
cur := 0
mu := sync.Mutex{}
@@ -224,8 +239,9 @@ func TestListMap(t *testing.T) {
func TestListIter(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l := NewList(Int32(0), Int32(1), Int32(2), Int32(3), Int32(4))
l := NewList(cs, Int32(0), Int32(1), Int32(2), Int32(3), Int32(4))
acc := []int32{}
i := uint64(0)
l.Iter(func(v Value, index uint64) bool {
@@ -236,7 +252,7 @@ func TestListIter(t *testing.T) {
})
assert.Equal([]int32{0, 1, 2}, acc)
cl := NewList(NewString("a"), NewString("b"), NewString("c"), NewString("d"), NewString("e"), NewString("f"))
cl := NewList(cs, NewString("a"), NewString("b"), NewString("c"), NewString("d"), NewString("e"), NewString("f"))
acc2 := []string{}
cl.Iter(func(v Value, i uint64) bool {
acc2 = append(acc2, v.(String).String())
@@ -258,8 +274,9 @@ func TestListIter(t *testing.T) {
func TestListIterAll(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l := NewList(Int32(0), Int32(1), Int32(2), Int32(3), Int32(4))
l := NewList(cs, Int32(0), Int32(1), Int32(2), Int32(3), Int32(4))
acc := []int32{}
i := uint64(0)
l.IterAll(func(v Value, index uint64) {
@@ -269,7 +286,7 @@ func TestListIterAll(t *testing.T) {
})
assert.Equal([]int32{0, 1, 2, 3, 4}, acc)
cl := NewList(NewString("a"), NewString("b"), NewString("c"), NewString("d"), NewString("e"), NewString("f"))
cl := NewList(cs, NewString("a"), NewString("b"), NewString("c"), NewString("d"), NewString("e"), NewString("f"))
acc2 := []string{}
cl.IterAll(func(v Value, i uint64) {
acc2 = append(acc2, v.(String).String())
@@ -279,6 +296,7 @@ func TestListIterAll(t *testing.T) {
func TestListIterAllP(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
testIter := func(concurrency, listLen int) {
values := make([]Value, listLen)
@@ -286,7 +304,7 @@ func TestListIterAllP(t *testing.T) {
values[i] = Int64(i)
}
l := NewList(values...)
l := NewList(cs, values...)
cur := 0
mu := sync.Mutex{}
@@ -335,11 +353,13 @@ func TestListIterAllP(t *testing.T) {
func TestListType(t *testing.T) {
assert := assert.New(t)
l := NewList(Int32(0))
cs := chunks.NewMemoryStore()
l := NewList(cs, Int32(0))
assert.True(l.Type().Equals(MakeCompoundType(ListKind, MakePrimitiveType(ValueKind))))
tr := MakeCompoundType(ListKind, MakePrimitiveType(UInt8Kind))
l2 := newListNoCopy([]Value{UInt8(0), UInt8(1)}, tr)
l2 := newListNoCopy(cs, []Value{UInt8(0), UInt8(1)}, tr)
assert.Equal(tr, l2.Type())
l3 := l2.Slice(0, 1)
@@ -363,16 +383,17 @@ func TestListType(t *testing.T) {
func TestListChunks(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l1 := NewList(Int32(0))
l1 := NewList(cs, Int32(0))
c1 := l1.Chunks()
assert.Len(c1, 0)
l2 := NewList(NewRef(Int32(0).Ref()))
l2 := NewList(cs, NewRef(Int32(0).Ref()))
c2 := l2.Chunks()
assert.Len(c2, 1)
l3 := NewList(l2)
l3 := NewList(cs, l2)
c3 := l3.Chunks()
assert.Len(c3, 1)
assert.Equal(Int32(0).Ref(), c3[0])

View File

@@ -5,6 +5,7 @@ import (
"sort"
"sync"
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/d"
"github.com/attic-labs/noms/ref"
)
@@ -14,18 +15,19 @@ type Map struct {
indexOf indexOfMapFn
t Type
ref *ref.Ref
cs chunks.ChunkStore
}
type mapData []mapEntry
type indexOfMapFn func(m mapData, v Value) int
func NewMap(kv ...Value) Map {
return NewTypedMap(mapType, kv...)
func NewMap(cs chunks.ChunkStore, kv ...Value) Map {
return NewTypedMap(cs, mapType, kv...)
}
func NewTypedMap(t Type, kv ...Value) Map {
return newMapFromData(buildMapData(mapData{}, kv, t), t)
func NewTypedMap(cs chunks.ChunkStore, t Type, kv ...Value) Map {
return newMapFromData(cs, buildMapData(mapData{}, kv, t), t)
}
func (m Map) First() (Value, Value) {
@@ -72,12 +74,12 @@ func (m Map) Set(key Value, val Value) Map {
elemTypes := m.t.Desc.(CompoundDesc).ElemTypes
assertType(elemTypes[0], key)
assertType(elemTypes[1], val)
return newMapFromData(buildMapData(m.data, []Value{key, val}, m.t), m.t)
return newMapFromData(m.cs, buildMapData(m.data, []Value{key, val}, m.t), m.t)
}
func (m Map) SetM(kv ...Value) Map {
assertMapElemTypes(m, kv...)
return newMapFromData(buildMapData(m.data, kv, m.t), m.t)
return newMapFromData(m.cs, buildMapData(m.data, kv, m.t), m.t)
}
func (m Map) Remove(k Value) Map {
@@ -89,7 +91,7 @@ func (m Map) Remove(k Value) Map {
data := make(mapData, len(m.data)-1)
copy(data, m.data[:idx])
copy(data[idx:], m.data[idx+1:])
return newMapFromData(data, m.t)
return newMapFromData(m.cs, data, m.t)
}
type mapIterCallback func(key, value Value) (stop bool)
@@ -143,7 +145,7 @@ func (m Map) Filter(cb mapFilterCallback) Map {
}
}
// Already sorted.
return newMapFromData(data, m.t)
return newMapFromData(m.cs, data, m.t)
}
func (m Map) Ref() ref.Ref {
@@ -186,8 +188,8 @@ type mapEntry struct {
value Value
}
func newMapFromData(data mapData, t Type) Map {
return Map{data, getIndexFnForMapType(t), t, &ref.Ref{}}
func newMapFromData(cs chunks.ChunkStore, data mapData, t Type) Map {
return Map{data, getIndexFnForMapType(t), t, &ref.Ref{}, cs}
}
func buildMapData(oldData mapData, values []Value, t Type) mapData {

View File

@@ -7,14 +7,16 @@ import (
"testing"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/chunks"
)
func TestNewMap(t *testing.T) {
assert := assert.New(t)
m := NewMap()
assert.IsType(NewMap(), m)
cs := chunks.NewMemoryStore()
m := NewMap(cs)
assert.IsType(NewMap(cs), m)
assert.Equal(uint64(0), m.Len())
m = NewMap(NewString("foo"), NewString("foo"), NewString("bar"), NewString("bar"))
m = NewMap(cs, NewString("foo"), NewString("foo"), NewString("bar"), NewString("bar"))
assert.Equal(uint64(2), m.Len())
assert.True(NewString("foo").Equals(m.Get(NewString("foo"))))
assert.True(NewString("bar").Equals(m.Get(NewString("bar"))))
@@ -22,7 +24,8 @@ func TestNewMap(t *testing.T) {
func TestMapHasRemove(t *testing.T) {
assert := assert.New(t)
m1 := NewMap()
cs := chunks.NewMemoryStore()
m1 := NewMap(cs)
assert.False(m1.Has(NewString("foo")))
m2 := m1.Set(NewString("foo"), NewString("foo"))
assert.False(m1.Has(NewString("foo")))
@@ -35,7 +38,8 @@ func TestMapHasRemove(t *testing.T) {
func TestMapFirst(t *testing.T) {
assert := assert.New(t)
m1 := NewMap()
cs := chunks.NewMemoryStore()
m1 := NewMap(cs)
k, v := m1.First()
assert.Nil(k)
assert.Nil(v)
@@ -56,7 +60,8 @@ func TestMapFirst(t *testing.T) {
func TestMapSetGet(t *testing.T) {
assert := assert.New(t)
m1 := NewMap()
cs := chunks.NewMemoryStore()
m1 := NewMap(cs)
assert.Nil(m1.Get(NewString("foo")))
m2 := m1.Set(NewString("foo"), Int32(42))
assert.Nil(m1.Get(NewString("foo")))
@@ -74,7 +79,8 @@ func TestMapSetGet(t *testing.T) {
func TestMapSetM(t *testing.T) {
assert := assert.New(t)
m1 := NewMap()
cs := chunks.NewMemoryStore()
m1 := NewMap(cs)
m2 := m1.SetM()
assert.True(m1.Equals(m2))
m3 := m2.SetM(NewString("foo"), NewString("bar"), NewString("hot"), NewString("dog"))
@@ -89,13 +95,15 @@ func TestMapSetM(t *testing.T) {
// BUG 98
func TestMapDuplicateSet(t *testing.T) {
assert := assert.New(t)
m1 := NewMap(Bool(true), Bool(true), Int32(42), Int32(42), Int32(42), Int32(42))
cs := chunks.NewMemoryStore()
m1 := NewMap(cs, Bool(true), Bool(true), Int32(42), Int32(42), Int32(42), Int32(42))
assert.Equal(uint64(2), m1.Len())
}
func TestMapIter(t *testing.T) {
assert := assert.New(t)
m := NewMap()
cs := chunks.NewMemoryStore()
m := NewMap(cs)
type entry struct {
key Value
@@ -138,6 +146,7 @@ func TestMapIter(t *testing.T) {
func TestMapIterAllP(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
testIter := func(concurrency, mapLen int) {
values := make([]Value, 2*mapLen)
@@ -146,7 +155,7 @@ func TestMapIterAllP(t *testing.T) {
values[2*i+1] = UInt64(i)
}
m := NewMap(values...)
m := NewMap(cs, values...)
cur := 0
mu := sync.Mutex{}
@@ -193,27 +202,30 @@ func TestMapIterAllP(t *testing.T) {
func TestMapFilter(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
m := NewMap(Int8(0), NewString("a"), Int8(1), NewString("b"), Int8(2), NewString("c"))
m := NewMap(cs, Int8(0), NewString("a"), Int8(1), NewString("b"), Int8(2), NewString("c"))
m2 := m.Filter(func(k, v Value) bool {
return k.Equals(Int8(0)) || v.Equals(NewString("c"))
})
assert.True(NewMap(Int8(0), NewString("a"), Int8(2), NewString("c")).Equals(m2))
assert.True(NewMap(cs, Int8(0), NewString("a"), Int8(2), NewString("c")).Equals(m2))
}
func TestMapEquals(t *testing.T) {
assert := assert.New(t)
m1 := NewMap()
cs := chunks.NewMemoryStore()
m1 := NewMap(cs)
m2 := m1
m3 := NewMap()
m3 := NewMap(cs)
assert.True(m1.Equals(m2))
assert.True(m2.Equals(m1))
assert.True(m3.Equals(m2))
assert.True(m2.Equals(m3))
m1 = NewMap(NewString("foo"), Float32(0.0), NewString("bar"), NewList())
m2 = m2.SetM(NewString("foo"), Float32(0.0), NewString("bar"), NewList())
m1 = NewMap(cs, NewString("foo"), Float32(0.0), NewString("bar"), NewList(cs))
m2 = m2.SetM(NewString("foo"), Float32(0.0), NewString("bar"), NewList(cs))
assert.True(m1.Equals(m2))
assert.True(m2.Equals(m1))
assert.False(m2.Equals(m3))
@@ -222,6 +234,8 @@ func TestMapEquals(t *testing.T) {
func TestMapNotStringKeys(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
b1 := NewMemoryBlob(bytes.NewBufferString("blob1"))
b2 := NewMemoryBlob(bytes.NewBufferString("blob2"))
l := []Value{
@@ -233,14 +247,14 @@ func TestMapNotStringKeys(t *testing.T) {
Float64(0), NewString("float64: 0"),
b1, NewString("blob1"),
b2, NewString("blob2"),
NewList(), NewString("empty list"),
NewList(NewList()), NewString("list of list"),
NewMap(), NewString("empty map"),
NewMap(NewMap(), NewMap()), NewString("map of map/map"),
NewSet(), NewString("empty set"),
NewSet(NewSet()), NewString("map of set/set"),
NewList(cs), NewString("empty list"),
NewList(cs, NewList(cs)), NewString("list of list"),
NewMap(cs), NewString("empty map"),
NewMap(cs, NewMap(cs), NewMap(cs)), NewString("map of map/map"),
NewSet(cs), NewString("empty set"),
NewSet(cs, NewSet(cs)), NewString("map of set/set"),
}
m1 := NewMap(l...)
m1 := NewMap(cs, l...)
assert.Equal(uint64(14), m1.Len())
for i := 0; i < len(l); i += 2 {
assert.True(m1.Get(l[i]).Equals(l[i+1]))
@@ -249,8 +263,9 @@ func TestMapNotStringKeys(t *testing.T) {
}
func testMapOrder(assert *assert.Assertions, keyType, valueType Type, tuples []Value, expectOrdering []Value) {
cs := chunks.NewMemoryStore()
mapTr := MakeCompoundType(MapKind, keyType, valueType)
m := NewTypedMap(mapTr, tuples...)
m := NewTypedMap(cs, mapTr, tuples...)
i := 0
m.IterAll(func(key, value Value) {
assert.Equal(expectOrdering[i].Ref().String(), key.Ref().String())
@@ -378,21 +393,25 @@ func TestMapOrdering(t *testing.T) {
func TestMapEmpty(t *testing.T) {
assert := assert.New(t)
m := NewMap()
cs := chunks.NewMemoryStore()
m := NewMap(cs)
assert.True(m.Empty())
m = m.Set(Bool(false), NewString("hi"))
assert.False(m.Empty())
m = m.Set(NewList(), NewMap())
m = m.Set(NewList(cs), NewMap(cs))
assert.False(m.Empty())
}
func TestMapType(t *testing.T) {
assert := assert.New(t)
m := NewMap()
cs := chunks.NewMemoryStore()
m := NewMap(cs)
assert.True(m.Type().Equals(MakeCompoundType(MapKind, MakePrimitiveType(ValueKind), MakePrimitiveType(ValueKind))))
tr := MakeCompoundType(MapKind, MakePrimitiveType(StringKind), MakePrimitiveType(UInt64Kind))
m = newMapFromData(mapData{}, tr)
m = newMapFromData(cs, mapData{}, tr)
assert.Equal(tr, m.Type())
m2 := m.Remove(NewString("B"))
@@ -417,16 +436,17 @@ func TestMapType(t *testing.T) {
func TestMapChunks(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
l1 := NewMap(Int32(0), Int32(1))
l1 := NewMap(cs, Int32(0), Int32(1))
c1 := l1.Chunks()
assert.Len(c1, 0)
l2 := NewMap(NewRef(Int32(0).Ref()), Int32(1))
l2 := NewMap(cs, NewRef(Int32(0).Ref()), Int32(1))
c2 := l2.Chunks()
assert.Len(c2, 1)
l3 := NewMap(Int32(0), NewRef(Int32(1).Ref()))
l3 := NewMap(cs, Int32(0), NewRef(Int32(1).Ref()))
c3 := l3.Chunks()
assert.Len(c3, 1)
}

View File

@@ -77,7 +77,7 @@ func (ms metaSequenceObject) Type() Type {
return ms.t
}
type metaBuilderFunc func(tuples metaSequenceData, t Type, cs chunks.ChunkSource) Value
type metaBuilderFunc func(tuples metaSequenceData, t Type, cs chunks.ChunkStore) Value
type metaReaderFunc func(v Value) metaSequenceData
type metaSequenceFuncs struct {
@@ -93,7 +93,7 @@ func registerMetaValue(k NomsKind, bf metaBuilderFunc, rf metaReaderFunc) {
metaFuncMap[k] = metaSequenceFuncs{bf, rf}
}
func newMetaSequenceFromData(tuples metaSequenceData, t Type, cs chunks.ChunkSource) Value {
func newMetaSequenceFromData(tuples metaSequenceData, t Type, cs chunks.ChunkStore) Value {
concreteType := t.Desc.(CompoundDesc).ElemTypes[0]
if s, ok := metaFuncMap[concreteType.Kind()]; ok {

View File

@@ -14,10 +14,10 @@ type metaSequenceCursor struct {
parent *metaSequenceCursor
sequence metaSequence
idx int
cs chunks.ChunkSource
cs chunks.ChunkStore
}
func newMetaSequenceCursor(root metaSequence, cs chunks.ChunkSource) (cursor *metaSequenceCursor, leaf Value) {
func newMetaSequenceCursor(root metaSequence, cs chunks.ChunkStore) (cursor *metaSequenceCursor, leaf Value) {
cursors := []*metaSequenceCursor{&metaSequenceCursor{nil, root, 0, cs}}
for {
cursor = cursors[len(cursors)-1]
@@ -34,7 +34,7 @@ func newMetaSequenceCursor(root metaSequence, cs chunks.ChunkSource) (cursor *me
type cursorIterFn func(v Value) bool
func iterateMetaSequenceLeaf(root metaSequence, cs chunks.ChunkSource, cb cursorIterFn) {
func iterateMetaSequenceLeaf(root metaSequence, cs chunks.ChunkStore, cb cursorIterFn) {
cursor, v := newMetaSequenceCursor(root, cs)
for {
if cb(v) || !cursor.advance() {

View File

@@ -14,21 +14,21 @@ func TestMeta(t *testing.T) {
cs := chunks.NewMemoryStore()
flatList := []Value{UInt32(0), UInt32(1), UInt32(2), UInt32(3), UInt32(4), UInt32(5), UInt32(6), UInt32(7)}
l0 := NewList(flatList[0])
l0 := NewList(cs, flatList[0])
lr0 := WriteValue(l0, cs)
l1 := NewList(flatList[1])
l1 := NewList(cs, flatList[1])
lr1 := WriteValue(l1, cs)
l2 := NewList(flatList[2])
l2 := NewList(cs, flatList[2])
lr2 := WriteValue(l2, cs)
l3 := NewList(flatList[3])
l3 := NewList(cs, flatList[3])
lr3 := WriteValue(l3, cs)
l4 := NewList(flatList[4])
l4 := NewList(cs, flatList[4])
lr4 := WriteValue(l4, cs)
l5 := NewList(flatList[5])
l5 := NewList(cs, flatList[5])
lr5 := WriteValue(l5, cs)
l6 := NewList(flatList[6])
l6 := NewList(cs, flatList[6])
lr6 := WriteValue(l6, cs)
l7 := NewList(flatList[7])
l7 := NewList(cs, flatList[7])
lr7 := WriteValue(l7, cs)
mtr := MakeCompoundType(MetaSequenceKind, l0.Type())

View File

@@ -9,9 +9,9 @@ import (
type enumBuilderFunc func(v uint32) Value
type enumReaderFunc func(v Value) uint32
type refBuilderFunc func(target ref.Ref) Value
type structBuilderFunc func(values []Value) Value
type structBuilderFunc func(cs chunks.ChunkStore, values []Value) Value
type structReaderFunc func(v Value) []Value
type valueBuilderFunc func(v Value) Value
type valueBuilderFunc func(cs chunks.ChunkStore, v Value) Value
type valueReaderFunc func(v Value) Value
type enumFuncs struct {
@@ -51,7 +51,7 @@ func RegisterPackage(p *Package) (r ref.Ref) {
return
}
func readPackage(r ref.Ref, cs chunks.ChunkSource) *Package {
func readPackage(r ref.Ref, cs chunks.ChunkStore) *Package {
p := ReadValue(r, cs).(Package)
RegisterPackage(&p)
return &p
@@ -61,9 +61,9 @@ func RegisterStruct(t Type, bf structBuilderFunc, rf structReaderFunc) {
structFuncMap[t.Ref()] = structFuncs{bf, rf}
}
func structBuilderForType(values []Value, typ, typeDef Type) Value {
func structBuilderForType(cs chunks.ChunkStore, values []Value, typ, typeDef Type) Value {
if s, ok := structFuncMap[typ.Ref()]; ok {
return s.builder(values)
return s.builder(cs, values)
}
return structBuilder(values, typ, typeDef)
}
@@ -97,9 +97,9 @@ func RegisterValue(t Type, bf valueBuilderFunc, rf valueReaderFunc) {
valueFuncMap[t.Ref()] = valueFuncs{bf, rf}
}
func valueFromType(v Value, t Type) Value {
func valueFromType(cs chunks.ChunkStore, v Value, t Type) Value {
if s, ok := valueFuncMap[t.Ref()]; ok {
return s.builder(v)
return s.builder(cs, v)
}
return v
}

View File

@@ -13,22 +13,23 @@ import (
type SetOfRefOfPackage struct {
s Set
ref *ref.Ref
cs chunks.ChunkStore
}
func NewSetOfRefOfPackage() SetOfRefOfPackage {
return SetOfRefOfPackage{NewSet(), &ref.Ref{}}
func NewSetOfRefOfPackage(cs chunks.ChunkStore) SetOfRefOfPackage {
return SetOfRefOfPackage{NewTypedSet(cs, __typeForSetOfRefOfPackage), &ref.Ref{}, cs}
}
type SetOfRefOfPackageDef map[ref.Ref]bool
func (def SetOfRefOfPackageDef) New() SetOfRefOfPackage {
func (def SetOfRefOfPackageDef) New(cs chunks.ChunkStore) SetOfRefOfPackage {
l := make([]Value, len(def))
i := 0
for d, _ := range def {
l[i] = NewRefOfPackage(d)
i++
}
return SetOfRefOfPackage{NewSet(l...), &ref.Ref{}}
return SetOfRefOfPackage{NewTypedSet(cs, __typeForSetOfRefOfPackage, l...), &ref.Ref{}, cs}
}
func (s SetOfRefOfPackage) Def() SetOfRefOfPackageDef {
@@ -72,8 +73,8 @@ func init() {
RegisterValue(__typeForSetOfRefOfPackage, builderForSetOfRefOfPackage, readerForSetOfRefOfPackage)
}
func builderForSetOfRefOfPackage(v Value) Value {
return SetOfRefOfPackage{v.(Set), &ref.Ref{}}
func builderForSetOfRefOfPackage(cs chunks.ChunkStore, v Value) Value {
return SetOfRefOfPackage{v.(Set), &ref.Ref{}, cs}
}
func readerForSetOfRefOfPackage(v Value) Value {
@@ -111,7 +112,7 @@ func (s SetOfRefOfPackage) IterAll(cb SetOfRefOfPackageIterAllCallback) {
type SetOfRefOfPackageFilterCallback func(p RefOfPackage) (keep bool)
func (s SetOfRefOfPackage) Filter(cb SetOfRefOfPackageFilterCallback) SetOfRefOfPackage {
ns := NewSetOfRefOfPackage()
ns := NewSetOfRefOfPackage(s.cs)
s.IterAll(func(v RefOfPackage) {
if cb(v) {
ns = ns.Insert(v)
@@ -121,19 +122,19 @@ func (s SetOfRefOfPackage) Filter(cb SetOfRefOfPackageFilterCallback) SetOfRefOf
}
func (s SetOfRefOfPackage) Insert(p ...RefOfPackage) SetOfRefOfPackage {
return SetOfRefOfPackage{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfPackage{s.s.Insert(s.fromElemSlice(p)...), &ref.Ref{}, s.cs}
}
func (s SetOfRefOfPackage) Remove(p ...RefOfPackage) SetOfRefOfPackage {
return SetOfRefOfPackage{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}}
return SetOfRefOfPackage{s.s.Remove(s.fromElemSlice(p)...), &ref.Ref{}, s.cs}
}
func (s SetOfRefOfPackage) Union(others ...SetOfRefOfPackage) SetOfRefOfPackage {
return SetOfRefOfPackage{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfPackage{s.s.Union(s.fromStructSlice(others)...), &ref.Ref{}, s.cs}
}
func (s SetOfRefOfPackage) Subtract(others ...SetOfRefOfPackage) SetOfRefOfPackage {
return SetOfRefOfPackage{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}}
return SetOfRefOfPackage{s.s.Subtract(s.fromStructSlice(others)...), &ref.Ref{}, s.cs}
}
func (s SetOfRefOfPackage) Any() RefOfPackage {
@@ -205,7 +206,7 @@ func builderForRefOfPackage(r ref.Ref) Value {
return NewRefOfPackage(r)
}
func (r RefOfPackage) TargetValue(cs chunks.ChunkSource) Package {
func (r RefOfPackage) TargetValue(cs chunks.ChunkStore) Package {
return ReadValue(r.target, cs).(Package)
}

View File

@@ -35,6 +35,7 @@ func (v Bool) Type() Type {
return typeForBool
}
type Float32 float32
func (p Float32) Equals(other Value) bool {
@@ -63,6 +64,7 @@ func (v Float32) Type() Type {
return typeForFloat32
}
func (v Float32) Less(other OrderedValue) bool {
return v < other.(Float32)
}
@@ -95,6 +97,7 @@ func (v Float64) Type() Type {
return typeForFloat64
}
func (v Float64) Less(other OrderedValue) bool {
return v < other.(Float64)
}
@@ -127,6 +130,7 @@ func (v Int16) Type() Type {
return typeForInt16
}
func (v Int16) Less(other OrderedValue) bool {
return v < other.(Int16)
}
@@ -159,6 +163,7 @@ func (v Int32) Type() Type {
return typeForInt32
}
func (v Int32) Less(other OrderedValue) bool {
return v < other.(Int32)
}
@@ -191,6 +196,7 @@ func (v Int64) Type() Type {
return typeForInt64
}
func (v Int64) Less(other OrderedValue) bool {
return v < other.(Int64)
}
@@ -223,6 +229,7 @@ func (v Int8) Type() Type {
return typeForInt8
}
func (v Int8) Less(other OrderedValue) bool {
return v < other.(Int8)
}
@@ -255,6 +262,7 @@ func (v UInt16) Type() Type {
return typeForUInt16
}
func (v UInt16) Less(other OrderedValue) bool {
return v < other.(UInt16)
}
@@ -287,6 +295,7 @@ func (v UInt32) Type() Type {
return typeForUInt32
}
func (v UInt32) Less(other OrderedValue) bool {
return v < other.(UInt32)
}
@@ -319,6 +328,7 @@ func (v UInt64) Type() Type {
return typeForUInt64
}
func (v UInt64) Less(other OrderedValue) bool {
return v < other.(UInt64)
}
@@ -351,6 +361,8 @@ func (v UInt8) Type() Type {
return typeForUInt8
}
func (v UInt8) Less(other OrderedValue) bool {
return v < other.(UInt8)
}

Some files were not shown because too many files have changed in this diff Show More