File: alphabet.go

package info (click to toggle)
golang-github-shenwei356-util 0.0~git20201231.861956c-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 192 kB
  • sloc: makefile: 2
file content (28 lines) | stat: -rw-r--r-- 562 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package byteutil

import "sort"

// Alphabet returns the alphabet of a byte slice
func Alphabet(s []byte) []byte {
	count := CountOfByte(s)
	letters := make([]byte, len(count))
	i := 0
	for b := range count {
		letters[i] = b
		i++
	}
	sort.Sort(ByteSlice(letters))
	return letters
}

// AlphabetFromCountOfByte returns the alphabet of a byte slice from count
func AlphabetFromCountOfByte(count map[byte]int) []byte {
	letters := make([]byte, len(count))
	i := 0
	for b := range count {
		letters[i] = b
		i++
	}
	sort.Sort(ByteSlice(letters))
	return letters
}