aboutsummaryrefslogtreecommitdiffstats
path: root/android/paths.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2017-10-24 11:13:31 -0700
committerColin Cross <ccross@android.com>2017-10-24 12:12:32 -0700
commitb6715449737261c64d3408418754185da8624204 (patch)
tree737974202fe72cabcc566e7c6b8c1ca3637b028e /android/paths.go
parentae88703df55dcd721ccd5c3cca4c02c7b541ca9d (diff)
downloadbuild_soong-b6715449737261c64d3408418754185da8624204.tar.gz
build_soong-b6715449737261c64d3408418754185da8624204.tar.bz2
build_soong-b6715449737261c64d3408418754185da8624204.zip
Move first/last unique elements utility functions to android package
Move firstUniqueElements to android.FirstUniqueStrings, lastUniqueElements to android.LastUniqueStrings, and lastUniquePaths to android.LastUniquePaths. Test: m checkbuild Change-Id: Ieac840405126c7f8f98afb4a4ef35c01a18fe7fb
Diffstat (limited to 'android/paths.go')
-rw-r--r--android/paths.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/android/paths.go b/android/paths.go
index 74435473..d6a1c668 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -286,8 +286,8 @@ func (p Paths) Strings() []string {
return ret
}
-// FirstUniqueElements returns all unique elements of a slice, keeping the first copy of each
-// modifies the slice contents in place, and returns a subslice of the original slice
+// FirstUniquePaths returns all unique elements of a Paths, keeping the first copy of each. It
+// modifies the Paths slice contents in place, and returns a subslice of the original slice.
func FirstUniquePaths(list Paths) Paths {
k := 0
outer:
@@ -303,6 +303,24 @@ outer:
return list[:k]
}
+// LastUniquePaths returns all unique elements of a Paths, keeping the last copy of each. It
+// modifies the Paths slice contents in place, and returns a subslice of the original slice.
+func LastUniquePaths(list Paths) Paths {
+ totalSkip := 0
+ for i := len(list) - 1; i >= totalSkip; i-- {
+ skip := 0
+ for j := i - 1; j >= totalSkip; j-- {
+ if list[i] == list[j] {
+ skip++
+ } else {
+ list[j+skip] = list[j]
+ }
+ }
+ totalSkip += skip
+ }
+ return list[totalSkip:]
+}
+
func indexPathList(s Path, list []Path) int {
for i, l := range list {
if l == s {