本文整理汇总了Golang中sort.StringSlice.Search方法的典型用法代码示例。如果您正苦于以下问题:Golang StringSlice.Search方法的具体用法?Golang StringSlice.Search怎么用?Golang StringSlice.Search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sort.StringSlice
的用法示例。
在下文中一共展示了StringSlice.Search方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SortedStringHas
func SortedStringHas(s sort.StringSlice, x string) bool {
index := s.Search(x)
if index == len(s) {
return false
}
return s[s.Search(x)] == x
}
示例2: SortedStringsDelete
func SortedStringsDelete(s sort.StringSlice, x string) sort.StringSlice {
index := s.Search(x)
if len(s) != index && s[index] == x {
s = append(s[:index], s[index+1:]...)
}
return s
}
示例3: addPlayerToTable
func addPlayerToTable(c appengine.Context, tableName string, table *Table, name string) os.Error {
key := datastore.NewKey(c, "Table", tableName, 0, nil)
return datastore.RunInTransaction(c, func(c appengine.Context) os.Error {
err := datastore.Get(c, key, table)
if err != nil {
return err
}
var ss sort.StringSlice = table.Players
ss.Sort()
i := ss.Search(name)
if i >= len(ss) {
table.Players = append(table.Players, name)
}
_, err = datastore.Put(c, key, table)
return err
}, nil)
}
示例4: calcCalls
func (r dynamicImage) calcCalls(source *arrowSlice, func_name string, call_depth uint, buffer *bytes.Buffer, visitedCalls sort.StringSlice) {
for _, v := range *source {
if v.from < func_name {
continue
} else if v.from > func_name {
break
}
buffer.WriteString(v.attr)
buffer.WriteString("\n")
idx := visitedCalls.Search(v.to)
if idx < visitedCalls.Len() && visitedCalls[idx] == v.to {
} else if r.callDepth == 0 || call_depth+1 < r.callDepth {
visitedCalls = append(visitedCalls, v.to)
visitedCalls.Sort()
r.calcCalls(source, v.to, call_depth+1, buffer, visitedCalls)
}
}
}
示例5: FallbackSubjKeys
// Helper to return the subject fallback keys we need in dataDb
func FallbackSubjKeys(direction, tenant, tor, fallbackSubjects string) []string {
var sslice sort.StringSlice
if len(fallbackSubjects) != 0 {
for _, fbs := range strings.Split(fallbackSubjects, string(FALLBACK_SEP)) {
newKey := fmt.Sprintf("%s:%s:%s:%s", direction, tenant, tor, fbs)
i := sslice.Search(newKey)
if i < len(sslice) && sslice[i] != newKey {
// not found so insert it
sslice = append(sslice, "")
copy(sslice[i+1:], sslice[i:])
sslice[i] = newKey
} else {
if i == len(sslice) {
// not found and at the end
sslice = append(sslice, newKey)
}
} // newKey was foundfound
}
}
return sslice
}