func (oldDoc *Document) updateYamlCocument(newDoc *Document) {

	sort.SliceStable(oldDoc.Components, func(i, j int) bool {
		b := strings.Compare(oldDoc.Components[i].Prefix, oldDoc.Components[j].Prefix)
		return b < 0
	})
	sort.SliceStable(newDoc.Components, func(i, j int) bool {
		b := strings.Compare(newDoc.Components[i].Prefix, newDoc.Components[j].Prefix)
		return b < 0
	})

	if len(oldDoc.Components) == 0 {
		oldDoc.Components = newDoc.Components
		return
	}
	components := make([]*Component, 0)

	i := 0
	j := 0
	ok := (i < len(oldDoc.Components) && j < len(newDoc.Components))

	for ; ok; ok = (i < len(oldDoc.Components) && j < len(newDoc.Components)) {
		ci := oldDoc.Components[i]
		cj := newDoc.Components[j]

		c := strings.Compare(ci.Prefix, cj.Prefix)
		switch c {
		case -1:
			// only in old, may be deleted
			i++
		case 0:
			// the same component
			ci.updateComponent(cj)
			components = append(components, ci)
			i++
			j++
		case 1:
			// not in old, should insert into old
			components = append(components, cj)
			j++
		}
	}

	oldDoc.Components = components
}
// updateYamlCocument will update oldDoc useing newDoc
updateYamlCocument will update oldDoc useing newDoc
// updateYamlCocument will update oldDoc useing newDoc
func (oldDoc *Document) updateYamlCocument(newDoc *Document) {
	sort.SliceStable(oldDoc.Components, func(i, j int) bool {
		b := strings.Compare(oldDoc.Components[i].Prefix, oldDoc.Components[j].Prefix)
		return b < 0
	})
	sort.SliceStable(newDoc.Components, func(i, j int) bool {
		b := strings.Compare(newDoc.Components[i].Prefix, newDoc.Components[j].Prefix)
		return b < 0
	})
	if len(oldDoc.Components) == 0 {
		oldDoc.Components = newDoc.Components
		return
	}
	components := make([]*Component, 0)
	i := 0
	j := 0
	ok := (i < len(oldDoc.Components) && j < len(newDoc.Components))
	for ; ok; ok = (i < len(oldDoc.Components) && j < len(newDoc.Components)) {
		ci := oldDoc.Components[i]
		cj := newDoc.Components[j]
		c := strings.Compare(ci.Prefix, cj.Prefix)
		switch c {
		case -1:
			i++
		case 0:
			ci.updateComponent(cj)
			components = append(components, ci)
			i++
			j++
		case 1:
			components = append(components, cj)
			j++
		}
	}
	oldDoc.Components = components
}
func ( oldDoc * Document ) updateYamlCocument ( newDoc * Document ) { sort . SliceStable ( oldDoc . Components , func ( i , j int ) bool { b := strings . Compare ( oldDoc . Components [ i ] . Prefix , oldDoc . Components [ j ] . Prefix ) return b < 0 } ) sort . SliceStable ( newDoc . Components , func ( i , j int ) bool { b := strings . Compare ( newDoc . Components [ i ] . Prefix , newDoc . Components [ j ] . Prefix ) return b < 0 } ) if len ( oldDoc . Components ) == 0 { oldDoc . Components = newDoc . Components return } components := make ( [ ] * Component , 0 ) i := 0 j := 0 ok := ( i < len ( oldDoc . Components ) && j < len ( newDoc . Components ) ) for ; ok ; ok = ( i < len ( oldDoc . Components ) && j < len ( newDoc . Components ) ) { ci := oldDoc . Components [ i ] cj := newDoc . Components [ j ] c := strings . Compare ( ci . Prefix , cj . Prefix ) switch c { case - 1 : i ++ case 0 : ci . updateComponent ( cj ) components = append ( components , ci ) i ++ j ++ case 1 : components = append ( components , cj ) j ++ } } oldDoc . Components = components }
updateYamlCocument will update oldDoc useing newDoc
updateYamlCocument will update oldDoc useing newDoc
// only in old, may be deleted // the same component // not in old, should insert into old