Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F12655933
ArcanistDiffVectorTree.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
ArcanistDiffVectorTree.php
View Options
<?php
final
class
ArcanistDiffVectorTree
extends
Phobject
{
private
$vectors
=
array
();
public
function
addVector
(
array
$vector
)
{
$this
->
vectors
[]
=
$vector
;
return
$this
;
}
public
function
newDisplayList
()
{
$root
=
new
ArcanistDiffVectorNode
();
foreach
(
$this
->
vectors
as
$vector
)
{
$root
->
addChild
(
$vector
,
count
(
$vector
),
0
);
}
foreach
(
$root
->
getChildren
()
as
$child
)
{
$this
->
compressTree
(
$child
);
}
$root
->
setDisplayDepth
(-
1
);
foreach
(
$root
->
getChildren
()
as
$child
)
{
$this
->
updateDisplayDepth
(
$child
);
}
return
$this
->
getDisplayList
(
$root
);
}
private
function
compressTree
(
ArcanistDiffVectorNode
$node
)
{
$display_node
=
$node
;
$children
=
$node
->
getChildren
();
if
(
$children
)
{
$parent
=
$node
->
getParentNode
();
if
(
$parent
)
{
$siblings
=
$parent
->
getChildren
();
if
(
count
(
$siblings
)
===
1
)
{
if
(!
$parent
->
getValueNode
())
{
$parent_display
=
$parent
->
getDisplayNode
();
if
(
$parent_display
)
{
$display_node
=
$parent_display
;
if
(
$node
->
getValueNode
())
{
$parent
->
setValueNode
(
$node
->
getValueNode
());
}
}
}
}
}
}
$node
->
setDisplayNode
(
$display_node
);
$display_element
=
last
(
$node
->
getVector
());
$display_node
->
appendDisplayElement
(
$display_element
);
foreach
(
$children
as
$child
)
{
$this
->
compressTree
(
$child
);
}
}
private
function
updateDisplayDepth
(
ArcanistDiffVectorNode
$node
)
{
$parent_depth
=
$node
->
getParentNode
()->
getDisplayDepth
();
if
(
$node
->
getDisplayVector
()
===
null
)
{
$display_depth
=
$parent_depth
;
}
else
{
$display_depth
=
$parent_depth
+
1
;
}
$node
->
setDisplayDepth
(
$display_depth
);
foreach
(
$node
->
getChildren
()
as
$child
)
{
$this
->
updateDisplayDepth
(
$child
);
}
}
private
function
getDisplayList
(
ArcanistDiffVectorNode
$node
)
{
$result
=
array
();
foreach
(
$node
->
getChildren
()
as
$child
)
{
if
(
$child
->
getDisplayVector
()
!==
null
)
{
$result
[]
=
$child
;
}
foreach
(
$this
->
getDisplayList
(
$child
)
as
$item
)
{
$result
[]
=
$item
;
}
}
return
$result
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 28, 15:08 (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1046190
Default Alt Text
ArcanistDiffVectorTree.php (2 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment