本文整理匯總了Golang中container/list.PushBack函數的典型用法代碼示例。如果您正苦於以下問題:Golang PushBack函數的具體用法?Golang PushBack怎麽用?Golang PushBack使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了PushBack函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: expandClass
func expandClass(regex []int) string {
list := New()
list.Init()
nextEscape := false
escaped := false
var toDelete *Element
for reg_index := 0; reg_index < len(regex); reg_index++ {
escaped = nextEscape
nextEscape = false
switch regex[reg_index] {
case '\\':
if escaped {
escaped = false
list.PushBack(int('\\'))
toDelete = nil
} else {
nextEscape = true
toDelete = list.PushBack(int('\\'))
}
break
case '-':
if escaped {
escaped = false
list.PushBack(int('-'))
toDelete.Value = Delete
} else {
if reg_index > 0 && reg_index < len(regex)-1 {
start := regex[reg_index-1]
end := uint8(regex[reg_index+1])
for char := uint8(start + 1); char < end; char++ {
list.PushBack(int(char))
}
} else {
//ERROR
fmt.Println("invalid character class")
}
}
break
default:
list.PushBack(regex[reg_index])
break
}
}
for e := list.Front(); e != nil; e = e.Next() {
if e.Value.(int) == Delete {
list.Remove(e)
}
}
out := string(list.Remove(list.Front()).(int))
for e := list.Front(); e != nil; e = e.Next() {
out += string('|')
out += string(e.Value.(int))
}
return out
}
示例2: MakeList
func MakeList(args ...Data) List {
list := CreateList()
for _, arg := range args {
list.PushBack(arg)
}
return list
}
示例3: readASN1CertList
// Reads a list of ASN1Cert types from |r|
func readASN1CertList(r io.Reader, totalLenBytes int, elementLenBytes int) ([]ASN1Cert, error) {
listBytes, err := readVarBytes(r, totalLenBytes)
if err != nil {
return []ASN1Cert{}, err
}
list := list.New()
listReader := bytes.NewReader(listBytes)
var entry []byte
for err == nil {
entry, err = readVarBytes(listReader, elementLenBytes)
if err != nil {
if err != io.EOF {
return []ASN1Cert{}, err
}
} else {
list.PushBack(entry)
}
}
ret := make([]ASN1Cert, list.Len())
i := 0
for e := list.Front(); e != nil; e = e.Next() {
ret[i] = e.Value.([]byte)
i++
}
return ret, nil
}
示例4: GetConnectedUsers
// UserList related:
func GetConnectedUsers(userList *list.List) *list.List {
list := list.New()
for e := userList.Front(); e != nil; e = e.Next() {
list.PushBack(e.Value.(*User).Username)
}
return list
}
示例5: memory
//==================================================
// env GODEBUG=gctrace=1,schedtrace=1000 ./grammar
//
// even one struct{xxx} nested into another struct{xxx} the gc can
// collect the memory too.
//==================================================
func memory() {
type stdata struct {
data [64 * 1024]byte
}
type stmemory struct {
used int
data *stdata
}
list := list.New()
i := 0
for {
c := new(stmemory)
d := new(stdata)
c.data = d
list.PushBack(c)
time.Sleep(10 * time.Millisecond)
if c == nil {
break
}
i++
if i%1024 == 0 {
i = 0
//this will cause gc to collect memory to the minimal size
fmt.Printf("do list init\n")
list.Init()
}
}
}
示例6: Add
func (txs *txStore) Add(tx string, f *frame.Frame) error {
if list, ok := txs.transactions[tx]; ok {
f.Header.Del(frame.Transaction)
list.PushBack(f)
return nil
}
return txUnknown
}
示例7: main
func main() {
for i := 0; i < 100000; i++ {
list := list.New()
for j := 0; j < 10000; j++ {
myStruct := new(MyStruct)
list.PushBack(myStruct)
}
}
}
示例8: Map
func (ls List) Map(f func(a Data, i int) Data) List {
list := CreateList()
i := 0
for e := ls.Front(); e != nil; e = e.Next() {
switch t := e.Value.(type) {
case Data:
list.PushBack(f(t, i))
}
i++
}
return list
}
示例9: MatchAll
func MatchAll(m *Matcher, text string) []Match {
list := list.New()
ch := m.Match(text)
for n := range ch {
list.PushBack(n)
}
all := make([]Match, list.Len())
idx := 0
for e := list.Front(); e != nil; e = e.Next() {
all[idx] = e.Value.(Match)
idx++
}
return all
}
示例10: Map
func Map(value string) *list.List {
list := list.New()
f := func(c rune) bool {
return !unicode.IsLetter(c) && !unicode.IsNumber(c)
}
array_str := strings.FieldsFunc(value, f)
for i := 0; i < len(array_str); i++ {
fmt.Println("Element", i, "of array is", array_str[i])
list.PushBack(array_str[i])
}
return list
}
示例11: compressSubGraph
func compressSubGraph(letterCount int, subGraph map[string]*WordNode, done chan bool) {
for _, node := range subGraph {
list := list.New()
for letter := 0; letter < letterCount; letter++ {
for _, edge := range node.Edges[letter] {
if edge != nil {
list.PushBack(edge)
}
}
}
node.Neighbours = listToNodeSlice(list)
node.Edges = nil
}
done <- true
}
示例12: Filter
func (ls List) Filter(f func(a Data, i int) bool) List {
list := CreateList()
i := 0
for e := ls.Front(); e != nil; e = e.Next() {
switch t := e.Value.(type) {
case Data:
if f(t, i) {
list.PushBack(t)
}
}
i++
}
return list
}
示例13: init
func (d *Discover) init() {
//構造一個映射端口號隊列列表
list := list.New()
startPort := 1990
for i := 0; i < 10; i++ {
list.PushBack(startPort)
startPort++
}
d.MappingInfo = MappingInfo{OutsideMappingPort: make(map[string]int, 2), InsideMappingPort: make(map[string]int, 2)}
d.GroupIp = "239.255.255.250:1900"
d.DiscoverInfo = DiscoverInfo{MappingPorts: list,
Protocols: []string{"TCP", "UDP"},
DefaultSearchType: []string{"urn:schemas-upnp-org:service:WANIPConnection:1",
"urn:schemas-upnp-org:service:WANPPPConnection:1",
"urn:schemas-upnp-org:device:InternetGatewayDevice:1"}}
}
示例14: Map
// our simplified version of MapReduce does not supply a
// key to the Map function, as in the paper; only a value,
// which is a part of the input file content. the return
// value should be a list of key/value pairs, each represented
// by a mapreduce.KeyValue.
func Map(value string) *list.List {
list := list.New()
f := func(c rune) bool {
return !unicode.IsLetter(c) && !unicode.IsNumber(c)
}
array_str := strings.FieldsFunc(value, f)
for i := 0; i < len(array_str); i++ {
var kv mapreduce.KeyValue
kv.Key = array_str[i]
kv.Value = "1"
list.PushBack(kv)
}
return list
}
示例15: ParseTree
func ParseTree(tree ast.ASTNode) (*list.List, error) {
list := list.New()
switch node := tree.(type) {
case *ast.BlockStmt:
previous := current
current = newScope()
scopes = append(scopes, current)
for _, stmt := range node.List() {
l, err := ParseTree(stmt)
if err != nil {
return nil, err
}
list.PushBackList(l)
}
current = previous
return list, nil
case *ast.GenDecl:
// declarations never push back lists
_, err := ParseTree(node.Decl)
if err != nil {
return nil, err
}
value, err := ParseTree(node.Value)
if err != nil {
return nil, err
}
list.PushBackList(value)
case *ast.DeclObj:
return nil, current.declVar(node.Id)
case *ast.AsmExpr:
asm := strings.Split(node.Asm, "\n")
for _, asm := range asm {
cmt := strings.Split(asm, ";")
if len(cmt) > 0 && len(cmt[0]) > 0 && cmt[0] != ";" {
list.PushBack(strings.TrimSpace(cmt[0]))
}
}
return list, nil
}
return list, nil
}