当前位置: 首页>>代码示例>>Golang>>正文


Golang sort.SortStrings函数代码示例

本文整理汇总了Golang中sort.SortStrings函数的典型用法代码示例。如果您正苦于以下问题:Golang SortStrings函数的具体用法?Golang SortStrings怎么用?Golang SortStrings使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SortStrings函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: process

func (rg *Registrar) process(seqn uint64, memberSet, calSet map[string]string) {
	memberSets := make(map[uint64]map[string]string)
	memberSets[seqn] = dup(memberSet)

	calSets := make(map[uint64][]string)
	calSets[seqn] = nonEmpty(values(calSet))
	sort.SortStrings(calSets[seqn])

	for {
		select {
		case l := <-rg.lookupCh:
			heap.Push(rg.lookups, l)
		case ev := <-rg.evs:
			dir, name := path.Split(ev.Path)
			switch dir {
			case membersDir:
				memberSet[name] = ev.Body, ev.IsSet()
			case slotDir:
				calSet[name] = ev.Body, ev.IsSet()
			}
			seqn = ev.Seqn
			memberSets[seqn] = dup(memberSet)
			calSets[seqn] = nonEmpty(values(calSet))
			sort.SortStrings(calSets[seqn])
		}

		// If we have any lookups that can be satisfied, do them.
		for l := rg.lookups.peek(); seqn >= l.cver; l = rg.lookups.peek() {
			heap.Pop(rg.lookups)
			l.memberSet = memberSets[l.cver]
			l.calSet = calSets[l.cver]
			l.done <- 1
		}
	}
}
开发者ID:andradeandrey,项目名称:doozer,代码行数:35,代码来源:registrar.go

示例2: expectContentsEqual

func expectContentsEqual(t *testing.T, set *set.StringSet, expected []string) {
	var contents vector.StringVector
	for val := range set.Iter() {
		contents.Push(val)
	}

	sort.SortStrings(contents)
	sort.SortStrings(expected)

	if !reflect.DeepEqual(contents.Data(), expected) {
		t.Errorf("Expected:%v\nGot: %v", expected, contents)
	}
}
开发者ID:jacobsa,项目名称:igo,代码行数:13,代码来源:parse_test.go

示例3: listCommands

func listCommands(conn core.Conn) {
	// Sort command names alphabetically
	names := make([]string, len(cmds))
	i := 0
	for name := range cmds {
		names[i] = name
		i++
	}
	sort.SortStrings(names)

	// Print command names
	lines := make([]string, (len(names)+3)/4)
	for i = 0; i < len(names); i += 4 {
		a, b, c, d := names[i], "", "", ""
		if i+1 < len(names) {
			b = names[i+1]
		}
		if i+2 < len(names) {
			c = names[i+2]
		}
		if i+3 < len(names) {
			d = names[i+3]
		}
		lines[i/4] = fmt.Sprintf("%20s%20s%20s%20s", a, b, c, d)
	}
	sendLines(conn, lines)
}
开发者ID:stefanha,项目名称:bouncin,代码行数:27,代码来源:commands.go

示例4: writeCookies

