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

Golang types.Path类代码示例

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

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



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

示例1: diffLists

func diffLists(dq *diffQueue, w io.Writer, p types.Path, v1, v2 types.List) {
	wroteHeader := false
	splices := v2.Diff(v1)
	for _, splice := range splices {
		if splice.SpRemoved == splice.SpAdded {
			for i := uint64(0); i < splice.SpRemoved; i++ {
				lastEl := v1.Get(splice.SpAt + i)
				newEl := v2.Get(splice.SpFrom + i)
				if canCompare(lastEl, newEl) {
					idx := types.Number(splice.SpAt + i)
					p1 := p.AddIndex(idx)
					dq.PushBack(diffInfo{p1, idx, lastEl, newEl})
				} else {
					wroteHeader = writeHeader(w, wroteHeader, p)
					line(w, subPrefix, nil, v1.Get(splice.SpAt+i))
					line(w, addPrefix, nil, v2.Get(splice.SpFrom+i))
				}
			}
		} else {
			for i := uint64(0); i < splice.SpRemoved; i++ {
				wroteHeader = writeHeader(w, wroteHeader, p)
				line(w, subPrefix, nil, v1.Get(splice.SpAt+i))
			}
			for i := uint64(0); i < splice.SpAdded; i++ {
				wroteHeader = writeHeader(w, wroteHeader, p)
				line(w, addPrefix, nil, v2.Get(splice.SpFrom+i))
			}
		}
	}
	writeFooter(w, wroteHeader)
}
开发者ID:willhite,项目名称:noms-old,代码行数:31,代码来源:diff.go


示例2: diffMaps

func diffMaps(dq *diffQueue, w io.Writer, p types.Path, v1, v2 types.Map) {
	wroteHeader := false

	added, removed, modified := v2.Diff(v1)
	for _, k := range added {
		wroteHeader = writeHeader(w, wroteHeader, p)
		line(w, addPrefix, k, v2.Get(k))
	}
	for _, k := range removed {
		wroteHeader = writeHeader(w, wroteHeader, p)
		line(w, subPrefix, k, v1.Get(k))
	}
	for _, k := range modified {
		c1, c2 := v1.Get(k), v2.Get(k)
		if canCompare(c1, c2) {
			buf := bytes.NewBuffer(nil)
			d.Exp.NoError(types.WriteEncodedValueWithTags(buf, k))
			p1 := p.AddField(buf.String())
			dq.PushBack(diffInfo{path: p1, key: k, v1: c1, v2: c2})
		} else {
			wroteHeader = writeHeader(w, wroteHeader, p)
			line(w, subPrefix, k, v1.Get(k))
			line(w, addPrefix, k, v2.Get(k))
		}
	}
	writeFooter(w, wroteHeader)
}
开发者ID:willhite,项目名称:noms-old,代码行数:27,代码来源:diff.go


示例3: 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


示例4: diffLists

func diffLists(w io.Writer, p types.Path, v1, v2 types.List) (err error) {
	spliceChan := make(chan types.Splice)
	stopChan := make(chan struct{}, 1) // buffer size of 1, so this won't block if diff already finished

	go func() {
		v2.Diff(v1, spliceChan, stopChan)
		close(spliceChan)
	}()

	wroteHdr := false

	for splice := range spliceChan {
		if err != nil {
			break
		}

		if splice.SpRemoved == splice.SpAdded {
			// Heuristic: list only has modifications.
			for i := uint64(0); i < splice.SpRemoved; i++ {
				lastEl := v1.Get(splice.SpAt + i)
				newEl := v2.Get(splice.SpFrom + i)
				if shouldDescend(lastEl, newEl) {
					idx := types.Number(splice.SpAt + i)
					writeFooter(w, &wroteHdr)
					err = diff(w, p.AddIndex(idx), idx, lastEl, newEl)
				} else {
					writeHeader(w, p, &wroteHdr)
					line(w, DEL, nil, v1.Get(splice.SpAt+i))
					err = line(w, ADD, nil, v2.Get(splice.SpFrom+i))
				}
			}
			continue
		}

		// Heuristic: list only has additions/removals.
		for i := uint64(0); i < splice.SpRemoved && err == nil; i++ {
			writeHeader(w, p, &wroteHdr)
			err = line(w, DEL, nil, v1.Get(splice.SpAt+i))
		}
		for i := uint64(0); i < splice.SpAdded && err == nil; i++ {
			writeHeader(w, p, &wroteHdr)
			err = line(w, ADD, nil, v2.Get(splice.SpFrom+i))
		}
	}

	err = writeFooter(w, &wroteHdr)

	if err != nil {
		stopChan <- struct{}{}
		// Wait for diff to stop.
		for range spliceChan {
		}
	}
	return
}
开发者ID:Richardphp,项目名称:noms,代码行数:55,代码来源:diff.go


示例5: writeHeader

func writeHeader(w io.Writer, wroteHeader bool, p types.Path) bool {
	var err error
	if !wroteHeader {
		_, err = w.Write([]byte(p.String()))
		d.Exp.NoError(err)
		_, err = w.Write([]byte(" {\n"))
		d.Exp.NoError(err)
		wroteHeader = true
	}
	return wroteHeader
}
开发者ID:willhite,项目名称:noms-old,代码行数:11,代码来源:diff.go


示例6: writeHeader

func writeHeader(w io.Writer, p types.Path, wroteHdr *bool) error {
	if *wroteHdr {
		return nil
	}
	*wroteHdr = true
	hdr := "(root)"
	if len(p) > 0 {
		hdr = p.String()
	}
	return write(w, []byte(hdr+" {\n"))
}
开发者ID:Richardphp,项目名称:noms,代码行数:11,代码来源:diff.go


