Need help on barrier(normSack) and withBulk(false)

57 views
Skip to first unread message

Choo Max

unread,
Apr 7, 2021, 6:33:42 AM4/7/21
to Gremlin-users

Hi,

I'm learning Gremlin recently and got confused on the last example of Sack Step in the official guide.

====Examples===
gremlin> g.withSack(1.0d).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier() //[4]
==>v[1]
==>v[1]
gremlin> g.withSack(1.0d).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier().sack() //[5]
==>0.5
==>0.5
gremlin> g.withSack(1.0d,sum).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier().sack() //[6]
==>1.0
==>1.0
gremlin> g.withBulk(false).withSack(1.0f,sum).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier().sack() //[7]
==>1.0
gremlin> g.withBulk(false).withSack(1.0f).V(1).local(outE('knows').barrier(normSack).inV()).in('knows').barrier().sack() //[8]
==>0.5
==>0.5

Notes:
  • [5] The local(…​barrier(normSack)…​) ensures that all traversers leaving vertex 1 have an evenly distributed amount of the initial 1.0 "energy" (50-50), i.e. the sack is 0.5 on each result.
  • [6] Using sum as merge operator leads to the expected 1.0.
  • [7] There is now a single traverser with bulk of 2 and sack of 1.0 and thus, setting withBulk(false)` yields the expected 1.0

  • [8] Like 7, but without the sum operator

=======End======

My Questions:
  1. What's indeed the normSack for? Is it a function to distribute the sack number among traversers?
  2. Is local(…​barrier(normSack)…​) the only form/context of the usage of normSack? I can't find more information on it in the class API docs.
  3. Comaring to example 6, example 7,8 begin with withBulk(false) step. What will this influence the behavior of traversers? Will the traverser clone itself when the path splits?
Looking forward to your help. Thanks ahead.

Max

Stephen Mallette

unread,
Apr 8, 2021, 9:03:55 AM4/8/21
to gremli...@googlegroups.com
Wow, this might be the first question ever on normSack :)

> What's indeed the normSack for? Is it a function to distribute the sack number among traversers?

    > Is local(…barrier(normSack)…) the only form/context of the usage of normSack? I can't find more information on it in the class API docs.

    barrier() is the only step that can take a Consumer<TraverserSet> so I don't think you will find use for normSack anywhere else. I can't say that you should always use it with local() though. I suppose that part depends on your use case.

    > Comaring to example 6, example 7,8 begin with withBulk(false) step. What will this influence the behavior of traversers? Will the traverser clone itself when the path splits?

    I'm honestly not sure why 7 says "there is now a single traverser with a bulk of 2" - i thought that withBulk(false) would mean that traversers of this type ended up with a bulk of 1 (if bulk count was greater than zero).


    --
    You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/75e96d94-4d92-411e-bf9e-052fbffcb8e2n%40googlegroups.com.
    Reply all
    Reply to author
    Forward
    0 new messages