// writeCookies writes the wire representation of the cookies
// to w. Each cookie is written on a separate "Cookie: " line.
// This choice is made because HTTP parsers tend to have a limit on
// line-length, so it seems safer to place cookies on separate lines.
func writeCookies(w io.Writer, kk []*http.Cookie) os.Error {
	lines := make([]string, 0, len(kk))
	var b bytes.Buffer
	for _, c := range kk {
		b.Reset()
		n := c.Name
		// TODO(petar): c.Value (below) should be unquoted if it is recognized as quoted
		fmt.Fprintf(&b, "%s=%s", http.CanonicalHeaderKey(n), c.Value)
		if len(c.Path) > 0 {
			fmt.Fprintf(&b, "; $Path=%s", http.URLEscape(c.Path))
		}
		if len(c.Domain) > 0 {
			fmt.Fprintf(&b, "; $Domain=%s", http.URLEscape(c.Domain))
		}
		if c.HttpOnly {
			fmt.Fprintf(&b, "; $HttpOnly")
		}
		lines = append(lines, "Cookie: "+b.String()+"\r\n")
	}
	sort.SortStrings(lines)
	for _, l := range lines {
		if _, err := io.WriteString(w, l); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:kybernetyk,项目名称:web.go,代码行数:31,代码来源:cookie.go

示例5: NewDocument

// Parse a text string, words seprated by whitespaces, and create a
// Document instance.  In order to initialize topic_histogram, this
// function requires the number_of_topics.
func NewDocument(text string, num_topics int) (doc *Document, err os.Error) {
	if num_topics <= 1 {
		return nil, os.NewError("num_topics must be >= 2")
	}

	words := strings.Fields(text)
	if len(words) <= 1 {
		return nil, os.NewError("Document less than 2 words:" + text)
	}
	sort.SortStrings(words)

	doc = new(Document)
	doc.wordtopics = make([]int, len(words))
	doc.unique_words = make([]string, 0)
	doc.wordtopics_indices = make([]int, 0)
	doc.topic_histogram = make([]int, num_topics)
	doc.topic_histogram[0] = len(words)

	prev_word := ""
	for i := 0; i < len(words); i++ {
		if words[i] != prev_word {
			prev_word = words[i]
			doc.unique_words = append(doc.unique_words, prev_word)
			doc.wordtopics_indices = append(doc.wordtopics_indices, i)
		}
	}

	if !doc.IsValid() {
		return nil, os.NewError("Document is invalid")
	}
	return
}
开发者ID:cuiweiqiang,项目名称:lda-go,代码行数:35,代码来源:document.go

示例6: writeCanonicalizedAmzHeaders

func writeCanonicalizedAmzHeaders(buf *bytes.Buffer, req *http.Request) {
	amzHeaders := make([]string, 0)
	vals := make(map[string][]string)
	for k, vv := range req.Header {
		if hasPrefixCaseInsensitive(k, "x-amz-") {
			lk := strings.ToLower(k)
			amzHeaders = append(amzHeaders, lk)
			vals[lk] = vv
		}
	}
	sort.SortStrings(amzHeaders)
	for _, k := range amzHeaders {
		buf.WriteString(k)
		buf.WriteByte(':')
		for idx, v := range vals[k] {
			if idx > 0 {
				buf.WriteByte(',')
			}
			if strings.Contains(v, "\n") {
				// TODO: "Unfold" long headers that
				// span multiple lines (as allowed by
				// RFC 2616, section 4.2) by replacing
				// the folding white-space (including
				// new-line) by a single space.
				buf.WriteString(v)
			} else {
				buf.WriteString(v)
			}
		}
		buf.WriteByte('\n')
	}
}
开发者ID:rvijax,项目名称:camlistore,代码行数:32,代码来源:auth.go

示例7: TestDoozerWalkWithRev

func TestDoozerWalkWithRev(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	rev, _ := cl.Set("/test/foo", store.Clobber, []byte("bar"))
	cl.Set("/test/fun", store.Clobber, []byte("house"))
	cl.Set("/test/fab", store.Clobber, []byte("ulous"))

	w, err := cl.Walk("/test/**", &rev, nil, nil)
	assert.Equal(t, nil, err, err)

	ls := []string{}
	for e := range w.C {
		ls = append(ls, e.Path)
	}

	sort.SortStrings(ls)
	assert.Equal(t, []string{"/test/foo"}, ls)
}
开发者ID:chrismoos,项目名称:doozerd,代码行数:25,代码来源:peer_test.go

示例8: glob

// glob searches for files matching pattern in the directory dir
// and appends them to matches. If the directory cannot be
// opened, it returns the existing matches. New matches are
// added in lexicographical order.
// The only possible error return occurs when the pattern is malformed.
func glob(dir, pattern string, matches []string) (m []string, e os.Error) {
	m = matches
	fi, err := os.Stat(dir)
	if err != nil {
		return
	}
	if !fi.IsDirectory() {
		return
	}
	d, err := os.Open(dir)
	if err != nil {
		return
	}
	defer d.Close()

	names, err := d.Readdirnames(-1)
	if err != nil {
		return
	}
	sort.SortStrings(names)

	for _, n := range names {
		matched, err := Match(pattern, n)
		if err != nil {
			return m, err
		}
		if matched {
			m = append(m, Join(dir, n))
		}
	}
	return
}
开发者ID:go-nosql,项目名称:golang,代码行数:37,代码来源:match.go

示例9: TestWalkStop

func TestWalkStop(t *testing.T) {
	exp := map[string]string{
		"/d/x":   "1",
		"/d/y":   "2",
		"/d/z/a": "3",
	}
	var expPaths []string
	for p := range exp {
		expPaths = append(expPaths, p)
	}
	sort.SortStrings(expPaths)

	st := New()
	st.Ops <- Op{1, MustEncodeSet("/d/x", "1", Clobber)}
	st.Ops <- Op{2, MustEncodeSet("/d/y", "2", Clobber)}
	st.Ops <- Op{3, MustEncodeSet("/d/z/a", "3", Clobber)}
	st.Ops <- Op{4, MustEncodeSet("/m/y", "", Clobber)}
	st.Ops <- Op{5, MustEncodeSet("/n", "", Clobber)}
	glob, err := CompileGlob("/d/**")
	assert.Equal(t, nil, err)
	var c int
	b := Walk(st, glob, func(path, body string, rev int64) bool {
		assert.Equal(t, expPaths[0], path)
		assert.Equal(t, exp[path], body)
		c++
		expPaths = expPaths[1:]
		return true
	})
	assert.Equal(t, true, b)
	assert.Equal(t, 1, c)
}
开发者ID:kr,项目名称:doozer,代码行数:31,代码来源:getter_test.go

示例10: TestDoozerGetdirOnDir

func TestDoozerGetdirOnDir(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	cl.Set("/test/a", store.Clobber, []byte("1"))
	cl.Set("/test/b", store.Clobber, []byte("2"))
	cl.Set("/test/c", store.Clobber, []byte("3"))

	w, err := cl.Getdir("/test", 0, 0, nil)
	assert.Equal(t, nil, err)

	got := make([]string, 0)
	for e := range w.C {
		got = append(got, e.Path)
	}

	sort.SortStrings(got)
	assert.Equal(t, []string{"a", "b", "c"}, got)
}
开发者ID:chrismoos,项目名称:doozerd,代码行数:25,代码来源:peer_test.go

示例11: glob

// glob searches for files matching pattern in the directory dir
// and appends them to matches.
func glob(dir, pattern string, matches []string) []string {
	fi, err := os.Stat(dir)
	if err != nil {
		return nil
	}
	if !fi.IsDirectory() {
		return matches
	}
	d, err := os.Open(dir, os.O_RDONLY, 0666)
	if err != nil {
		return nil
	}
	defer d.Close()

	names, err := d.Readdirnames(-1)
	if err != nil {
		return nil
	}
	sort.SortStrings(names)

	for _, n := range names {
		matched, err := Match(pattern, n)
		if err != nil {
			return matches
		}
		if matched {
			matches = append(matches, Join(dir, n))
		}
	}
	return matches
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:33,代码来源:match.go

示例12: signatureBase

func signatureBase(httpMethod string, base_uri string, params map[string]string) string {
	var buf bytes.Buffer

	buf.WriteString(httpMethod)
	buf.WriteString("&")
	buf.WriteString(URLEscape(base_uri))
	buf.WriteString("&")

	var keys vector.StringVector
	for k, _ := range params {
		keys.Push(k)
	}

	sort.SortStrings(keys)
	for i, k := range keys {
		v := params[k]
		buf.WriteString(URLEscape(k))
		buf.WriteString("%3D")
		buf.WriteString(URLEscape(v))
		//don't include the dangling %26
		if i < len(params)-1 {
			buf.WriteString("%26")
		}
		i++
	}
	return buf.String()
}
开发者ID:gmarik,项目名称:twitterstream,代码行数:27,代码来源:oauth.go

示例13: PrefixList

// PrefixList returns a list of all prefixes, with duplicates removed.
// For instance, for the mapping:
//
//	user   -> /home/user
//	public -> /home/user/public
//	public -> /home/build/public
//
// the prefix list is:
//
//	user, public
//
func (m *Mapping) PrefixList() []string {
	// compute the list lazily
	if m.prefixes == nil {
		list := make([]string, len(m.list))

		// populate list
		for i, e := range m.list {
			list[i] = e.prefix
		}

		// sort the list and remove duplicate entries
		sort.SortStrings(list)
		i := 0
		prev := ""
		for _, path := range list {
			if path != prev {
				list[i] = path
				i++
				prev = path
			}
		}

		m.prefixes = list[0:i]
	}

	return m.prefixes
}
开发者ID:go-nosql,项目名称:golang,代码行数:38,代码来源:mapping.go

示例14: getdir

func (c *conn) getdir(t *T, tx txn) {
	path := pb.GetString(t.Path)

	if g := c.getterFor(t); g != nil {
		ents, rev := g.Get(path)

		if rev == store.Missing {
			c.respond(t, Valid|Done, nil, noEnt)
			return
		}

		if rev != store.Dir {
			c.respond(t, Valid|Done, nil, notDir)
			return
		}

		sort.SortStrings(ents)
		offset := int(pb.GetInt32(t.Offset))
		if offset < 0 || offset >= len(ents) {
			c.respond(t, Valid|Done, nil, erange)
			return
		}

		e := ents[offset]
		c.respond(t, Valid|Done, tx.cancel, &R{Path: &e})
	}
}
开发者ID:kr,项目名称:doozerd,代码行数:27,代码来源:server.go

示例15: loadCodewalk

// loadCodewalk reads a codewalk from the named XML file.
func loadCodewalk(file string) (*Codewalk, os.Error) {
	f, err := os.Open(file)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	cw := new(Codewalk)
	p := xml.NewParser(f)
	p.Entity = xml.HTMLEntity
	err = p.Unmarshal(cw, nil)
	if err != nil {
		return nil, &os.PathError{"parsing", file, err}
	}

	// Compute file list, evaluate line numbers for addresses.
	m := make(map[string]bool)
	for _, st := range cw.Step {
		i := strings.Index(st.Src, ":")
		if i < 0 {
			i = len(st.Src)
		}
		file := st.Src[0:i]
		data, err := ioutil.ReadFile(absolutePath(file, *goroot))
		if err != nil {
			st.Err = err
			continue
		}
		if i < len(st.Src) {
			lo, hi, err := addrToByteRange(st.Src[i+1:], 0, data)
			if err != nil {
				st.Err = err
				continue
			}
			// Expand match to line boundaries.
			for lo > 0 && data[lo-1] != '\n' {
				lo--
			}
			for hi < len(data) && (hi == 0 || data[hi-1] != '\n') {
				hi++
			}
			st.Lo = byteToLine(data, lo)
			st.Hi = byteToLine(data, hi-1)
		}
		st.Data = data
		st.File = file
		m[file] = true
	}

	// Make list of files
	cw.File = make([]string, len(m))
	i := 0
	for f := range m {
		cw.File[i] = f
		i++
	}
	sort.SortStrings(cw.File)

	return cw, nil
}
开发者ID:go-nosql,项目名称:golang,代码行数:60,代码来源:codewalk.go


注:本文中的sort.SortStrings函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。