示例7: writeHeader

func writeHeader(w io.Writer, wroteHeader bool, p types.Path) bool {
	if !wroteHeader {
		if len(p) == 0 {
			write(w, []byte("(root)"))
		} else {
			write(w, []byte(p.String()))
		}
		write(w, []byte(" {\n"))
	}
	return true
}
开发者ID:kalman,项目名称:noms-pre-release,代码行数:11,代码来源:diff.go


示例8: diffOrdered

func diffOrdered(w io.Writer, p types.Path, lf lineFunc, df diffFunc, kf, v1, v2 valueFunc) (err error) {
	changeChan := make(chan types.ValueChanged)
	stopChan := make(chan struct{}, 1) // buffer size of 1, so this won't block if diff already finished

	go func() {
		df(changeChan, stopChan)
		close(changeChan)
	}()

	wroteHdr := false

	for change := range changeChan {
		if err != nil {
			break
		}

		k := kf(change.V)

		switch change.ChangeType {
		case types.DiffChangeAdded:
			writeHeader(w, p, &wroteHdr)
			err = lf(w, ADD, k, v2(change.V))
		case types.DiffChangeRemoved:
			writeHeader(w, p, &wroteHdr)
			err = lf(w, DEL, k, v1(change.V))
		case types.DiffChangeModified:
			c1, c2 := v1(change.V), v2(change.V)
			if shouldDescend(c1, c2) {
				writeFooter(w, &wroteHdr)
				err = diff(w, p.AddIndex(k), change.V, c1, c2)
			} else {
				writeHeader(w, p, &wroteHdr)
				lf(w, DEL, k, c1)
				err = lf(w, ADD, k, c2)
			}
		default:
			panic("unknown change type")
		}
	}

	writeFooter(w, &wroteHdr)

	if err != nil {
		stopChan <- struct{}{}
		// Wait for diff to stop.
		for range changeChan {
		}
	}
	return
}
开发者ID:Richardphp,项目名称:noms,代码行数:50,代码来源:diff.go


示例9: 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


示例10: diffSets

func diffSets(dq *diffQueue, w io.Writer, p types.Path, v1, v2 types.Set) {
	wroteHeader := false
	added, removed := v2.Diff(v1)
	if len(added) == 1 && len(removed) == 1 && canCompare(added[0], removed[0]) {
		p1 := p.AddField(added[0].Hash().String())
		dq.PushBack(diffInfo{path: p1, key: types.String(""), v1: removed[0], v2: added[0]})
	} else {
		for _, value := range removed {
			wroteHeader = writeHeader(w, wroteHeader, p)
			line(w, subPrefix, nil, value)
		}
		for _, value := range added {
			wroteHeader = writeHeader(w, wroteHeader, p)
			line(w, addPrefix, nil, value)
		}
	}
	writeFooter(w, wroteHeader)
	return
}
开发者ID:willhite,项目名称:noms-old,代码行数:19,代码来源:diff.go


示例11: diffLists

func diffLists(w io.Writer, p types.Path, v1, v2 types.List) {
	spliceChan := make(chan types.Splice)
	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, spliceChan, stopChan)
		close(spliceChan)
	}()

	wroteHeader := false

	for splice := range spliceChan {
		if splice.SpRemoved == splice.SpAdded {
			for i := uint64(0); i < splice.SpRemoved; i++ {
				lastEl := v1.Get(splice.SpAt + i)
				newEl := v2.Get(splice.SpFrom + i)
				if shouldDescend(lastEl, newEl) {
					idx := types.Number(splice.SpAt + i)
					diff(w, p.AddIndex(idx), idx, lastEl, newEl)
				} else {
					wroteHeader = writeHeader(w, wroteHeader, p)
					line(w, DEL, nil, v1.Get(splice.SpAt+i))
					line(w, ADD, nil, v2.Get(splice.SpFrom+i))
				}
			}
		} else {
			for i := uint64(0); i < splice.SpRemoved; i++ {
				wroteHeader = writeHeader(w, wroteHeader, p)
				line(w, DEL, nil, v1.Get(splice.SpAt+i))
			}
			for i := uint64(0); i < splice.SpAdded; i++ {
				wroteHeader = writeHeader(w, wroteHeader, p)
				line(w, ADD, nil, v2.Get(splice.SpFrom+i))
			}
		}
	}

	writeFooter(w, wroteHeader)
}
开发者ID:kalman,项目名称:noms-pre-release,代码行数:40,代码来源:diff.go


示例12: diffMaps

func diffMaps(w io.Writer, p types.Path, v1, v2 types.Map) {
	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 {
		switch change.ChangeType {
		case types.DiffChangeAdded:
			wroteHeader = writeHeader(w, wroteHeader, p)
			line(w, ADD, change.V, v2.Get(change.V))
		case types.DiffChangeRemoved:
			wroteHeader = writeHeader(w, wroteHeader, p)
			line(w, DEL, change.V, v1.Get(change.V))
		case types.DiffChangeModified:
			c1, c2 := v1.Get(change.V), v2.Get(change.V)
			if shouldDescend(c1, c2) {
				wroteHeader = writeFooter(w, wroteHeader)
				diff(w, p.AddIndex(change.V), change.V, c1, c2)
			} else {
				wroteHeader = writeHeader(w, wroteHeader, p)
				line(w, DEL, change.V, c1)
				line(w, ADD, change.V, c2)
			}
		default:
			panic("unknown change type")
		}
	}

	writeFooter(w, wroteHeader)
}
开发者ID:kalman,项目名称:noms-pre-release,代码行数:37,代码来源:diff.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang types.Ref类代码示例发布时间:2022-05-24
下一篇:
Golang types.List类代码示例发布时间: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