本文整理匯總了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()
}
示例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
}
示例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
}
示例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
}
示例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: >>>>>>>
}
}
示例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())
}
}
示例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
//.........這裏部分代碼省略.........