예제 #1
0
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
0
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
0
파일: tables.go 프로젝트: bclement/sabacc
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
0
파일: app.go 프로젝트: jinlf/callgraph
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
0
// 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
}