• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang types.Struct类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/attic-labs/noms/go/types.Struct的典型用法代码示例。如果您正苦于以下问题:Golang Struct类的具体用法?Golang Struct怎么用?Golang Struct使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Struct类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: diffStructs

func diffStructs(w io.Writer, p types.Path, v1, v2 types.Struct) {
	changeChan := make(chan types.ValueChanged)
	stopChan := make(chan struct{}, 1) // buffer size of 1, so this won't block if diff already finished

	defer stop(stopChan)
	go func() {
		v2.Diff(v1, changeChan, stopChan)
		close(changeChan)
	}()

	wroteHeader := false

	for change := range changeChan {
		fn := string(change.V.(types.String))
		switch change.ChangeType {
		case types.DiffChangeAdded:
			wroteHeader = writeHeader(w, wroteHeader, p)
			field(w, ADD, change.V, v2.Get(fn))
		case types.DiffChangeRemoved:
			wroteHeader = writeHeader(w, wroteHeader, p)
			field(w, DEL, change.V, v1.Get(fn))
		case types.DiffChangeModified:
			f1 := v1.Get(fn)
			f2 := v2.Get(fn)
			if shouldDescend(f1, f2) {
				diff(w, p.AddField(fn), types.String(fn), f1, f2)
			} else {
				wroteHeader = writeHeader(w, wroteHeader, p)
				field(w, DEL, change.V, f1)
				field(w, ADD, change.V, f2)
			}
		}
	}
	writeFooter(w, wroteHeader)
}
开发者ID:kalman,项目名称:noms-pre-release,代码行数:35,代码来源:diff.go


示例2: descendsFrom

func descendsFrom(commit types.Struct, currentHeadRef types.Ref, vr types.ValueReader) bool {
	// BFS because the common case is that the ancestor is only a step or two away
	ancestors := commit.Get(ParentsField).(types.Set)
	for !ancestors.Has(currentHeadRef) {
		if ancestors.Empty() {
			return false
		}
		ancestors = getAncestors(ancestors, vr)
	}
	return true
}
开发者ID:willhite,项目名称:noms-old,代码行数:11,代码来源:database_common.go


示例3: diffStructs

func diffStructs(dq *diffQueue, w io.Writer, p types.Path, v1, v2 types.Struct) {
	changed := types.StructDiff(v1, v2)
	wroteHeader := false
	for _, field := range changed {
		f1 := v1.Get(field)
		f2 := v2.Get(field)
		if canCompare(f1, f2) {
			p1 := p.AddField(field)
			dq.PushBack(diffInfo{path: p1, key: types.String(field), v1: f1, v2: f2})
		} else {
			wroteHeader = writeHeader(w, wroteHeader, p)
			line(w, subPrefix, types.String(field), f1)
			line(w, addPrefix, types.String(field), f2)
		}
	}
}
开发者ID:willhite,项目名称:noms-old,代码行数:16,代码来源:diff.go


示例4: diffSummaryStructs

func diffSummaryStructs(ch chan<- diffSummaryProgress, v1, v2 types.Struct) {
	size1 := uint64(v1.Type().Desc.(types.StructDesc).Len())
	size2 := uint64(v2.Type().Desc.(types.StructDesc).Len())
	diffSummaryValueChanged(ch, size1, size2, func(changeChan chan<- types.ValueChanged, stopChan <-chan struct{}) {
		v2.Diff(v1, changeChan, stopChan)
	})
}
开发者ID:kalman,项目名称:noms-pre-release,代码行数:7,代码来源:summary.go


示例5: getNode

func (fs *nomsFS) getNode(inode types.Struct, name string, parent *nNode) *nNode {
	// The parent has to be a directory.
	if parent != nil {
		d.Chk.Equal("Directory", nodeType(parent.inode))
	}

	np, ok := fs.nodes[inode.Hash()]
	if ok {
		d.Chk.Equal(np.parent, parent)
		d.Chk.Equal(np.name, name)
	} else {
		np = &nNode{
			nLock:  &sync.Mutex{},
			parent: parent,
			name:   name,
			key:    inode.Hash(),
			inode:  inode,
		}
		fs.nodes[np.key] = np
	}
	return np
}
开发者ID:Richardphp,项目名称:noms,代码行数:22,代码来源:nomsfs.go


示例6: diffStructs

func diffStructs(w io.Writer, p types.Path, v1, v2 types.Struct) error {
	return diffOrdered(w, p, field, func(cc chan<- types.ValueChanged, sc <-chan struct{}) {
		v2.Diff(v1, cc, sc)
	},
		func(k types.Value) types.Value { return k },
		func(k types.Value) types.Value { return v1.Get(string(k.(types.String))) },
		func(k types.Value) types.Value { return v2.Get(string(k.(types.String))) },
	)
}
开发者ID:Richardphp,项目名称:noms,代码行数:9,代码来源:diff.go


示例7: updateNode

func (fs *nomsFS) updateNode(np *nNode, inode types.Struct) {
	delete(fs.nodes, np.key)
	np.inode = inode
	np.key = inode.Hash()
	fs.nodes[np.key] = np
}
开发者ID:Richardphp,项目名称:noms,代码行数:6,代码来源:nomsfs.go


示例8: updateMtime

func updateMtime(attr types.Struct) types.Struct {
	now := time.Now()
	mtime := types.Number(float64(now.Unix()) + float64(now.Nanosecond())/1000000000)

	return attr.Set("mtime", mtime)
}
开发者ID:Richardphp,项目名称:noms,代码行数:6,代码来源:nomsfs.go


示例9: commit

func (ds *databaseCommon) commit(datasetID string, commit types.Struct) error {
	d.PanicIfTrue(!IsCommitType(commit.Type()), "Can't commit a non-Commit struct to dataset %s", datasetID)
	return ds.doCommit(datasetID, commit)
}
开发者ID:Richardphp,项目名称:noms,代码行数:4,代码来源:database_common.go


示例10: NewCommit

// NewCommit creates a new commit object. The type of Commit is computed based on the type of the value, the type of the meta info as well as the type of the parents.
//
// For the first commit we get:
//
// ```
// struct Commit {
//   meta: M,
//   parents: Set<Ref<Cycle<0>>>,
//   value: T,
// }
// ```
//
// As long as we continue to commit values with type T and meta of type M that type stays the same.
//
// When we later do a commit with value of type U and meta of type N we get:
//
// ```
// struct Commit {
//   meta: N,
//   parents: Set<Ref<struct Commit {
//     meta: M | N,
//     parents: Set<Ref<Cycle<0>>>,
//     value: T | U
//   }>>,
//   value: U,
// }
// ```
//
// Similarly if we do a commit with a different type for the meta info.
//
// The new type gets combined as a union type for the value/meta of the inner commit struct.
func NewCommit(value types.Value, parents types.Set, meta types.Struct) types.Struct {
	t := makeCommitType(value.Type(), valueTypesFromParents(parents, ValueField), meta.Type(), valueTypesFromParents(parents, MetaField))
	return types.NewStructWithType(t, types.ValueSlice{meta, parents, value})
}
开发者ID:Richardphp,项目名称:noms,代码行数:35,代码来源:commit.go



注:本文中的github.com/attic-labs/noms/go/types.Struct类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang types.Value类代码示例发布时间:2022-05-24
下一篇:
Golang types.Set类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap