MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / SymbolCountOrd

Function SymbolCountOrd

compression/huffmancoding_test.go:16–29  ·  view source on GitHub ↗

SymbolCountOrd computes sorted symbol-frequency list of input message

(message string)

Source from the content-addressed store, hash-verified

14
15// SymbolCountOrd computes sorted symbol-frequency list of input message
16func SymbolCountOrd(message string) []compression.SymbolFreq {
17 runeCount := make(map[rune]int)
18 for _, s := range message {
19 runeCount[s]++
20 }
21 listfreq := make([]compression.SymbolFreq, len(runeCount))
22 i := 0
23 for s, n := range runeCount {
24 listfreq[i] = compression.SymbolFreq{Symbol: s, Freq: n}
25 i++
26 }
27 sort.Slice(listfreq, func(i, j int) bool { return listfreq[i].Freq < listfreq[j].Freq })
28 return listfreq
29}
30
31func TestHuffman(t *testing.T) {
32 messages := []string{

Callers 1

TestHuffmanFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected