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

Function RLEdecode

compression/rlecoding.go:37–47  ·  view source on GitHub ↗

RLEdecode takes a run-length encoded string and returns the original string

(data string)

Source from the content-addressed store, hash-verified

35
36// RLEdecode takes a run-length encoded string and returns the original string
37func RLEdecode(data string) string {
38 var result string
39 regex := regexp.MustCompile(`(\d+)(\w)`)
40
41 for _, match := range regex.FindAllStringSubmatch(data, -1) {
42 num, _ := strconv.Atoi(match[1])
43 result += strings.Repeat(match[2], num)
44 }
45
46 return result
47}
48
49// RLEncodebytes takes a byte slice and returns its run-length encoding as a byte slice
50func RLEncodebytes(data []byte) []byte {

Callers 2

TestCompressionRLEDecodeFunction · 0.92
BenchmarkRLEDecodeFunction · 0.92

Calls

no outgoing calls

Tested by 2

TestCompressionRLEDecodeFunction · 0.74
BenchmarkRLEDecodeFunction · 0.74