当前位置: 首页>>代码示例>>Golang>>正文


Golang List.InsertAfter方法代码示例

本文整理汇总了Golang中container/list.List.InsertAfter方法的典型用法代码示例。如果您正苦于以下问题:Golang List.InsertAfter方法的具体用法?Golang List.InsertAfter怎么用?Golang List.InsertAfter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在container/list.List的用法示例。


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

示例1: Insert

func Insert(e Elem, L *list.List) int {
	if L.Len() == 0 {
		L.PushFront(e)
		return L.Len()
	}

	front := L.Front()
	if e.GetTime() < front.Value.(Elem).GetTime() {
		L.InsertBefore(e, front)
		return L.Len()
	}

	el := L.Back()
Loop:
	for {
		if el.Value.(Elem).GetTime() > e.GetTime() {
			el = el.Prev()
		} else {
			break Loop
		}
	}
	L.InsertAfter(e, el)

	return L.Len()
}
开发者ID:jeffallen,项目名称:go-warp,代码行数:25,代码来源:DT.go

示例2: InsertAfterList

func InsertAfterList(rl *list.List, ol *list.List, mark *list.Element) *list.Element {
	rcur := mark
	for cur := ol.Front(); cur != nil; cur = cur.Next() {
		rcur = rl.InsertAfter(cur.Value, rcur)
	}
	return rcur
}
开发者ID:cluo,项目名称:gosegment,代码行数:7,代码来源:utils.go

示例3: commitsBefore

