Это проблема графа связанного компонента .
Вы можете выполнить поиск в глубину на каждом узле и получить подключенный компонент. Если у вас есть более двух компонентов в результате, тогда да, весь объект не связан со всеми другими объектами.
class MyObject {
var id: Int = 0
var connectedIds: [Int] = []
}
func isAlreadyVisited(n: MyObject, cc: inout [[MyObject]]) -> Bool {
for c in cc {
c.forEach {
return ([110].id == n.id)
}
}
return false
}
func connectedComponent(g: [MyObject]) -> [[MyObject]] {
var cc = [[MyObject]]()
for n in g {
if !isAlreadyVisited(n: n, cc: &cc) {
var c = DFS(n, g) // Use placeHolder for DFS, you can write your own
cc.append(contentsOf: c)
}
}
return cc
}
var cc = connectedComponent(g: [MyObject(), MyObject()])
Why don't you untar normally, then just:
mv wordpress/.* .
mv wordpress/* .
rmdir wordpress
But alas, there's:
tar --strip-components=1 -zxvf wordpress.tgz
Surprisingly, my tar
(GNU tar v1.16) doesn't have an option to strip initial pathname elements.
However, it seems that more recent versions sport a --strip-components=number
parameter, which will strip that many compononents from the start of the path.
If like me you are using an older tar
, and you are certain that the archive does not contain a directory or file named wordpress/wordpress
, you could always just make a symlink from wordpress
to .
, then extract as usual:
ln -s . wordpress
tar xvfz latest.tar.gz wordpress
rm wordpress