0

I have a parent-child relationship in which there is a numeric property on the edge. I would like to sack the maximum value of this property and carry it through the reset of the traversal, referring to it as needed.

Current implementation looks like this:

g.withSack(1).V(33131).outE("parent_to").values("order").max().unfold().sack(Operator.max)
    .project("count","sack")
        .by(V().count())
        .by(sack())

Gremlify

Is there a cleaner way to do this? The projection here is only for example sake.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38

1 Answers1

0

I think you are using sack pretty much the way it was intended. To accumulate a value on a per traverser basis. I'm not quite clear on why you are using unfold as max is a reducing barrier. You can also use sack(assign) as there will only be one value coming out of the max step.

I regularly use sack in similar ways such as shown here to compute the sum of a set of values.

g.withSack(0).
  V().has('code','SAF').
      repeat(outE().sack(sum).by('dist').inV()).times(2).limit(10).
      order().by(sack()).
      sack().path().
      by('code').by('dist').by('code').by('dist').by('code').by()
[SAF,549,DFW,190,AUS,739]
[SAF,549,DFW,225,IAH,774]
[SAF,549,DFW,630,BNA,1179]
[SAF,549,DFW,729,ATL,1278]
[SAF,549,DFW,1120,FLL,1669]
[SAF,549,DFW,1170,IAD,1719]
[SAF,549,DFW,1190,DCA,1739]
[SAF,549,DFW,1210,BWI,1759]
[SAF,549,DFW,1560,BOS,2109]
[SAF,549,DFW,3030,ANC,3579]
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38