Hi Sergey,
let's pick the
classic toy graph for this example. Let the input vertices be v2, v3 and v4, and now find those vertices, that have the most outgoing edges to the aforementioned vertices:
gremlin> g = TinkerFactory.createClassic()
==>tinkergraph[vertices:6 edges:6]
gremlin> input = g.V(2,3,4).toList()
==>v[2]
==>v[3]
==>v[4]
gremlin> sm = g.of().inject(input).unfold().in().groupCount().next().sort { -it.getValue() }
==>v[1]=3
==>v[4]=1
==>v[6]=1
gremlin> m = sm.iterator().next().getValue()
==>3
gremlin> result = sm.grep { it.getValue() == m }*.getKey()
==>v[1]
And if you're using TP2:
gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> input = g.v(2,3,4).toList()
==>v[2]
==>v[3]
==>v[4]
gremlin> sm = input._().in().groupCount().cap().next().sort { -it.getValue() }
==>v[1]=3
==>v[4]=1
==>v[6]=1
gremlin> m = sm.iterator().next().getValue()
==>3
gremlin> result = sm.grep { it.getValue() == m }*.getKey()
==>v[1]
As you can see, there's only one vertex that has outgoing edges to all of the 3 vertices (v1), hence this is your result.
Cheers,
Daniel