本文整理汇总了Golang中container/list.Front函数的典型用法代码示例。如果您正苦于以下问题:Golang Front函数的具体用法?Golang Front怎么用?Golang Front使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Front函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: deletelist
func (ls *libstore) deletelist() {
now := time.Now()
// ls.mutex.Lock()
// // fmt.Println("deleteinvalid")
// defer ls.mutex.Unlock()
for key, list := range ls.keyValudhistory {
ls.initiateKeyValueMutex(key)
ls.keyValueMutex[key].Lock()
for list.Len() > 0 {
e := list.Front()
if e.Value.(time.Time).Add(time.Duration(storagerpc.QueryCacheSeconds)*time.Second).After(now) && list.Len() <= storagerpc.QueryCacheThresh {
break
}
list.Remove(list.Front())
}
ls.keyValueMutex[key].Unlock()
}
for key, list := range ls.keyListhistory {
ls.initiateKeyListMutex(key)
ls.keyListMutex[key].Lock()
for list.Len() > 0 {
e := list.Front()
if e.Value.(time.Time).Add(time.Duration(storagerpc.QueryCacheSeconds)*time.Second).After(now) && list.Len() <= storagerpc.QueryCacheThresh {
break
}
list.Remove(list.Front())
}
ls.keyListMutex[key].Unlock()
}
}
开发者ID:Karthikvb,项目名称:15640_projects,代码行数:32,代码来源:libstore_impl.go
示例2: 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
}
开发者ID:bjh83,项目名称:stammer,代码行数:55,代码来源:preprocessor.go
示例3: Commit
// Commit causes all requests that have been queued for the transaction
// to be sent to the request channel for processing. Calls the commit
// function (commitFunc) in order for each request that is part of the
// transaction.
func (txs *txStore) Commit(tx string, commitFunc func(f *frame.Frame) error) error {
if list, ok := txs.transactions[tx]; ok {
for element := list.Front(); element != nil; element = list.Front() {
err := commitFunc(list.Remove(element).(*frame.Frame))
if err != nil {
return err
}
}
delete(txs.transactions, tx)
return nil
}
return txUnknown
}
开发者ID:MySportsBox,项目名称:stomp,代码行数:17,代码来源:tx_store.go
示例4: PrintDepartures
func PrintDepartures(airport string, data *FlightData) {
list := data.Departures[airport]
for cursor := list.Front(); cursor != nil; cursor = cursor.Next() {
f := cursor.Value.(Flight)
fmt.Println(f.From, f.To, f.Cost)
}
}
开发者ID:ivancich,项目名称:Cheap-Tourist--Fast-Tourist,代码行数:7,代码来源:flights.go
示例5: 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
}
开发者ID:jfrazelle,项目名称:cfssl,代码行数:27,代码来源:serialization.go
示例6: locate
// locate returns the node on which the item at the logical index should reside.
// If the index lands on a slice node, the offset is the physical index relative
// to the slice. If the index lands on a value node, then the offset is
// meaningless and set to 0.
func (s *GapSlice) locate(i int) (elem *list.Element, offset int) {
if i < 0 || i >= s.size {
return nil, 0
}
remaining := i
list := s.list
for e := list.Front(); e != nil; e = e.Next() {
switch value := e.Value.(type) {
case gapSliceChunk:
if chunkSize := len(value); remaining < chunkSize {
return e, remaining
} else {
remaining -= chunkSize
}
default:
if remaining == 0 {
return e, 0
} else {
remaining -= 1
}
}
}
panic(Errorf("could not find element for index %d in GapSlice", i))
}
开发者ID:kourge,项目名称:ggit,代码行数:30,代码来源:gapslice.go
示例7: GetList
func (ss *storageServer) GetList(args *storagerpc.GetArgs, reply *storagerpc.GetListReply) error {
if !ss.isInServerRange(args.Key) {
reply.Status = storagerpc.WrongServer
return nil
}
//get the lock for current key
ss.mutex.Lock()
lock, exist := ss.lockMap[args.Key]
if !exist {
lock = new(sync.Mutex)
ss.lockMap[args.Key] = lock
}
ss.mutex.Unlock()
//Lock current key we are going to work on
lock.Lock()
//process lease request
grantLease := false
if args.WantLease {
//add to lease map
var libServerList *list.List
libServerList, exist := ss.leaseMap[args.Key]
if !exist {
libServerList = new(list.List)
}
leaseRecord := LeaseRecord{args.HostPort, time.Now()}
libServerList.PushBack(leaseRecord)
ss.leaseMap[args.Key] = libServerList
grantLease = true
}
reply.Lease = storagerpc.Lease{grantLease, storagerpc.LeaseSeconds}
//retrieve list
list, exist := ss.keyListMap[args.Key]
if !exist {
reply.Status = storagerpc.KeyNotFound
} else {
//convert list format from "map" to "[]string"
listSize := list.Len()
replyList := make([]string, listSize)
i := 0
for e := list.Front(); e != nil; e = e.Next() {
val := (e.Value).(string)
replyList[i] = val
i = i + 1
}
reply.Value = replyList
reply.Status = storagerpc.OK
}
lock.Unlock()
return nil
}
开发者ID:oldady,项目名称:Tribbler,代码行数:57,代码来源:storageserver_impl.go
示例8: Top
func (stack *Stack) Top() []byte {
list := (*list.List)(stack)
el := list.Front()
if el == nil {
return nil
}
val, ok := el.Value.([]byte)
if !ok {
panic("Why is it not a byte array?")
}
return val
}
开发者ID:ancientlore,项目名称:hashsrv,代码行数:12,代码来源:stack.go
示例9: Get
func (h *hashMap) Get(key Value) (Value, error) {
index := h.getIndex(key)
if h.data[index] == nil {
return nil, fmt.Errorf("not found")
}
list := h.data[index]
for e := list.Front(); e != nil; e = e.Next() {
if i := e.Value.(*item); i.key.Get() == key.Get() {
return i.value, nil
}
}
return nil, fmt.Errorf("not found")
}
开发者ID:oinume,项目名称:algo,代码行数:13,代码来源:hash_map.go
示例10: IsBST
func IsBST(root *TreeNode) bool {
list := list.New()
createOrderedArray(root, list)
prev := list.Front()
for e := prev.Next(); e != nil; e = e.Next() {
if prev.Value.(int) > e.Value.(int) {
return false
}
prev = e
}
return true
}
开发者ID:mura-s,项目名称:coding-interview-go,代码行数:14,代码来源:ex4_5.go
示例11: 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
}
开发者ID:k-takata,项目名称:nvcheck,代码行数:14,代码来源:match_all.go
示例12: GoString
// GoString formats this GapSlice as a space-separated list of nodes surrounded
// by parentheses. Value nodes are represented by the GoString format of the
// value itself, while slice nodes are presented as a space-separated list of
// values in GoString format surrounded by square brackets.
func (s *GapSlice) GoString() string {
list := s.list
b := bytes.NewBufferString("(")
for e := list.Front(); e != nil; e = e.Next() {
if chunk, isChunk := e.Value.(gapSliceChunk); isChunk {
b.WriteString(fmt.Sprintf("%v", chunk))
} else {
b.WriteString(fmt.Sprintf("%#v", e.Value))
}
if e != list.Back() {
b.WriteRune(' ')
}
}
b.WriteRune(')')
return b.String()
}
开发者ID:kourge,项目名称:ggit,代码行数:20,代码来源:gapslice.go
示例13: Remove
// Remove a service definition from the list. If a service has been removed,
// return true. Different connections cannot remove services they did not add.
func (l *serviceList) Remove(service *ServiceDef) bool {
list := (*list.List)(l)
for iter := list.Front(); iter != nil; iter = iter.Next() {
e := iter.Value.(*ServiceDef)
res := service.compare(e)
if res > 0 {
continue
} else if res == 0 && e.connId == service.connId {
list.Remove(iter)
return true
}
// Did not find the service.
break
}
return false
}
开发者ID:croachrose,项目名称:discovery,代码行数:18,代码来源:service_list.go
示例14: daythirteen
func daythirteen() {
file, _ := os.Open("input-day13")
list := list.New()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
text := scanner.Text()
list.PushFront(text)
}
arr := make([]string, list.Len())
count := 0
for e := list.Front(); e != nil; e = e.Next() {
arr[count] = e.Value.(string)
count++
}
fmt.Printf("Best = %d\n", ProcSeatingArray(arr, 0))
fmt.Printf("Best = %d\n", ProcSeatingArray(arr, 1))
}
开发者ID:brotherlogic,项目名称:advent,代码行数:17,代码来源:day13.go
示例15: toArray
func toArray(values interface{}) ([]interface{}, os.Error) {
// vector to array
if vector, ok := values.(*vector.Vector); ok {
return toArray(*vector)
}
result := new(vector.Vector)
// list to array
if list, ok := values.(*list.List); ok {
for e := list.Front(); e != nil; e = e.Next() {
result.Push(e.Value)
}
return *result, nil
}
switch v := reflect.ValueOf(values); v.Kind() {
// array to array (copy)
case reflect.Array, reflect.Slice:
arr := v
for i := 0; i < arr.Len(); i++ {
obj := arr.Index(i).Interface()
result.Push(obj)
}
// channel to array
case reflect.Chan:
ch := v
for {
if x, ok := ch.Recv(); ok {
obj := x.Interface()
result.Push(obj)
} else {
break
}
}
// unknown type
default:
return nil, Errorf("type error: expected a collection type, but was “%v” of type “%T”", values, values)
}
return *result, nil
}
开发者ID:boggle,项目名称:gospec,代码行数:45,代码来源:matchers.go
示例16: Walk
// Walk iterates through this GapSlice, calling walkFn for each item visited by
// Walk.
//
// If walkFun returns an error, the iteration is immediately halted, and in turn,
// that error is returned by Walk.
func (s *GapSlice) Walk(walkFn GapSliceWalkFunc) error {
list := s.list
for e := list.Front(); e != nil; e = e.Next() {
switch value := e.Value.(type) {
case gapSliceChunk:
for _, v := range value {
if err := walkFn(v); err != nil {
return err
}
}
default:
if err := walkFn(value); err != nil {
return nil
}
}
}
return nil
}
开发者ID:kourge,项目名称:ggit,代码行数:23,代码来源:gapslice.go
示例17: reconstructPath
func reconstructPath(came_from map[Coord]Coord, current_node Coord) []*Move {
list := list.New()
for present := true; present; _, present = came_from[current_node] {
next_node := came_from[current_node]
list.PushFront(findMove(current_node, next_node))
current_node = next_node
}
// Convert to a list and return
rtn := make([]*Move, list.Len())
i := 0
for e := list.Front(); e != nil; e = e.Next() {
move := e.Value.(Move)
rtn[i] = &move
i++
}
return rtn
}
开发者ID:splondike,项目名称:go-digger,代码行数:19,代码来源:pathfinder.go
示例18: Add
// Add a new service definition to the list. If the definition is added or
// updated, return true.
func (l *serviceList) Add(service *ServiceDef) bool {
list := (*list.List)(l)
for iter := list.Front(); iter != nil; iter = iter.Next() {
e := iter.Value.(*ServiceDef)
res := service.compare(e)
if res > 0 {
continue
} else if res < 0 {
list.InsertBefore(service, iter)
return true
} else if e.connId == service.connId {
// Replace the definition if it is from the same connection.
iter.Value = service
return true
}
// Equal entries but from a different connection.
return false
}
list.PushBack(service)
return true
}
开发者ID:croachrose,项目名称:discovery,代码行数:23,代码来源:service_list.go
示例19: taskView
//查看某状态的任务
func taskView(w http.ResponseWriter, r *http.Request) {
status := r.FormValue("status")
reg := regexp.MustCompile(status_requ)
if reg.MatchString(status) == false {
io.WriteString(w, "need param status, status must be 0-new task ,1-success,2-can not get rdb,3-parse fatal, 4-get remote redis password error or 5-task is running!")
return
}
int_stat, _ := strconv.ParseInt(status, 10, 32)
mark, list := dbutil.FetchTask(int(int_stat))
if mark == 1 {
var listHtml string = "<body><ol>"
for e := list.Front(); e != nil; e = e.Next() {
task, ok := e.Value.(dbutil.Task)
if ok {
//获取task信息
host := task.Host
port := task.Port
filterLength := task.FilterLength
filterKey := task.FilterKey
taskId := task.TaskId
createTime := task.CreateTime
listHtml += "<li>" + "host:" + host + ";port:" + port + ";filterLength:" + strconv.FormatInt(int64(filterLength), 10) + ";filterKey:" + filterKey + ";taskId:" + taskId + ";create_time:" + createTime + "</li>"
} else {
//task的类型不正确
return
}
}
listHtml = listHtml + "</ol></body>"
io.WriteString(w, listHtml)
} else {
io.WriteString(w, "error occure !")
logs.Log("error occure in taskView!")
}
}
开发者ID:z383966992,项目名称:redis-rdb-parse,代码行数:40,代码来源:main.go
示例20: task
//根据taskId查看某一个task
func task(w http.ResponseWriter, r *http.Request) {
taskId := r.FormValue("taskId")
mark, list := dbutil.FetchTaskById(taskId)
if list.Len() == 0 {
io.WriteString(w, "without this task !")
return
}
if mark == 1 {
var listHtml string = "<body><ol>"
for e := list.Front(); e != nil; e = e.Next() {
task, ok := e.Value.(dbutil.Task)
if ok {
//获取task信息
host := task.Host
port := task.Port
filterLength := task.FilterLength
filterKey := task.FilterKey
taskId := task.TaskId
priority := task.Priority
status := task.Status
createTime := task.CreateTime
listHtml += "<li>" + "host:" + host + ";port:" + port + ";filterLength:" + strconv.FormatInt(int64(filterLength), 10) + ";filter_key:" + filterKey + ";taskId:" + taskId +
";priority:" + strconv.FormatInt(int64(priority), 10) + ";status:" + strconv.FormatInt(int64(status), 10) + ";create_time:" + createTime + "</li>"
} else {
//task的类型不正确
return
}
listHtml = listHtml + "</ol></body>"
}
io.WriteString(w, listHtml)
} else {
io.WriteString(w, "error occure !")
logs.Log("error occure in taskView!")
}
}
开发者ID:z383966992,项目名称:redis-rdb-parse,代码行数:39,代码来源:main.go
注:本文中的container/list.Front函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论