MCPcopy
hub / github.com/containerd/containerd / longestCommonPrefix

Function longestCommonPrefix

core/mount/mount_linux.go:466–491  ·  view source on GitHub ↗

longestCommonPrefix finds the longest common prefix in the string slice.

(strs []string)

Source from the content-addressed store, hash-verified

464
465// longestCommonPrefix finds the longest common prefix in the string slice.
466func longestCommonPrefix(strs []string) string {
467 if len(strs) == 0 {
468 return ""
469 } else if len(strs) == 1 {
470 return strs[0]
471 }
472
473 // find out the min/max value by alphabetical order
474 min, max := strs[0], strs[0]
475 for _, str := range strs[1:] {
476 if min > str {
477 min = str
478 }
479 if max < str {
480 max = str
481 }
482 }
483
484 // find out the common part between min and max
485 for i := 0; i < len(min) && i < len(max); i++ {
486 if min[i] != max[i] {
487 return min[:i]
488 }
489 }
490 return min
491}
492
493// copyOptions copies the options.
494func copyOptions(opts []string) []string {

Callers 3

TestLongestCommonPrefixFunction · 0.85
getCommonDirectoryFunction · 0.85
compactLowerdirOptionFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestLongestCommonPrefixFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…