本文整理匯總了Golang中container/list.List.Front方法的典型用法代碼示例。如果您正苦於以下問題:Golang List.Front方法的具體用法?Golang List.Front怎麽用?Golang List.Front使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類container/list.List
的用法示例。
在下文中一共展示了List.Front方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: filter
func filter(idx int, vals, bits *list.List) []interface{} {
if vals == nil || bits == nil {
return nil
}
var shifted uint = 0
valsPerCase := make([]interface{}, vals.Len())
for i, v, b := 0, vals.Front(), bits.Front(); v != nil && b != nil; v, b = v.Next(), b.Next() {
valIdx := idx >> shifted
mask := int(math.Pow(2, float64(b.Value.(uint))) - 1)
valIdx &= mask
if valIdx >= len(v.Value.([]interface{})) {
return nil
}
valsPerCase[i] = v.Value.([]interface{})[valIdx]
i++
shifted += b.Value.(uint)
}
return valsPerCase
}
示例2: StrList2StrArray
func StrList2StrArray(l *list.List) []string {
output := make([]string, 0)
for i := l.Front(); i != nil; i = i.Next() {
output = append(output, i.Value.(string))
}
return output
}
示例3: bootstrapStores
// bootstrapStores bootstraps uninitialized stores once the cluster
// and node IDs have been established for this node. Store IDs are
// allocated via a sequence id generator stored at a system key per
// node.
func (n *Node) bootstrapStores(bootstraps *list.List, stopper *stop.Stopper) {
log.Infof("bootstrapping %d store(s)", bootstraps.Len())
if n.ClusterID == "" {
panic("ClusterID missing during store bootstrap of auxiliary store")
}
// Bootstrap all waiting stores by allocating a new store id for
// each and invoking store.Bootstrap() to persist.
inc := int64(bootstraps.Len())
firstID, err := allocateStoreIDs(n.Descriptor.NodeID, inc, n.ctx.DB)
if err != nil {
log.Fatal(err)
}
sIdent := roachpb.StoreIdent{
ClusterID: n.ClusterID,
NodeID: n.Descriptor.NodeID,
StoreID: firstID,
}
for e := bootstraps.Front(); e != nil; e = e.Next() {
s := e.Value.(*storage.Store)
if err := s.Bootstrap(sIdent, stopper); err != nil {
log.Fatal(err)
}
if err := s.Start(stopper); err != nil {
log.Fatal(err)
}
n.stores.AddStore(s)
sIdent.StoreID++
log.Infof("bootstrapped store %s", s)
// Done regularly in Node.startGossip, but this cuts down the time
// until this store is used for range allocations.
s.GossipStore()
}
}
示例4: convertArgumentsToSlice
func convertArgumentsToSlice(arguments *list.List) []string {
argumentSlice := make([]string, 0, arguments.Len())
for e := arguments.Front(); e != nil; e = e.Next() {
argumentSlice = append(argumentSlice, e.Value.(string))
}
return argumentSlice
}
示例5: outOfOrder
func outOfOrder(l *list.List) {
iTotal := 25
if iTotal > l.Len() {
iTotal = l.Len()
}
ll := make([]*list.List, iTotal)
for i := 0; i < iTotal; i++ {
ll[i] = list.New()
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for e := l.Front(); e != nil; e = e.Next() {
fpath, ok := e.Value.(string)
if !ok {
panic("The path is invalid string")
}
if rand.Int()%2 == 0 {
ll[r.Intn(iTotal)].PushFront(fpath)
} else {
ll[r.Intn(iTotal)].PushBack(fpath)
}
}
r0 := rand.New(rand.NewSource(time.Now().UnixNano()))
l.Init()
for i := 0; i < iTotal; i++ {
if r0.Intn(2) == 0 {
l.PushBackList(ll[i])
} else {
l.PushFrontList(ll[i])
}
ll[i].Init()
}
}
示例6: copyList
func copyList(l *list.List) *list.List {
n := list.New()
for e := l.Front(); e != nil; e = e.Next() {
n.PushBack(e.Value.(string))
}
return n
}
示例7: initSynsetVector
func (this *UKB) initSynsetVector(ls *list.List, pv []float64) {
nw := 0
uniq := make(map[string]*Word)
for s := ls.Front(); s != nil; s = s.Next() {
for w := s.Value.(*Sentence).Front(); w != nil; w = w.Next() {
if this.RE_wnpos.MatchString(w.Value.(*Word).getTag(0)) {
key := w.Value.(*Word).getLCForm() + "#" + strings.ToLower(w.Value.(*Word).getTag(0))[0:1]
if uniq[key] == nil {
nw++
uniq[key] = w.Value.(*Word)
}
}
}
}
for _, u := range uniq {
lsen := u.getSenses(0)
nsyn := lsen.Len()
for s := lsen.Front(); s != nil; s = s.Next() {
syn := this.wn.getVertex(s.Value.(FloatPair).first)
if syn == VERTEX_NOT_FOUND {
LOG.Warn("Unknown synset " + s.Value.(FloatPair).first + " ignored. Please check consistency between sense dictionary and KB")
} else {
pv[syn] += (1.0 / float64(nw)) * (1.0 / float64(nsyn))
}
}
}
}
示例8: houseKeeping
func houseKeeping(get, give chan interface{},
factory func() interface{}) {
q := new(list.List)
for {
if q.Len() == 0 {
atomic.AddInt64(&makes, 1)
q.PushFront(queued{when: time.Now(), data: factory()})
}
element := q.Front()
timeout := time.NewTimer(time.Minute)
select {
case b := <-give:
timeout.Stop()
q.PushFront(queued{when: time.Now(), data: b})
case get <- element.Value.(queued).data:
timeout.Stop()
q.Remove(element)
case <-timeout.C:
e := q.Front()
for e != nil {
n := e.Next()
if time.Since(e.Value.(queued).when) > time.Minute {
q.Remove(e)
e.Value = nil
}
e = n
}
}
}
}
示例9: computeAverages
func computeAverages(execution_results *list.List) (float64, float64, int) {
average_concurrent_users, average_response_time := 0.0, 0.0
var result *httpActionResult
var avg_rt_counter time.Duration
max_concurrent_users := 0
avg_cu_counter := 0.0
counter := 0.0
if execution_results.Len() > 0 {
for elem := execution_results.Front(); elem != nil; elem = elem.Next() {
result = elem.Value.(*httpActionResult)
avg_cu_counter += float64(result.concurrent_users)
if result.concurrent_users > max_concurrent_users {
max_concurrent_users = result.concurrent_users
}
if result.is_client_error == false &&
result.is_server_error == false &&
result.has_timed_out == false {
avg_rt_counter += result.response_time
counter++
}
}
average_concurrent_users = avg_cu_counter / float64(execution_results.Len())
numerator := avg_rt_counter.Seconds() * 1000.0
average_response_time = float64(numerator) / counter
}
return average_concurrent_users, average_response_time,
max_concurrent_users
}
示例10: loadInputTemplate
func loadInputTemplate(name string, loader TemplateLoader) (Template, error) {
t, err := loader.LoadTemplate(name)
if err != nil {
return Template{}, nil
}
load_tracker := map[string]bool{name: true}
var load_queue list.List
for _, new_name := range t.InputDependencies {
if !load_tracker[new_name] {
load_tracker[new_name] = true
load_queue.PushBack(new_name)
}
}
for e := load_queue.Front(); e != nil; e = e.Next() {
template_name := e.Value.(string)
new_template, err := loader.LoadTemplate(template_name)
if err != nil {
return Template{}, err
}
t.Inputs = append(t.Inputs, new_template.Inputs...)
for _, new_name := range new_template.InputDependencies {
if !load_tracker[new_name] {
load_tracker[new_name] = true
load_queue.PushBack(new_name)
}
}
}
return t, nil
}
示例11: main
func main() {
give := make(chan []byte)
get := make(chan []byte)
go func() {
q := new(list.List)
for {
if q.Len() == 0 {
q.PushFront(make([]byte, 100))
}
e := q.Front()
select {
case s := <-give:
q.PushFront(s)
case get <- e.Value.([]byte):
q.Remove(e)
}
}
}()
// Gets a new buffer from the recycler.
buffer := <-get
// Give it back to the recycler.
give <- buffer
// Get the recycled buffer again.
buffer = <-get
}
示例12: LoadTemplates
func LoadTemplates(name string, loader TemplateLoader) (*template.Template, error) {
load_tracker := map[string]bool{name: true}
var load_queue list.List
load_queue.Init()
load_queue.PushBack(name)
t := template.New(name).Funcs(builtins)
for e := load_queue.Front(); e != nil; e = e.Next() {
template_name := e.Value.(string)
new_template, err := loader.LoadTemplate(template_name)
if err != nil {
return nil, err
}
if _, err := t.Parse(new_template.Data); err != nil {
return nil, err
}
if t.Lookup(template_name) == nil {
return nil, fmt.Errorf(`template "%s"load failed.`, template_name)
}
for _, new_name := range new_template.Dependencies {
if !load_tracker[new_name] {
load_tracker[new_name] = true
load_queue.PushBack(new_name)
}
}
}
return t, nil
}
示例13: listen
func listen(mr *MapReduce, stage JobType, completed *int, jobs *list.List) {
NumOther := 0
switch stage {
case Map:
NumOther = mr.nReduce
case Reduce:
NumOther = mr.nMap
}
if jobs.Len() != 0 {
select {
//wait for worker responses
case r := <-mr.responses:
HandleResponse(r, completed, jobs)
//wait for available if none are available
case id := <-mr.available:
w := mr.Workers[id]
//pop off a job id
j := jobs.Remove(jobs.Front()).(int)
args := &DoJobArgs{mr.file, stage, j, NumOther}
go SendRPC(mr, w, args, j)
}
} else {
r := <-mr.responses
HandleResponse(r, completed, jobs)
}
}
示例14: closestContacts
func (k *Kademlia) closestContacts(searchID ID, excludedID ID, amount int) (contacts []Contact) {
contacts = make([]Contact, 0)
k.doInSearchOrder(searchID, func(index int) bool {
// add as many contacts from bucket i as possible,
currentBucket := k.Buckets[index].contacts
sortedList := new(list.List)
//sort that list |suspect|
for e := currentBucket.Front(); e != nil; e = e.Next() {
insertSorted(sortedList, e.Value.(Contact), func(first Contact, second Contact) int {
firstDistance := first.NodeID.Xor(searchID)
secondDistance := second.NodeID.Xor(searchID)
return firstDistance.Compare(secondDistance)
})
}
// (^._.^)~ kirby says add as much as you can to output slice
for e := sortedList.Front(); e != nil; e = e.Next() {
c := e.Value.(Contact)
if !c.NodeID.Equals(excludedID) {
contacts = append(contacts, c)
// if the slice is full, break
if len(contacts) == amount {
return false
}
}
}
// slice isn't full, do on the next index
return true
})
return
}
示例15: pushMetric
// pushMetric adds the metric to the end of the list and returns a comma separated string of the
// previous 61 entries. We return 61 instead of 60 (an hour) because the chart on the client
// tracks deltas between these values - there is nothing to compare the first value against.
func pushMetric(history *list.List, ev expvar.Var) string {
history.PushBack(ev.String())
if history.Len() > 61 {
history.Remove(history.Front())
}
return JoinStringList(history)
}