// The limit is depth, not total number of returned commits.
func (repo *Repository) commitsBefore(l *list.List, parent *list.Element, id sha1, current, limit int) error {
	// Reach the limit
	if limit > 0 && current > limit {
		return nil
	}

	commit, err := repo.getCommit(id)
	if err != nil {
		return fmt.Errorf("getCommit: %v", err)
	}

	var e *list.Element
	if parent == nil {
		e = l.PushBack(commit)
	} else {
		var in = parent
		for {
			if in == nil {
				break
			} else if in.Value.(*Commit).ID.Equal(commit.ID) {
				return nil
			} else if in.Next() == nil {
				break
			}

			if in.Value.(*Commit).Committer.When.Equal(commit.Committer.When) {
				break
			}

			if in.Value.(*Commit).Committer.When.After(commit.Committer.When) &&
				in.Next().Value.(*Commit).Committer.When.Before(commit.Committer.When) {
				break
			}

			in = in.Next()
		}

		e = l.InsertAfter(commit, in)
	}

	pr := parent
	if commit.ParentCount() > 1 {
		pr = e
	}

	for i := 0; i < commit.ParentCount(); i++ {
		id, err := commit.ParentID(i)
		if err != nil {
			return err
		}
		err = repo.commitsBefore(l, pr, id, current+1, limit)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:mhartkorn,项目名称:git-module,代码行数:59,代码来源:repo_commit.go

示例4: commitsBefore

func (repo *Repository) commitsBefore(lock *sync.Mutex, l *list.List, parent *list.Element, id sha1, limit int) error {
	commit, err := repo.getCommit(id)
	if err != nil {
		return err
	}

	var e *list.Element
	if parent == nil {
		e = l.PushBack(commit)
	} else {
		var in = parent
		//lock.Lock()
		for {
			if in == nil {
				break
			} else if in.Value.(*Commit).Id.Equal(commit.Id) {
				//lock.Unlock()
				return nil
			} else {
				if in.Next() == nil {
					break
				}
				if in.Value.(*Commit).Committer.When.Equal(commit.Committer.When) {
					break
				}

				if in.Value.(*Commit).Committer.When.After(commit.Committer.When) &&
					in.Next().Value.(*Commit).Committer.When.Before(commit.Committer.When) {
					break
				}
			}
			in = in.Next()
		}

		e = l.InsertAfter(commit, in)
		//lock.Unlock()
	}

	var pr = parent
	if commit.ParentCount() > 1 {
		pr = e
	}

	for i := 0; i < commit.ParentCount(); i++ {
		id, err := commit.ParentId(i)
		if err != nil {
			return err
		}
		err = repo.commitsBefore(lock, l, pr, id, 0)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:sfi2k7,项目名称:git,代码行数:56,代码来源:repo_commit.go

示例5: processAfterSegment

func (s *Segment) processAfterSegment(text string, result *list.List) {
	// 匹配同义词
	if s.options.SynonymOutput {
		node := result.Front()
		for node != nil {
			pW := node.Value.(*dict.WordInfo)
			synonyms := s.synonym.GetSynonyms(pW.Word)
			if synonyms != nil {
				for _, word := range synonyms {
					node = result.InsertAfter(dict.NewWordInfo(word, pW.Position, pW.Pos, pW.Frequency, s.params.SymbolRank, dict.TSynonym, pW.WordType), node)
				}
			}
			node = node.Next()
		}
	}

	// 通配符匹配
	if s.options.WildcardOutput {
		// todo: >>>>>>>
	}

}
开发者ID:rli-diraryi,项目名称:gosegment,代码行数:22,代码来源:segment.go

示例6: insertScore

// Insert the given score into the given list
func insertScore(scores *list.List, length int, s score) {
	// Loop through the scores
	for e := scores.Front(); e != nil; e = e.Next() {
		if e == scores.Back() {
			scores.InsertAfter(s, e)
			break
		}
		v, ok := e.Value.(score)
		if !ok {
			log.Fatal("Could not extract score from sorted list")
		}
		if s.score > v.score {
			scores.InsertBefore(s, e)
			break
		}
	}

	// Remove the last entry if the list is too long
	if scores.Len() > length {
		scores.Remove(scores.Back())
	}
}
开发者ID:alienscience,项目名称:bread,代码行数:23,代码来源:sorted.go

示例7: add

func add(l *list.List, args []string) {
	switch len(args) {
	case 0:
		fmt.Println("What do you want to add?")
		os.Exit(0)
	case 1:
		item := ListItem{
			DESC: args[0],
			DATE: time.Now().Format(DATE_FORMAT),
		}
		l.PushFront(item)
		fmt.Println("adding new item to list: " + args[0])
	case 2:
		// Check if first arg is int
		n, err := strconv.Atoi(args[0])
		if err == nil {
			// Make item (args[1])
			item := ListItem{
				DESC: args[1],
				DATE: time.Now().Format(DATE_FORMAT),
			}

			// Check bounds
			if n > l.Len()+1 {
				fmt.Printf("item [%d] is out of bounds.\n", n)
				os.Exit(1)
			} else if n < 1 {
				fmt.Printf("item [%d] is out of bounds.\n", n)
				os.Exit(1)
			} else if n == 1 { // regular add
				l.PushFront(item)
				fmt.Println("adding new item to list: " + args[1])
				break
			} else { // add in place
				// Insert item at location (n)
				// get nth element
				itemNumber, element := 1, l.Front()
				for itemNumber < n-1 {
					element = element.Next()
					itemNumber++
				}

				// add args[1] after element n-1
				l.InsertAfter(item, element)
				fmt.Printf("adding new item[%d]: %s\n", itemNumber+1, args[1])
				break
			}
		}
		fallthrough

	default:

		// check for first arg numeric in bounds
		n, err := strconv.Atoi(args[0])
		if err == nil { // numeric
			args = args[1:]
			// Check bounds
			if n > l.Len()+1 {
				fmt.Printf("item [%d] is out of bounds.\n", n)
				os.Exit(1)
			} else if n < 1 {
				fmt.Printf("item [%d] is out of bounds.\n", n)
				os.Exit(1)
			}
		}

		// Make item
		item := ListItem{
			DATE: time.Now().Format(DATE_FORMAT),
			DESC: args[0],
		}
		// check if args[1:] have other fields
		for _, a := range args[1:] {
			fields := strings.Split(a, ":")
			if len(fields) < 2 { // not extra field
				fmt.Printf("Missing field name: %s\n", a)
				os.Exit(1)
			} else if len(fields) > 2 { // too many extra field
				fmt.Printf("Too many field names: %s\n", a)
				os.Exit(1)
			} else { // add new field to item
				item[strings.Title(fields[0])] = fields[1]
			}
		}

		str, _ := getJSONString(item)
		switch n {
		case 0, 1: // not numeric, regular add
			l.PushFront(item)
			fmt.Println("adding new item to list: " + str)
		default: // add in place
			// Insert item at location (n)
			// get n-1th element
			itemNumber, element := 1, l.Front()
			for itemNumber < n-1 {
				element = element.Next()
				itemNumber++
			}

			// add args[1] after element n-1
//.........这里部分代码省略.........
开发者ID:tgrijalva,项目名称:lst,代码行数:101,代码来源:lst.go


注:本文中的container/list.List.InsertAfter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。