Skip to content

Commit 0d3d524

Browse files
epostmarcosh
authored andcommitted
[#328] [stbx-core, stbx-proto] Commit collaboration session changes.
1 parent d42c87c commit 0d3d524

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

stbx-core/src/Statebox/Core/WiringTree.purs

+17-11
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,28 @@ linearizePartitionsAndNames :: ArrayMultiset PID -> Array String -> Linearizatio
3737
linearizePartitionsAndNames partition names =
3838
either (NLLDecodingFailed >>> Left) (Right <<< flip linearizeTransitionsAndNames names) $ fromNLL 0 partition
3939

40-
-- the use of `lift3` does not consider the fact that the arrays could in principle have different lengths
40+
-- TODO `lift3` does not consider the case where the arrays have different lengths; so add check and error
4141
linearizeTransitionsAndNames :: Array (TransitionF' PID) -> Array String -> Array (Glued Transition)
4242
linearizeTransitionsAndNames transitions names =
43-
sortInitialFinal $ lift3 buildGluedTransition (range 0 (length transitions - 1)) transitions names
43+
sortInitialInteriorFinal $ lift3 buildGluedTransition (range 0 (length transitions - 1)) transitions names
4444

4545
buildGluedTransition :: TID -> TransitionF' PID -> String -> Glued Transition
4646
buildGluedTransition tid (pre /\ post) name =
4747
case pre, post of
48-
[], _ -> Initial { name: name, path: [0, 0, 0], transition: tid, tokens: buildTokens pre post } -- the path is [0, 0, 0] because we consider a trivial diagram to be there
49-
_ , [] -> Final { name: name, path: [0, 0, 0], transition: tid, tokens: buildTokens pre post }
50-
_ , _ -> Untouched { name: name, path: [0, 0, 0], transition: tid, tokens: buildTokens pre post }
48+
[], _ -> Initial gluedTransition
49+
_ , [] -> Final gluedTransition
50+
_ , _ -> Untouched gluedTransition
51+
where
52+
gluedTransition = { name, path, transition: tid, tokens: buildTokens pre post }
53+
path = [netIndex, diagramIndex, 0] -- path to trivial diagram that is assumed to exist
54+
diagramIndex = 0
55+
netIndex = 0
5156

5257
-- | We use this custom function instead of `sortBy` because that does not guarantee
53-
-- | the order of equal elements to be preserved.
54-
sortInitialFinal :: a. Array (Glued a) -> Array (Glued a)
55-
sortInitialFinal gluedItems =
56-
let { no: notInitial , yes: initial } = partition isInitial gluedItems
57-
{ no: notInitialAndFinal, yes: final } = partition isFinal notInitial
58-
in initial <> notInitialAndFinal <> final
58+
-- | the order of equal elements (wrt the initial/interior/final ordering) to be preserved.
59+
sortInitialInteriorFinal :: a. Array (Glued a) -> Array (Glued a)
60+
sortInitialInteriorFinal gluedItems =
61+
initial <> interior <> final
62+
where
63+
{ no: notInitial, yes: initial } = partition isInitial gluedItems
64+
{ no: interior , yes: final } = partition isFinal notInitial

stbx-protocol/src/Statebox/Protocol/Fire.purs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ data FiringError
1818
-- | The wiring does not describe a valid wiring tree.
1919
= FireInvalidWiringTree
2020

21-
-- | The linerization of the wiring tree failed with a LinerizationError
22-
| FireLinerizationError LinearizationError
21+
-- | The linearization of the wiring tree failed with a LinearizationError
22+
| FireLinearizationError LinearizationError
2323

2424
-- | The path of the firing describing
2525
| FireTransitionIndexOutOfBounds
@@ -32,7 +32,7 @@ fire wiring firing marking = maybe
3232
(Left FireInvalidWiringTree)
3333
(\wiringTree ->
3434
either
35-
(Left <<< FireLinerizationError)
35+
(Left <<< FireLinearizationError)
3636
(\gluedTransitions ->
3737
let transitionIndex = head firing.path
3838
in maybe

0 commit comments

Comments
 (0)