                   marked (if is-seg-c
                            (:node-edges right-sib)
                            (if (:is-seg-c right-sib)
-                             #{edge}
+                             #{(:forward-edge edge)}
                              #{}))
                   l (update-in layer [:marked] set/union marked)]
               (recur l tree parent-index c))

  bi-layer ordering. Implements the algorithm found in Bilayer Cross Counting,
  by Wilhelm Barth, Petra Mutzel and Michael Jünger"
  [graph layer next-layer]
  (let [next-edge-order (sorted-next-edge-order graph
                                                (:minus-ps layer)
                                                (:without-qs next-layer))
        tree-size (next-power-of-2-minus-1 (count (:without-qs next-layer)))
        first-leaf (/ (dec tree-size) 2)]
    (loop [layer layer
           tree (vec (repeat tree-size (AccumulatorNode. 0 #{} false)))
           crossings 0
           order next-edge-order]
      (if (empty? order)
        [layer crossings]
        (let [[ord edge] (first order)

                        (update-in [index :weight] + weight)
                        (cond->
                         is-seg-c (assoc-in [index :is-seg-c] true)
                         (not is-seg-c) (update-in [index :node-edges] conj (:forward-edge edge))))]
              (recur layer t parent-index crossings))))))))


